Install Kookio.
One script first in the head, then mark the tags that must wait for a yes.
The script, then your tags
The script goes before every analytics or marketing tag. A tag that needs consent waits as inert markup.
<head>
<script
src="https://cdn.kookio.example/sdk/v1/kookio.js"
data-site-id="ks_your_site_id"></script>
<script
type="text/plain"
data-kookio-category="analytics"
data-src="https://example.com/analytics.js"></script>
</head>
<iframe
title="Video"
data-kookio-category="marketing"
data-src="https://example.com/embed"></iframe>
<!-- Any link can reopen the preferences -->
<a href="#" data-kookio-open-preferences>Cookie settings</a>The categories are functional, analytics and marketing. A hidden iframe shows a short note with a Cookie settings button.
Ask from your own code
One object, window.Kookio, and two events on the document.
| Call | What it does |
|---|---|
| Kookio.ready() | Resolves with the consent, once loaded. |
| Kookio.getConsent() | A copy of the current choice. |
| Kookio.hasConsent(category) | True when that category is allowed. |
| Kookio.showPreferences() | Opens the preferences panel. |
| Kookio.setConsent(categories) | Records a custom choice. |
| Kookio.acceptAll() Kookio.rejectAll() | The same as the banner buttons. |
| Kookio.withdrawConsent() | Switches every optional category off. |
| Kookio.onWithdraw(category, fn) | Calls your function on withdrawal. |
document.addEventListener('kookio:ready', (event) => {
console.log(event.detail.consent);
});
document.addEventListener('kookio:consentChanged', (event) => {
const { previous, current, reason } = event.detail;
});What Kookio cannot do
Block a tag already running
A normal script tag loads before any choice. Move it to inert markup.
Undo what was sent
Withdrawal reloads the page to stop a running tag. Data already sent stays sent.
Remove every cookie
HttpOnly and third-party cookies are out of a script’s reach.