Banner
The JavaScript API
Control the banner from your code: reopen the preferences, read the consent state and react to decisions through the dataLayer.
Once loaded, the banner exposes a global window.__cmp object on every page. It lets you open the banner or the preference center from your own interface elements and read the current consent state: useful, for example, for a "Manage my cookies" link in your footer.
Methods
| Method | Effect |
|---|---|
__cmp.showPreferences() | Opens the preference center, where the visitor changes or withdraws their consent. |
__cmp.showBanner() | Shows the initial consent notice again. |
__cmp.hideBanner() | Hides the displayed notice. |
<a href="#" onclick="window.__cmp && __cmp.showPreferences(); return false;">
Manage my cookies
</a>The banner may not be loaded yet
The script loads asynchronously: always test for the presence of window.__cmp (and its ready property) before calling a method, as in the example above.
Reading the consent state
The __cmp object also carries the current state, read-only:
| Property | Content |
|---|---|
__cmp.consent | The per-category state, for example { necessary: true, analytics: true, advertisement: false }. |
__cmp.cats | The categories configured for the site. |
__cmp.ready | true when the banner is initialized. |
__cmp.regime | The consent regime applied to the visitor according to their location. |
__cmp.gpcApplied | true if a Global Privacy Control signal was honored. |
if (window.__cmp && __cmp.ready && __cmp.consent.analytics) {
// the visitor accepted the Analytics category
loadMyModule();
}The csm_consent cookie
The visitor's decision is kept in a single first-party cookie, csm_consent, valid for 365 days, set with SameSite=Lax; Secure on your site's registrable domain (so it also applies to your subdomains). Its value is an encoded JSON object:
| Field | Meaning |
|---|---|
id | The visitor's consent identifier (csm_ prefix), the one that appears in the record. |
v | The version of the configuration published at the time of the choice. |
c | The per-category detail (true / false). |
a | The action: accept_all, reject_all, save_preferences or withdraw. |
t | The decision's timestamp (milliseconds since the epoch). |
Reacting to decisions (dataLayer)
There is no callback subscription API: the integration goes through Google Tag Manager. On every decision, the banner pushes the Consent Mode update and the csm_consent_update event into the dataLayer. Create a custom event trigger on that name to fire a tag as soon as a visitor consents: it is exactly how the GA4 and Meta tags of the automatic installation re-fire without a reload.
window.dataLayer.push(["consent", "update", {
analytics_storage: "granted",
ad_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
/* … every Consent Mode v2 signal */
}]);
window.dataLayer.push({ event: "csm_consent_update" });