cookies-eu-banner reference
createCookiesBanner()
Type: (config: CookieEuBannerConfig) => CookiesEuBanner
Configuration CookieEuBannerConfig
bannerTemplateSelector
Type: string
Default: "#cookies-eu-banner-template"
Selector to find the banner <template> tag used to create a new banner in showBanner().
acceptButtonSelector
Type: string
Default: "#cookies-eu-accept"
Selector to find the Accept <button>, to bind click event on it in showBanner().
rejectButtonSelector
Type: string
Default: "#cookies-eu-reject"
Selector to find the Reject <button>, to bind click event on it in showBanner().
onAccept()
Type: () => void
Required
The callback that will be called when this user accepts or has already accepted. This is where you launch your scripts (tracking, player, etc.).
onReject()
Type: () => void
The callback that will be called when this user rejects or has already rejected.
onBeforeRemove()
Type: (bannerElement: HTMLElement) => void
Called before removing the banner, at the beginning of the delay. Useful to trigger a transition.
See also: delayBeforeRemove
delayBeforeRemove
Type: number
Default: 0
Delay before removing the banner from the DOM in milliseconds.
See also: onBeforeRemove
useLocalStorage
Type: boolean
Default: false
If enabled, stores the user consent in localStorage.
consentCookieName
Type: string
Default: DEFAULT_CONSENT_COOKIE_NAME
The name of the cookie or the localStorage key.
consentCookieTimeout
Type: number
Default: 31104000000 (12 months)
The timeout in milliseconds for the consent cookie.
trackingCookieNames
Type: string[]
Default: DEFAULT_TRACKING_COOKIE_NAMES
List of tracking cookies to remove when the user rejects cookies.
botsUserAgentRegexp
Type: RegExp
Default: /bot|crawler|spider|crawling|preview|vkShare|extended|facebook|meta-/i
A way to detect bots, crawlers, AI agents, and other non-human visitors. This prevents the banner from being shown to bots (in screenshots, etc.).
The CookiesEuBanner instance
showBanner()
Type: () => void
Show the banner and bind listeners to accept and reject buttons.
The banner template, accept and reject buttons must exist, based on bannerTemplateSelector, acceptButtonSelector and rejectButtonSelector, otherwise the function will throw an error.
Note: This function does nothing if the banner is already visible.
removeBanner()
Type: (delay?: number) => Promise<void>
Remove the banner from DOM after the specified delay.
delay: delay before removing the banner, in milliseconds. (Default: 0)
setConsent()
Type: (hasConsent: boolean) => void
hasConsent: the new consent value to set in the cookie or the localStorage.
hasConsent()
Type: () => boolean | undefined
Retrieve the current user consent status from cookie or localStorage.
true: user has acceptedfalse: user has rejectedundefined: no choice made yet, or has expired
setCookie()
Type: (name: string, value: string) => void
Helper to set a cookie value.
name: the cookie namevalue: the value to save in the cookie
getCookie()
Type: (name: string) => string | undefined
Helper to get a cookie value.
name: the cookie name
deleteCookie()
Type: (name: string) => void
Helper to delete a cookie.
name: the cookie name
DEFAULT_CONSENT_COOKIE_NAME
Type: string
Value: "hasConsent"
The default cookie (or localStorage key) used to store the consent.
DEFAULT_TRACKING_COOKIE_NAMES
Type: string[]
Value: ["__utma", "__utmb", "__utmc", "__utmt", "__utmv", "__utmz", "_ga", "_gat", "_gid"]
The list of cookie names that must be removed when the user rejects consent.
