Appearance
Consent cookie & events
Reference for wiring your own code — or Google Tag Manager — to the visitor's consent decision. Use this when the Consent Mode toggles and category gating don't cover what you need.
Read the decision from JavaScript
window.CookieWave is the supported way to read consent. It works the same on every banner CookieWave serves — the standard banner, the IAB TCF banner and the US opt-out notice — so code written against it keeps working if you switch.
window.CookieWave.getConsent()
Returns the visitor's current decision, or null while there is none yet (a first-time visitor who has not answered, or a page where the banner script has not finished loading).
js
const consent = window.CookieWave?.getConsent?.()
consent.categories // { necessary: true, analytics: true, marketing: false }
consent.accepted // ['necessary', 'analytics']
consent.rejected // ['marketing']
consent.hasDecision // true
consent.consentId // 'a1b2c3d4-…' — see belowcategories lists every category the site asks about, true where the visitor allowed it. The standard keys are necessary, preferences, analytics and marketing; a site may define others.
The cookiewave:consent event
Fired on document whenever a decision is made, and once on every page load for a visitor who decided earlier. event.detail is the same object getConsent() returns, plus where it came from:
detail.source | Fires when |
|---|---|
first | the visitor makes their first choice |
update | the visitor changes an earlier choice |
stored | the page loads for a visitor who already decided |
The decision is stored before the event fires, so code that reads the consent cookie from a listener finds it written. Nothing is announced before the visitor decides: the defaults in force until then are not a decision.
Example: gate your own SDK
The banner script loads in the <head>, so a returning visitor's decision is often announced before your code runs. Listen first, then read what is already there — applying the same decision twice is harmless:
js
let started = false
function sync(consent) {
if (!consent || !consent.hasDecision) return
const wanted = consent.categories.analytics === true
if (wanted && !started) { startAnalyticsSdk(); started = true }
if (!wanted && started) { stopAnalyticsSdk(); started = false }
}
document.addEventListener('cookiewave:consent', (e) => sync(e.detail))
sync(window.CookieWave?.getConsent?.())The visitor's consent ID
consentId is the random identifier the visitor's decisions are recorded under in your consent records. It is not derived from anything about the visitor and is not shared between sites.
It is what a visitor quotes when they ask you to show what they agreed to. To show it on a page — a privacy policy, an account page — read it from getConsent():
html
<p>Your consent ID: <code id="my-consent-id">no choice recorded yet</code></p>
<script>
function showId(consent) {
if (consent && consent.consentId) {
document.getElementById('my-consent-id').textContent = consent.consentId
}
}
document.addEventListener('cookiewave:consent', (e) => showId(e.detail))
showId(window.CookieWave?.getConsent?.())
</script>On WordPress, the CookieWave plugin's [cookiewave_consent_id] shortcode does exactly this.
Other methods
| Method | Does |
|---|---|
window.CookieWave.showPreferences() | reopens the consent preferences — see Reopen link |
window.CookieWave.getTcString() | IAB TCF banner only: the visitor's TC string |
Events from the standard banner
The standard (non-TCF) banner also dispatches its consent library's own events on window. They are not sent by the IAB TCF banner or the US opt-out notice — prefer cookiewave:consent for anything new.
| Event | Fires when |
|---|---|
cc:onFirstConsent | the visitor makes their first-ever choice |
cc:onConsent | on first consent and on every page load with a stored choice |
cc:onChange | the visitor changes an existing choice |
cc:onModalShow / cc:onModalHide | the banner or preferences modal opens / closes |
For gating a tag, cc:onConsent (does the visitor consent now, including on return visits) plus cc:onChange (they just changed their mind) is the pair you want.
Payload
js
window.addEventListener('cc:onConsent', (e) => {
e.detail.cookie.categories // e.g. ['necessary', 'analytics']
e.detail.cookie.consentId // stable random visitor id
e.detail.cookie.consentTimestamp
})
window.addEventListener('cc:onChange', (e) => {
e.detail.cookie.categories // the full current set
e.detail.changedCategories // just what flipped this time
})categories is the array to check. The standard keys are necessary, preferences, analytics and marketing; a site may define others.
Example with the library events
js
let started = false
function sync(categories) {
const wanted = categories.includes('analytics')
if (wanted && !started) { startAnalyticsSdk(); started = true }
if (!wanted && started) { stopAnalyticsSdk(); started = false }
}
window.addEventListener('cc:onConsent', (e) => sync(e.detail.cookie.categories))
window.addEventListener('cc:onChange', (e) => sync(e.detail.cookie.categories))The consent cookie
On the standard banner, the visitor's decision is stored in a first-party cookie named cw_consent, URL-encoded JSON:
json
{
"categories": ["necessary", "analytics"],
"consentId": "a1b2c3d4-…",
"revision": 0,
"consentTimestamp": "2026-07-26T10:00:00.000Z",
"lastConsentTimestamp": "2026-07-26T10:00:00.000Z",
"languageCode": "en"
}Read it server-side, or from a tag manager, to branch on consent without listening for an event. The IAB TCF banner stores its decision as a TC string instead (the euconsent-v2 cookie), so on a TCF site read consent through getConsent() in the browser.
Google Tag Manager
Two ways to fire a non-Google tag on consent:
Custom Event trigger. In GTM, create a Custom Event trigger with the event name cc:onChange (enable regex matching if you also want cc:onConsent). Bind your tag to it. GTM's dataLayer does not receive these by default, so push them yourself in a small bootstrap:
js
window.addEventListener('cc:onConsent', (e) =>
dataLayer.push({ event: 'cc:onConsent', cwCategories: e.detail.cookie.categories }))
window.addEventListener('cc:onChange', (e) =>
dataLayer.push({ event: 'cc:onChange', cwCategories: e.detail.cookie.categories }))1st-party cookie variable. Create a GTM 1st-Party Cookie variable reading cw_consent, and check whether it contains the category you need in your trigger condition.
For Google tags specifically you need neither — turn on the Google Consent Mode toggle and GTM gates them natively.