Skip to content

Script Blocking and data-ag-consent

Blocking is rule-based, not blanket. The consent script suspends what a rule or an annotation names - a curated tracker URL pattern, a classified cookie or storage key, or a data-ag-consent attribute - and activates suspended elements the moment consent covers them. Anything else on your page runs normally.

This page documents exactly what is blocked before consent, what is not, and the one case where you must act: self-hosted trackers served from your own domain require a data-ag-consent annotation. That step is part of installation, not an optional extra.

Under GDPR the model is opt-in: trackers must not run until the visitor consents. Under CCPA the model is opt-out: nothing is blocked before a choice. Once the visitor opts out - Reject all, a choice that refuses a category, a withdrawal, or a Global Privacy Control signal, which is recorded automatically without a banner unless the visitor gives consent themselves over it - the refused categories are blocked as under GDPR, from that moment and on every later page. Everything below describes the opt-in behavior, which an opt-out under CCPA switches on.

Before consent, the script enforces three kinds of rules plus your annotations:

Rule typeSourceWhat it stops
URL rulesCurated tracker database maintained by Kookiok (Google Analytics, Meta Pixel, Hotjar, Matomo, DoubleClick, and many more)Matching <script>, <iframe> and <img> elements that JavaScript points at a URL (el.src = ..., setAttribute('src', ...)): never requested. The same tags written in your page’s HTML: a script is kept from running, but the browser has already requested it (see the MutationObserver). Matching fetch / XMLHttpRequest / sendBeacon requests: not sent
Cookie name rulesCurated database + cookies our scanner discovered on your sites and classifieddocument.cookie writes to those names. Blocked writes are held (the latest per cookie name), and the ones the visitor’s consent covers are written for real when they decide; a cookie the page deleted in the meantime is not brought back. As with storage, a write for a category granted only later in the same visit is not recovered
Storage key rulesCurated database + storage entries our scanner discovered and classifiedlocalStorage / sessionStorage writes to those keys, and reads of them come back empty. Blocked writes are held in a buffer (the latest per key in each storage; no more are kept once 200 writes, cookies included, are held), and the ones the visitor’s consent covers are written for real when they decide. The buffer is emptied at that point, so a write for a category granted only later in the same visit is not recovered
Annotationsdata-ag-consent attributes you place in your markupExecution of the annotated element until its categories are granted

All rules are consent-aware. Once a visitor grants a category, that category’s URL and cookie rules stop matching: suspended elements are activated, and new loads and writes pass straight through. A cookie or storage write held earlier on the same page is written at that moment, before the suspended elements run (so a fresh write of theirs wins), and a refused category’s writes are dropped.

Storage is the exception, and it is coarser than the rest: the moment the visitor grants any non-necessary category, the storage interception is lifted for all of them. A visitor who accepts only preferences is no longer protected from a statistics or marketing storage write. Cookie rules stay per-category, so the same tracker’s cookie is still blocked - budget for that asymmetry if you rely on storage gating.

Refusing and withdrawing both clean up what was already stored:

  • Reject all - and any decision that leaves a category off - stops future tracking for the refused categories (rules keep matching, so nothing new is loaded, written or sent) and deletes the classified cookies and storage entries those categories already put on the device.
  • Withdraw consent (the privacy trigger, the cookie declaration’s withdraw button, or Kookiok.revokeConsent()) does the same for every non-necessary category, whatever the visitor had granted. It also records the withdrawal, sends Google Consent Mode a consent update with everything denied, updates the IAB TCF purposes, and shows the banner again. On a page that embeds only declaration.js (a cookie-policy page without the consent script), the withdraw button records the withdrawal and deletes what the consent script would delete - the classified non-necessary cookies (never by a generic name) and storage entries; where the visitor is under an opt-out model (CCPA, or a region you mapped to none), it also stores the opt-out, so the next page with the consent script does not grant again.

Deletion reaches cookies visible to JavaScript at path /, on the page’s host and on each of its parent domains - a tracker’s _ga on .example.com included. HttpOnly cookies and cookies set on another path have to be cleared by your own server.

What is deleted are the cookies your cookie declaration classifies for a refused category, and the curated tracker names that are distinctive (_ga, _fbp, _hjSession_*, hubspotutk). The curated names a site may well use for its own cookies are never deleted, so a refusal cannot sign your visitors out or empty their basket: the cookies SID, ID, AID, ANON, uuid, C, sp, mc, loc, locale, PREF, player, guest_id, Conversion, fr, sb and xs, and storage keys starting s_ or li_. That list is reviewed entry by entry. Those names are still blocked before consent (see the note on naming below).

The blocking mode is set per domain group in the banner editor, Privacy tab, “Blocking mode”. The default is auto.

Enforcementautomanual
Curated tracker URL rules (script / iframe / img)YesNo
Network interception (fetch, XMLHttpRequest, sendBeacon) against curated URL rulesYesNo
Cookie name rules (document.cookie, with replay buffer)YesNo
Storage key rules (localStorage / sessionStorage, with replay buffer)YesNo
data-ag-consent annotated elements written into the page’s HTMLYesYes
data-ag-consent annotated elements inserted later by JavaScriptPartly - the annotation is read, but too late to stop a tag that has already started loading. See Tags added after the page has loadedNo
Activation of annotated / suspended elements on consentYesYes

Auto is rule-based, not a blanket blocker. A script that matches no curated pattern, sets no classified cookie or storage key, and carries no annotation runs normally - including all of your first-party site code.

Google’s own tags follow the Google Consent Mode setting: in Basic the Google tag (gtag.js) and the Tag Manager container (gtm.js) wait for statistics consent like any tracker; in Advanced they load before a decision with everything denied, while the consent script’s defaults are what they read, and the requests they send without advertising storage go through. Every other vendor the consent script recognizes stays blocked in both. In Advanced, a tag your Tag Manager container adds for a vendor it does not recognize runs when the container does, unless you set Tag Manager’s “Require additional consent” on it. See Google Consent Mode v2.

Naming leaks the same way the URL matching above does. Cookie and storage rules match by name, and a few trackers use names short enough to collide with ordinary first-party ones: a cookie called uuid, ID or locale, or a storage key starting s_, mp_, li_ or amp_, matches a curated rule and its write is held before consent - silently, since a held write throws nothing - and written only once the visitor grants that category. If your own state disappears on a first visit and returns after consent, that is the cause. Rename the key, or tell us so we can tighten the rule.

Manual disables every interceptor. Nothing is blocked unless you annotate it, so in manual mode the data-ag-consent markup is the entire enforcement surface. If you switch to manual, annotate your trackers first, or you will be running them pre-consent.

In manual mode the annotation works because of the type="text/plain" you write next to it - there is no interceptor to catch anything else. Two consequences worth knowing before you choose manual:

  • An annotated tag without type="text/plain" executes normally and is then labelled data-ag-blocked after the fact. It looks blocked and is not - and on consent it runs a second time.
  • A tag that JavaScript inserts after the page has loaded is not gated at all, whatever it is annotated with.

Auto mode installs five interception surfaces, so the rules apply across the ways a tracker normally reaches a page - a <script>, <iframe> or <img> however it was created, and outbound HTTP from code already running:

  1. src property setters on HTMLScriptElement, HTMLIFrameElement and HTMLImageElement - catches el.src = url however the element was created.
  2. Element.setAttribute - catches el.setAttribute('src', url).
  3. document.write / document.writeln - rewrites tracker tags in the HTML string before the parser sees them.
  4. A MutationObserver - catches elements inserted by the parser or via innerHTML that never passed through the hooks above. It acts once an element is in the page, which is too late to stop the request: browsers start fetching the scripts and images in your page’s HTML ahead of the parser, typically while the consent script itself is still loading. A script caught this way does not run, but its file has been requested from the vendor before consent, with the visitor’s IP address and your page’s address. An <iframe> or <img> whose markup carries the URL is requested the same way, from your HTML in every browser and, depending on the browser, when inserted via innerHTML. Write such tags with type="text/plain" and data-ag-consent, and embeds with data-ag-src instead of src (the contract below): then nothing is requested until the visitor agrees.
  5. Network interception - fetch, XMLHttpRequest and sendBeacon calls are matched against the same URL rules, which catches SDKs bundled into your main JavaScript (a bundled analytics SDK never creates a script tag, but it does call home).

A blocked script element is kept in the DOM with type="text/plain", its URL moved from src to data-ag-src, and a data-ag-blocked attribute recording the category. That makes blocking directly inspectable - see Verifying the behavior.

Some site builders lock browser APIs before any embed can run. Wix redefines document.cookie itself, and when its security hardening is on it also makes window.fetch and window.XMLHttpRequest read-only and gives every <iframe> it creates its own setAttribute, which goes straight to the browser’s. A surface the page will not let the runtime wrap is skipped, and only that surface - the banner, consent records and every other surface keep working.

On a hardened Wix page that means fetch, document.cookie and setAttribute on iframes: an iframe that a widget creates and points at YouTube or Google Maps with setAttribute('src', ...) loads before consent (the src property is still intercepted). XMLHttpRequest stays intercepted, on the prototype its instances really use, for requests created after the consent script has loaded; an instance created earlier keeps Wix’s own open and is not held.

What had to be skipped is reported once, as a single console warning starting Kookiok: unavailable blocking layers on this page, and in the unavailableLayers field of the KookiokOnLoad event - see JavaScript API. If a tracker of yours makes its requests through a skipped API, gate the script that makes them with data-ag-consent (below), so it does not run before consent at all.

Those five surfaces are the ones a tracker realistically uses, but they are not every way a browser can fetch something. A URL reached through srcset, a <link rel="preload">, a media or <object> element, a CSS url(), a WebSocket, an EventSource, a dynamic import() or a service worker is not inspected, and neither is anything inside an <iframe> your page embeds, which runs in its own context with its own copy of these APIs. An inline <script> with tracker code in it has no URL to match, so only an annotation can gate it. If a tracker of yours reaches the page one of those ways, annotate it rather than assuming the rules found it.

Annotate a tag you want gated by setting type="text/plain" (so the browser itself never executes it early) and data-ag-consent with one or more consent categories:

<!-- external script, gated on statistics -->
<script type="text/plain" data-ag-consent="statistics"
src="/wp-content/plugins/some-analytics/tracker.js"></script>
<!-- inline script, gated on multiple categories (ALL must be granted) -->
<script type="text/plain" data-ag-consent="statistics,marketing">
window.someAnalyticsConfig = { siteId: 42 };
</script>

For <iframe> and <img>, put the URL in data-ag-src and omit src, so the browser has nothing to load pre-consent:

<iframe data-ag-src="https://www.youtube.com/embed/VIDEO_ID"
data-ag-consent="marketing"></iframe>
ValueMeaningBlocked before consent?
preferences, statistics, marketing”This is a tracker of this category.”Yes - held until the category is granted
Comma-separated, e.g. statistics,marketingTracker spanning several categoriesYes - runs only when every listed category is granted
necessary”This is a strictly-necessary tracker.”No - never blocked. It is a real consent category, and it is where the tracker’s cookies belong in your declaration - classify them there yourself, the annotation does not tell the scanner
ignore”This is not a tracker. Never touch this element.”No - never blocked, never re-executed, not part of consent at all

As single values, necessary and ignore are treated identically by the blocker (neither is ever suspended), but they do not mean the same thing. necessary makes a compliance claim - a tracker your service cannot run without - and its cookies belong in the Necessary section of your declaration. ignore opts the element out of consent management entirely; use it for site functionality like jQuery, theme bundles, or a UI library that a rule matches by mistake. If it is not a tracker, ignore is the honest annotation.

One limit on ignore: it exempts the element, not the URL. It works on a tag in your page’s HTML, but if JavaScript creates the element and assigns a src that matches a curated rule, the URL is checked before the annotation is read and the element is suspended anyway. For a first-party file a curated rule matches by mistake, the durable fix is to change the URL or tell us about the false positive rather than to annotate around it.

  • No consent yet: annotated tags stay inert.

  • Visitor grants the covering categories: tags are activated in the same page view, no reload - inline scripts run at once, external scripts and data-ag-src iframes and images are fetched and run when they arrive. The runtime fires KookiokOnScriptsUnblocked once it has finished handing the tags back to the browser, which is before any external file has actually executed. The event marks a consent decision, so it does not fire on a later page load that simply reuses the stored consent.

  • Returning visitor with stored consent: annotated tags are activated on every page load once the DOM is ready - unless the stored decision no longer counts: a Global Privacy Control signal started to apply to them after they decided (a decision they made themselves while it applied keeps counting), or the decision was an implied consent given outside the regulated regions and they are now treated as GDPR. Then the tags stay blocked: under the signal the visitor is refused automatically and can give consent from the privacy button; otherwise the banner asks again. Publishing a banner change does not ask anyone again: stored decisions stay valid.

  • Rejection: tags stay blocked, and stay blocked on the next load, and the refused categories’ classified cookies and storage entries are deleted. A script that already executed cannot be un-executed in place.

  • Withdrawal: as above, for every non-necessary category.

  • Global Privacy Control: visitors to whom the signal applies are refused automatically (everywhere by default; with “Only where the law requires it”, under the US opt-out model, where no banner is shown, and for visitors placed in the US or nowhere), so annotated tags stay blocked for them until they give consent themselves from the privacy button. See Global Privacy Control.

  • Tags added after the page has loaded: give them a real src and the annotation, with no type="text/plain". Auto mode gates them if their URL matches a curated rule, and lets them run once consent covers the annotated category. That is the shape to rely on.

    A tag inserted as type="text/plain" is handed back on insertion too, in every regulation and every consent state, as soon as the visitor’s current decision covers its categories. Until 2026-08-15 this rode on the tracker-blocking watcher, so it worked only while consent was partial: a visitor who accepted everything released the watcher, the opt-out model never installed it, and a pre-planted inert tag stayed blank with nothing logged. If you worked around that by inserting embeds live on the click, that still works and needs no change.

WordPress prints each enqueued classic script with id="{handle}-js", so you can find a handle by viewing your page source. Annotate the handles you want to gate with a script_loader_tag filter (in your child theme’s functions.php or a small mu-plugin):

add_filter( 'script_loader_tag', function ( $tag, $handle ) {
$gate = [
// handle => consent category
'burst' => 'statistics',
'burst-timeme' => 'statistics',
'google-recaptcha' => 'marketing',
];
if ( isset( $gate[ $handle ] ) ) {
// Classic themes print type="text/javascript"; drop it so the tag ends up
// with one type attribute rather than two.
$tag = preg_replace( '/\stype=([\'"])[^\'"]*\1/i', '', $tag );
$tag = str_replace(
'<script ',
'<script type="text/plain" data-ag-consent="' . esc_attr( $gate[ $handle ] ) . '" ',
$tag
);
}
return $tag;
}, 10, 2 );

The handles above are the ones those two plugins register today, and they show why you should check rather than copy. Burst Statistics enqueues its timing script burst-timeme as a dependency of burst, so WordPress prints it first and gating only burst would leave it running - and Burst’s “ghost mode” renames both to b and b-timeme. Contact Form 7 splits its reCAPTCHA support in two: google-recaptcha is the tag that loads Google’s api.js and is the one that needs gating, while wpcf7-recaptcha is Contact Form 7’s own integration code.

Four properties of this filter are worth knowing before you use it:

  • wp_add_inline_script() config is gated too. The $tag string WordPress passes to script_loader_tag includes any inline scripts attached to the handle that way (printed as id="{handle}-js-before" / "{handle}-js-after"). The str_replace annotates every <script in that string, so one gated handle can produce more than one gated tag. That is correct behavior: blocking a loader while letting its inline init run would be a leak. Data passed with wp_localize_script() is printed separately as -js-extra and does not pass through the filter, which is harmless - it declares variables rather than sending anything.
  • Some things this filter cannot reach. A handle registered with no file of its own (wp_register_script( 'x', false ), the usual way a plain tracker snippet is enqueued) is printed without ever passing through script_loader_tag, and script modules (wp_enqueue_script_module(), WordPress 6.5 and later) print with a -js-module id and do not pass through it either. Annotate those in the template that emits them.
  • A -before config script still runs first. Inline code is handed back to the browser immediately on consent, while the external file it configures has to be fetched first, so the configuration is always in place before the loader runs.
  • An -after init script does not wait for its loader. For the same reason, inline code attached with wp_add_inline_script( $handle, '...', 'after' ) runs before the external file arrives, and any call it makes into that file raises a ReferenceError. If a handle you want to gate carries -after code, move that code into the loader, or have it wait for the object it needs rather than assuming it exists.

Self-hosted trackers: annotation is required

Section titled “Self-hosted trackers: annotation is required”

If you run a tracker that is served from your own domain - an analytics plugin under /wp-content/plugins/..., a self-hosted analytics script bundled into your build - annotating it with data-ag-consent is a required installation step. Without the annotation, that tracker runs before consent. This is not an optional hardening.

Two facts combine to make it required:

  1. URL rules cannot see it. To a URL rule, /wp-content/plugins/burst-statistics/... and /wp-content/themes/your-theme/... differ only in path, and neither contains a curated tracker’s artifact. Kookiok will not guess which of your own paths are trackers, so no URL rule fires.
  2. Name-based rules stop storage, not execution - and only once we know the names. A self-hosted tracker’s cookie and storage keys reach your rules only after a scan has discovered and classified them; until then nothing about it is blocked at all. Even after that, blocking the identifier is not blocking the tracker: the script itself still executes and can still send beacons or transmit visitor data before consent. Under GDPR and the ePrivacy rules, that pre-consent access and transmission is exactly what needs the visitor’s permission.

Canonical example - Burst Statistics (WordPress). Burst is served from yoursite.com/wp-content/plugins/burst-statistics/, and its cookie names are not in our curated database - they enter your configuration only once a scan has classified them. So on a freshly connected site Burst is entirely unblocked, and after a scan its storage writes are stopped while the script still runs and sends its first-party beacons on every unconsented page view. The fix in both cases is the filter shown above: gate the Burst handles with data-ag-consent="statistics".

Self-hosted trackers blocked out of the box

Section titled “Self-hosted trackers blocked out of the box”

Some self-hosted trackers leave distinctive artifacts in their URLs, and for those the curated database does apply:

  • Matomo / Piwik - the anchors matomo. and piwik. match the standard filenames (matomo.js, matomo.php, piwik.js, piwik.php) wherever they are served from, including under your own domain, plus matomo.<your-domain> subdomain installs and their Matomo Tag Manager containers (.../js/container_*.js on such a host) and cdn.matomo.cloud. The one exception follows from the self-origin guard: on a page that is itself served from a host containing matomo., the rule is disabled for that page, so browsing your own Matomo interface never risks breaking it.

If you renamed the files or serve such a tracker from a URL that contains neither anchor, it is in the same position as Burst: annotate it.

Kookiok’s curated rules classify Google reCAPTCHA (google.com/recaptcha, gstatic.com/recaptcha, and the _GRECAPTCHA cookie) as necessary. That means reCAPTCHA loads without consent by default.

You have three options, and they are not equal. Only the first avoids a trade-off:

  1. Replace reCAPTCHA with spam control that calls no third party. A honeypot field plus a server-side filter such as Akismet protects the form without sending anything to Google, so there is no pre-consent request to gate and the form works for every visitor whatever they choose. If your forms can be defended this way, stop here - the other two options both force a trade, and this one does not.
  2. Gate it on consent (below). Nothing reaches Google before the visitor agrees, but visitors who decline get no reCAPTCHA token, so protected forms will reject their submissions.
  3. Leave the default. Forms work for everyone, but Google receives every visitor’s IP address on page load, before any consent.

A customer who took option 1 put it well: it is the only one that gives you a working form and zero pre-consent requests at the same time.

If you are choosing between 2 and 3, both sides of that decision deserve to be stated plainly:

  • Why necessary is the default. reCAPTCHA exists to stop fraud and abuse, and most CMPs apply the fraud-and-security exemption to it. Blocking it outright breaks every form it protects - contact, login, checkout - for every visitor who has not consented, and it breaks them silently. A lead form that swallows submissions is its own kind of harm.
  • Why that reading is contested. The French CNIL has rejected the security exemption for reCAPTCHA in an enforcement decision: in its Cityscoot ruling (délibération SAN-2023-003, 16 March 2023) it fined the operator under Article 82 of the French Data Protection Act for deploying reCAPTCHA on its site and app without informing users or obtaining their prior consent, holding that the site publisher, not Google, carries that obligation. Under a CNIL-aligned reading, necessary is not a defensible classification, particularly for audiences in France.

The stricter choice is fully supported. Annotate the reCAPTCHA tag with a consent category and it is gated like any other tracker: for a tag in your page’s HTML, the annotation takes precedence over the curated necessary category. On WordPress, gate the handle that enqueues Google’s api.js - google-recaptcha in the filter above - with data-ag-consent="marketing". In plain HTML, annotate the api.js tag directly:

<script type="text/plain" data-ag-consent="marketing"
src="https://www.google.com/recaptcha/api.js"></script>

This works because the tag is in the page’s markup, where the type="text/plain" keeps the browser from running it. If instead a plugin injects reCAPTCHA from JavaScript after the page loads, annotating the element it creates does not gate it: the URL is checked against the curated rules at the moment the script’s src is assigned, and reCAPTCHA passes that check as necessary before the annotation is ever read. Gate reCAPTCHA at the source - the handle or the template that emits the tag - rather than on a dynamically created element.

Be equally clear-eyed about the consequence: visitors who do not grant marketing will not get reCAPTCHA, so protected forms will not pass CAPTCHA validation for them. Plan for that - degrade gracefully server-side, or prompt for consent at the form. If neither is acceptable, that is the argument for option 1 above: removing the third party entirely is the only route that costs you nothing.

Blocked elements are directly inspectable. Open your site in a private window (no consent cookie), open DevTools, and run:

document.querySelectorAll('[data-ag-blocked]')

Every suspended element is listed with its category in data-ag-blocked; blocked scripts additionally show type="text/plain" and their URL parked in data-ag-src. Accept consent and run it again - elements whose categories you granted are gone from the list and active. Nothing on this page needs to be taken on faith.

Two things the snippet cannot tell you, so check them alongside it:

  • A listed element is not proof that nothing was sent. The attribute records that the runtime suspended the element. If the tag reached the browser with a real src and no type="text/plain" - an unannotated <img> pixel, or an annotation without the type - the request can already have left before the element was suspended. Confirm against the Network panel, filtered by the tracker’s host.
  • An unlisted element is not proof that nothing is blocked. A tag you suspended yourself with type="text/plain" is inert whether or not Kookiok has labelled it, and in manual mode nothing labels it. document.querySelectorAll('[data-ag-consent]:not([data-ag-blocked])') lists the unlabelled ones, most usefully the necessary and ignore tags that were given a type="text/plain" they should not have, and are therefore dead.

To find a misspelled category, grant every category and run the first query again. Anything still listed is annotated with a value no consent can satisfy.