Cookie Manager
The Cookie Manager provides a centralized system for managing user cookie consent preferences. It serves as the bridge between consent management apps and scripts that need to respect user privacy choices.
What it does
- Stores user consent preferences across different cookie categories
- Provides APIs to read and update consent settings
- Emits events when consent preferences change
- Integrates with Script Manager to conditionally load scripts based on consent
Data Structure
Cookie Categories
The Cookie Manager supports three types of cookies:
enum CookieCategory {
/**
* Required for basic site functionality
*/
Essential = 'essential',
/**
* Used for measuring site performance
*/
Analytics = 'analytics',
/**
* Used for advertising and tracking
*/
Marketing = 'marketing',
}
CookieConsentPermissions
Defines consent for each category:
type CookieConsentPermissions = {
category: CookieCategory
/**
* Apps or scripts to exclude from this category, even when category consent is granted.
*/
excluded?: string[]
}
CookieConsent
The main data structure that holds all consent information:
type CookieConsent = {
/**
* Whether the user has been asked for consent.
*/
prompted: boolean
/**
* The categories they have given permission for
*/
permissions: CookieConsentPermissions[]
/**
* The time when the consent was provided
*/
datestamp: string
/**
* The prompt version that user has consented to.
* The CPM should offer a different version every time
* the consent description or cookie structure changes
*/
version: string
}
API Methods
getCookieConsent
Retrieves the current user consent preferences:
getCookieConsent(): CookieConsent | undefined
setCookieConsent
Updates the user consent preferences and emits onCookieConsentChange
event through window.BM
event emitter:
setCookieConsent(cookieConsent: CookieConsent): void
isConsentGranted
Checks if consent is granted for a specific category and app:
isConsentGranted(params: {
category: CookieCategory,
name?: string
}): boolean
Parameters:
category
: The cookie category to checkname
: The name of the app or script that needs to be checked against the user’s consents
Returns: true
if consent is granted and the app is not excluded, false
otherwise