CookieFirst
CookieFirst offers an API documentation.
Event listener
The following code works asynchronously with CookieFirst Banner API and listens
for the cf_init
and cf_consent
, parses the consent state and eventually
calls the walker consent
command:
(function () {
function handleConsent(consent) {
if (!consent) return; // Process only explicit consent
// Renaming of the categories
const mapping = {
necessary: 'functional',
functional: 'functional',
performance: 'analytics',
advertising: 'marketing',
};
const state = {};
Object.keys(consent).forEach(function (category) {
state[mapping[category] || category] = consent[category];
});
elb('walker consent', state);
}
if (window.CookieFirst) {
// Already loaded
handleConsent(CookieFirst.consent);
} else {
// On load
window.addEventListener('cf_init', function () {
handleConsent(CookieFirst.consent);
});
}
// On change
window.addEventListener('cf_consent', function (e) {
handleConsent(e.detail);
});
})();
info
Ensure the elb function is available.