Skip to content

JavaScript API

The snippet adds a window.CookieDoo object.

Member What it does
CookieDoo.consent The current consent: { necessary, preferences, statistics, marketing }, each true or false; null before the visitor has chosen in an opt-in region.
CookieDoo.hasConsent("marketing") true if the category is allowed.
CookieDoo.open() Opens the banner settings, for example from a “Cookie settings” link in your footer.
<a href="#" onclick="CookieDoo.open(); return false;">Cookie settings</a>

Whenever consent is applied (after a choice, and at page load for a returning visitor) CookieDoo dispatches a CookieDooConsentUpdate event on window, with the consent as detail:

window.addEventListener("CookieDooConsentUpdate", (event) => {
if (event.detail.statistics) {
// start your own analytics
}
});

For Google Tag Manager, use the cookiedoo_consent_update dataLayer event instead (see Tag Manager).

On banners with rules by country, the snippet also provides the IAB GPP API (CMP API 1.1), for ad tags rather than for your own code. It supports ping, addEventListener, removeEventListener, hasSection, getSection and getField, and answers postMessage calls from iframes through the __gppLocator frame. See Rules by country.

__gpp("addEventListener", (event) => {
if (event.eventName === "signalStatus" && event.data === "ready") {
console.log(event.pingData.gppString, event.pingData.applicableSections);
}
});