Blocking & consent
JavaScript API
Read the visitor's choice, reopen the preferences, or withdraw consent from your own code.
Once the script has loaded, it exposes window.CMP.
Reading consent
window.CMP.consent;
Holds the visitor’s current choice as one true/false value per category — necessary, functional, analytical, marketing.
Reopening the preferences
Give visitors a way to change their mind — a “Cookie settings” link in your footer, for example:
<a href="#" onclick="window.CMP.show(); return false;">Cookie settings</a>
The banner also has an optional floating Cookie Settings button (see Banner design) that does the same without code.
Withdrawing consent
window.CMP.withdraw();
Clears the stored answer, sets every optional category back to refused, and shows the banner again so the visitor can choose afresh.
Events
| Event | Fires when |
|---|---|
cmp:consent-changed |
The visitor makes or changes a choice. |
cmp:consent-restored |
A returning visitor’s earlier choice is loaded. |
Both carry the choice as event.detail.consent:
window.addEventListener('cmp:consent-changed', (event) => {
if (event.detail.consent.analytical) {
// start your own analytics
}
});