CookieConsent
Passes the visitor's CookieConsent (v3, by orestbida) decision to walkerOS, so destinations gated with config.consent send only what the visitor agreed to. The source reads only a decision the visitor made: accepted categories are granted, rejected ones are denied.
Installation
npm install @walkeros/web-source-cmp-cookieconsent
import { startFlow } from '@walkeros/collector';
import { sourceCookieConsent } from '@walkeros/web-source-cmp-cookieconsent';
await startFlow({
sources: {
consent: {
code: sourceCookieConsent,
},
},
});
Configuration
This source uses the standard source config wrapper (consent, data, env, id, ...). For the shared fields see source configuration. Package-specific fields live under config.settings and are listed below.
Settings
| Property | Type | Description | More |
|---|---|---|---|
categoryMap | Record<string, string> | Map CookieConsent's category names (keys) to walkerOS consent groups (values). Categories without an entry keep their own name. Default: { ads: 'marketing' }. |
Mapping
This package does not define custom rule-level settings. For the standard rule fields (consent, condition, data, batch, name, policy) see mapping.
Examples
Accept all
The visitor clicks Accept all. CookieConsent fires cc:onConsent and the source grants necessary, analytics and marketing.
{
"valid": true,
"preferences": {
"acceptType": "all",
"acceptedCategories": [
"necessary",
"analytics",
"ads"
],
"rejectedCategories": []
}
}elb("walker consent", {
"necessary": true,
"analytics": true,
"marketing": true
})Category map override
A custom categoryMap reports the analytics category as a statistics group.
{
"valid": true,
"preferences": {
"acceptType": "custom",
"acceptedCategories": [
"necessary",
"analytics"
],
"rejectedCategories": [
"ads"
]
}
}{
"settings": {
"categoryMap": {
"analytics": "statistics"
}
}
}elb("walker consent", {
"necessary": true,
"statistics": true,
"marketing": false
})Custom category
A site category without a map entry, here functionality, is reported under its own name.
{
"valid": true,
"preferences": {
"acceptType": "custom",
"acceptedCategories": [
"necessary",
"functionality"
],
"rejectedCategories": [
"analytics",
"ads"
]
}
}elb("walker consent", {
"necessary": true,
"functionality": true,
"analytics": false,
"marketing": false
})First visit
The banner is open and CookieConsent holds no valid choice, so the source sends nothing until the visitor decides.
{
"valid": false,
"preferences": {
"acceptedCategories": [],
"rejectedCategories": []
}
}// no outputOpt-out defaults
In opt-out mode CookieConsent enables default categories before a choice. That is no decision, so the source sends nothing until the visitor decides.
{
"valid": false,
"preferences": {
"acceptedCategories": [
"necessary",
"analytics",
"ads"
],
"rejectedCategories": []
}
}// no outputPreferences change
The visitor withdraws analytics and ads in the preferences. CookieConsent fires cc:onChange and the source sends both groups as false.
{
"valid": true,
"preferences": {
"acceptType": "necessary",
"acceptedCategories": [
"necessary"
],
"rejectedCategories": [
"analytics",
"ads"
]
}
}elb("walker consent", {
"necessary": true,
"analytics": false,
"marketing": false
})Reject all
The visitor clicks Reject all. Only the read-only necessary category stays accepted, and the source sends analytics and marketing as false.
{
"valid": true,
"preferences": {
"acceptType": "necessary",
"acceptedCategories": [
"necessary"
],
"rejectedCategories": [
"analytics",
"ads"
]
}
}elb("walker consent", {
"necessary": true,
"analytics": false,
"marketing": false
})Returning visitor
CookieConsent restored a valid choice before the source started, so the static read at init publishes it.
{
"valid": true,
"preferences": {
"acceptType": "custom",
"acceptedCategories": [
"necessary",
"analytics"
],
"rejectedCategories": [
"ads"
]
}
}elb("walker consent", {
"necessary": true,
"analytics": true,
"marketing": false
})How it works
-
Stored decision: If
window.CookieConsentalready holds a valid decision when the source starts, the source publishes it at once. -
Decision events: The source listens for CookieConsent's
cc:onConsentandcc:onChangewindow events. CookieConsent firescc:onConsentafter a first decision and on every page load with a stored one, andcc:onChangewhen the visitor changes it. Each time, the source reads the decision fromCookieConsent.getUserPreferences(). -
Mapping: Accepted categories are published as
true, rejected ones asfalse, throughcategoryMapandelb('walker consent', state). -
One command per decision: A stored decision is reported both by the read at start and by
cc:onConsenton page load. The source sends a state only when it differs from the last one it sent.
The ESM build
The script build defines window.CookieConsent. If you import
vanilla-cookieconsent as a module, assign it before CookieConsent.run:
window.CookieConsent = CookieConsent;. Without it the source cannot read the
decision and logs an ERROR.
import * as CookieConsent from 'vanilla-cookieconsent';
window.CookieConsent = CookieConsent;
Default category mapping
The categories are the ones your CookieConsent.run configuration names. For
the categories the CookieConsent docs use:
| CookieConsent category | walkerOS consent group |
|---|---|
necessary | necessary: keeps its name and grants no group |
analytics | analytics |
ads | marketing |
| any other category | its own name |
CookieConsent always accepts the read-only necessary category, so the default
mapping never turns it into a group a destination waits for. Category names are
compared case-insensitively.
When several categories map to the same group, the group is true only if
every one of them is accepted: any deny denies.
Custom entries are merged with the default mapping. Specify only the categories you want to override. All other defaults remain active.
Custom mapping example
await startFlow({
sources: {
consent: {
code: sourceCookieConsent,
config: {
settings: {
categoryMap: {
functionality: 'functional', // Your functionality category
advertisement: 'marketing', // CookieConsent's Google Consent Mode guide names it so
},
},
},
},
},
});
When the source sends nothing
The source publishes a decision only while CookieConsent.validConsent() is
true, so it sends nothing:
- before the visitor makes a choice;
- after you raise
revisionin your configuration, until the visitor decides again; - in
mode: 'opt-out'before a choice, although CookieConsent runs the scripts of your enabled categories; - with
respectGpcfor a visitor whose browser sends Global Privacy Control, until that visitor opens the preferences and decides; - in a bot or automated browser (Playwright, Selenium, Puppeteer) under
CookieConsent's default
hideFromBots, so a test setup setshideFromBots: falseinCookieConsent.run.
Destinations gated with config.consent keep that visitor's events queued (see
how CMP sources work).
To act on your opt-out defaults before a choice, set them yourself with a
walker consent command or the collector's consent
setting.
Services
The source maps categories, not services: it publishes the categories CookieConsent reports as accepted or rejected.
Google Consent Mode
The source sends nothing to Google itself. The
gtag destination sets Google Consent Mode with
its como setting from the analytics and marketing groups.
If your CookieConsent callbacks already call gtag('consent', ...)
(CookieConsent's Google Consent Mode guide), keep one of them: remove those
calls, or set "como": false on the gtag destination.
Timing considerations
The source may start before or after CookieConsent.run. Both orders report
the stored decision once:
- CookieConsent runs before the source: the read at start publishes the stored decision.
- Source starts before CookieConsent: the source publishes the decision
when CookieConsent fires
cc:onConsent.