Reads the cookie consent configuration and records consent choices, for a
consent UI you build yourself. Available as lynkow.cookies on the server
and in the browser. For the built-in banner, use lynkow.consent.
Access via: lynkow.cookies
Methods
3 methods
clearCache
clearCache(): voidClears this service's cached consent configuration for every locale, so
the next getConfig() fetches it again. Only useful with cache: true.
Returns: void
lynkow.cookies.clearCache()getConfig
getConfig(options?: BaseRequestOptions): Promise<CookieConfig>Fetches the site's cookie consent configuration: mode, banner texts and
styling, categories and the third-party scripts gated on each category.
Texts and category labels come in the request locale, falling back to the
site's default locale. A site with no consent settings returns a default
configuration with enabled: false. With cache: true, cached for 10
minutes per locale.
Parameter | Type | Description |
|---|---|---|
|
|
|
Returns: Promise<CookieConfig>
const config = await lynkow.cookies.getConfig({
fetchOptions: { next: { revalidate: 3600, tags: ['lynkow:consent'] } },
})
if (config.enabled) {
console.log(config.categories) // [{id: 'necessary', ...}, {id: 'analytics', ...}]
console.log(config.texts.acceptAll) // "Accept all"
}logConsent
logConsent(preferences: CookiePreferences, options?: ConsentLogOptions): Promise<ConsentLogResponse>Records a visitor's consent choice in the site's consent log. In a
browser, visitorId, action and pageUrl are filled in for you.
Outside a browser, pass visitorId. The API records the banner locale it
serves for locale and the matching text version of
CookiesService.getConfig. Resolves to a confirmation message.
Throws LynkowError BAD_REQUEST (status 0, nothing sent) outside a
browser without visitorId, and VALIDATION_ERROR for an invalid field
such as a relative pageUrl or more than 100 categories.
Parameter | Type | Description |
|---|---|---|
|
| Category id to accepted flag, sent as |
|
|
|
Returns: Promise<ConsentLogResponse>
// Revoking a granted consent: 'withdraw' is never inferred.
await lynkow.cookies.logConsent(
{ necessary: true, analytics: false, marketing: false },
{ action: 'withdraw' }
)