Cookies EU Banner

cookies-eu-banner/headless reference

createHeadlessCookiesBanner()

Type: (config: HeadlessConfig) => HeadlessBanner

Configuration HeadlessConfig

onShowBanner()

Type: () => void
Required

Called when the banner should be shown.

Which means that the visitor is not a bot and has not made a choice yet.

onAccept()

Type: () => void
Required

The callback that will be called when the user accepts or has already accepted. This is where you launch your scripts (tracking, player, etc.).

onReject()

Type: () => void
Required

The callback that will be called when the user rejects or has already rejected.

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 HeadlessBanner instance

checkConsentAndShowBanner()

Type: () => void

Do checks (bots, DoNotTrack, consent) before creating the banner.

Triggers onAccept, onReject or onShowBanner when relevant.

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 accepted
  • false: user has rejected
  • undefined: no choice made yet, or has expired

setCookie()

Type: (name: string, value: string) => void

Helper to set a cookie value.

  • name: the cookie name
  • value: 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

Type: string
Value: "hasConsent"

The default cookie (or localStorage key) used to store the consent.

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.