Skip to content

Install KookiOk with an AI coding agent

KookiOk is one <script> tag. Where the tag goes decides whether it can hold trackers back, and that is what an agent gets wrong without instructions. Give it the prompt below. The rest of this page is for the agent, which can read it as Markdown at https://api.kookiok.com/docs/install-with-ai-agent.md.

  1. Create a free account. The free plan has no limit on websites or page views and needs no credit card; it shows a small “Powered by KookiOk” label on the banner.
  2. Add the domain of your website.
  3. Copy your Domain Group ID from the install snippet. It is not a secret: every visitor’s browser sees it.

Replace YOUR_DOMAIN_GROUP_ID with your id.

Add the KookiOk cookie consent banner to this project. This is the tag, and its address must not change:
<script src="https://cdn.kookiok.com/consent.js?id=YOUR_DOMAIN_GROUP_ID"></script>
If you can open web pages, read https://api.kookiok.com/docs/install-with-ai-agent.md first: it has the steps
for each stack. These rules apply in any case:
1. If the id above is still a placeholder, ask me for it. Do not make one up.
2. Search the source for "consent.js?id=". If the tag is already there, stop and tell me.
3. Put the tag in the layout all pages share (without one, in every page), once per page, as the first script
in <head>: above Google Tag Manager, analytics and every other script. No async, no defer, no type="module",
not inside a tag manager.
Vite: index.html. Astro: the layout, with is:inline. WordPress: do not edit the theme, tell me to install
the KookiOk plugin from wordpress.org.
4. Next.js App Router is the exception: load the tag's address with next/script and
strategy="afterInteractive" in app/layout, and make every tracker inert (rule 5). Remove trackers loaded
with next/script or @next/third-parties. Render the inert tags as the dangerouslySetInnerHTML of one
<div hidden>, never as JSX children: KookiOk replaces them in the DOM and React would crash on the next
navigation.
5. Find every tracker, pixel and third-party embed (analytics, ads, heatmaps, chat, YouTube, maps). Make each
inert: <script type="text/plain" data-ag-consent="statistics" data-ag-src="..."> instead of src, inline
code with the same type and data-ag-consent, and <iframe data-ag-consent="marketing" data-ag-src="...">
without src. Categories: preferences, statistics, marketing. Leave strictly necessary scripts (payments,
sign-in) as they are, and the Google Tag Manager snippet (gtm.js, not gtag.js) too, except in Next.js App
Router, where it is a tracker like any other. Trackers started from bundled code must wait for
window.Kookiok?.hasConsent?.("statistics") and the window event "Kookiok:consentUpdate".
6. KookiOk runs Google Consent Mode v2 itself. Remove any gtag("consent", "default", ...) and
gtag("consent", "update", ...) calls from the project.
7. Do not write your own banner, do not bundle or self-host consent.js, and remove another consent banner
only after asking me.
Then show me the diff, the list of trackers you found with the category you gave each, and how to check it:
in a private window the banner appears, typeof window.Kookiok?.getConsent is "function" in the console, and
no request to a tracker is made before I choose.

After the agent has finished, deploy, open the Implementation page of your domain group in the dashboard, enter your live address in the Verify Installation card and click Verify.

  1. The tag goes in <head>, as the first script. <meta>, <title> and <link> may come before it.
  2. It loads synchronously: no async, no defer, no type="module", no lazy loading.
  3. It goes into the layout that all pages share (without one, into every page), once per page. A second copy does not run and warns in the console.
  4. It loads from https://cdn.kookiok.com/consent.js?id=.... Do not bundle, copy, proxy or pin it.
  5. Never edit generated or vendored files (node_modules, dist, .next, .nuxt, vendor and the like). In a monorepo, install in the package that renders the site; with several, ask which.
  6. A project that renders no HTML has nowhere to put the tag: stop and say so.

First in <head> of every page, or of the shared header: base.html.twig, layouts/app.blade.php, base.html, application.html.erb, _Layout.cshtml. In a Shopify theme: layout/theme.liquid, directly above {{ content_for_header }}.

<head>
<script src="https://cdn.kookiok.com/consent.js?id=YOUR_DOMAIN_GROUP_ID"></script>
<!-- everything else -->
</head>

First in <head> of index.html. Not in main.tsx or main.ts: bundled code runs too late.

Next.js manages <head> itself and preloads what next/script loads, so a tracker loaded that way is requested before any consent tool can stop it. Two steps, both required. Load KookiOk in app/layout.tsx:

app/layout.tsx
import type { ReactNode } from 'react';
import Script from 'next/script';
import { Trackers } from './Trackers';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<Script
src="https://cdn.kookiok.com/consent.js?id=YOUR_DOMAIN_GROUP_ID"
strategy="afterInteractive"
/>
<Trackers />
{children}
</body>
</html>
);
}

And write every tracker inert, as the inner HTML of one wrapper. KookiOk replaces each tag when it runs it; tags rendered as JSX children would be React’s own nodes, and the next client-side navigation after the visitor accepts would fail with a React error.

app/Trackers.tsx
const GA_ID = 'G-XXXXXXXXXX';
const TAGS = `
<script type="text/plain" data-ag-consent="statistics" data-ag-src="https://www.googletagmanager.com/gtag/js?id=${GA_ID}"></script>
<script type="text/plain" data-ag-consent="statistics">
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', '${GA_ID}');
</script>`;
export function Trackers() {
return <div hidden dangerouslySetInnerHTML={{ __html: TAGS }} />;
}

Remove the next/script trackers and the @next/third-parties components these tags replace. Google Tag Manager is a tracker like any other here: its snippet goes into TAGS with data-ag-consent="statistics".

A plain <script>, first in <Head> of pages/_document.tsx; next/script does not work there. Trackers go below it as plain inert tags, in _document.tsx too: React does not hydrate that file, so JSX children are safe there, unlike in _app.tsx. The Google Tag Manager snippet may stay as a plain inline script below the KookiOk tag. Nothing is tracked through next/script or @next/third-parties, which preload. A project with both routers needs both installs.

pages/_document.tsx
<Head>
<script src="https://cdn.kookiok.com/consent.js?id=YOUR_DOMAIN_GROUP_ID" />
</Head>

First entry of app.head.script in nuxt.config.ts (Nuxt 2: head.script), without async or defer:

nuxt.config.ts
export default defineNuxtConfig({
app: {
head: {
script: [
{ src: 'https://cdn.kookiok.com/consent.js?id=YOUR_DOMAIN_GROUP_ID', tagPosition: 'head' },
],
},
},
});

First in <head> of the shared layout. is:inline is required, or Astro processes the tag:

<script is:inline src="https://cdn.kookiok.com/consent.js?id=YOUR_DOMAIN_GROUP_ID"></script>

First in <head> of src/app.html, above %sveltekit.head%. Not in +layout.svelte.

Do not edit the theme. Tell the person to install the official plugin: in wp-admin, Plugins, Add Plugin, search for KookiOk, install, activate; then Settings, Kookiok, paste the Domain Group ID, Connect, Save Changes. A caching plugin must not defer, delay or combine cdn.kookiok.com.

Above the Tag Manager snippet in the page, which stays as it is. Never as a tag inside the container: that runs only once the container has loaded, too late to hold back what ran before it.

KookiOk holds trackers it recognizes by their address. Mark the rest, and everything written into the HTML, because browsers request what is in the HTML before a script can stop it:

<script type="text/plain" data-ag-consent="statistics" data-ag-src="/js/analytics.js"></script>
<script type="text/plain" data-ag-consent="marketing">
startMyPixel();
</script>
<iframe data-ag-consent="marketing" data-ag-src="https://www.youtube.com/embed/VIDEO_ID"></iframe>
  • statistics: analytics, heatmaps, session recording. marketing: advertising, conversion pixels, social and video embeds. preferences: remembered choices that the service can do without. If a tag fits none, ask.
  • Several categories (statistics,marketing) must all be granted.
  • Leave strictly necessary scripts alone (payments, sign-in, fraud protection). Never write type="text/plain" on them.
  • A tracker started from bundled code (npm install analytics) has no tag to mark. Start it like this:
let started = false;
function startWithConsent() {
if (started || !window.Kookiok?.hasConsent?.('statistics')) return;
started = true;
startMyAnalytics();
}
startWithConsent();
window.addEventListener('Kookiok:consentUpdate', startWithConsent);

The full contract, with its limits: Script Blocking and data-ag-consent.

KookiOk sends the defaults and the updates. Remove the project’s own gtag('consent', 'default', ...) and gtag('consent', 'update', ...) calls, so the state has one source; if their Tag Manager container has another consent tool’s template, tell the person. A Google tag in the HTML, or one served from the site’s own domain, is marked inert like any tracker; the page needs nothing else. Basic or Advanced is the person’s choice in the dashboard; Basic is the default. In Advanced, a tag in their Tag Manager container for a vendor KookiOk does not recognize needs “Require additional consent” there: tell them. Details: Google Consent Mode v2.

If the site sends this header, it has to allow:

DirectiveValueWithout it
script-srchttps://cdn.kookiok.comno banner
connect-srchttps://api.kookiok.comchoices are not recorded
style-src'unsafe-inline'the banner has no styles
font-srchttps://api.kookiok.coma fallback font, on banners that use a self-hosted one
img-srcdata:missing check marks

'unsafe-inline' for styles loosens the policy: show the person that line and ask.

In the browser, in a private window:

  1. The banner is on the screen.
  2. Console: typeof window.Kookiok?.getConsent is "function", and no warning says that consent.js is included more than once.
  3. Network, before any choice: consent.js answers 200, and there is no request to an analytics, advertising or embed host.
  4. Console: document.querySelectorAll('[data-ag-blocked]') lists what is held.
  5. Accept all: the trackers load, and in a single-page app the next navigations still work. Then, in a new private window, Reject all: nothing loads, also after a reload.

In the source: the tag is the first script in the built HTML of <head> (Next.js App Router excepted), without async, defer or type.

On localhost and on any host that is not in the domain group, the banner works, the console says that the hostname is not registered, and no choice is recorded. That is expected before the deploy. On the live address it means that the person still has to add the domain in the dashboard.

  • The diff, and each tracker with the category you gave it.
  • What you could not mark, and why.
  • That they add the domain in the dashboard and, after the deploy, click Verify in its Verify Installation card.
  • That KookiOk is a tool, not legal advice: it writes no privacy policy, and it is not a certified CMP for programmatic advertising (its IAB TCF v2.2 API is compatible, not registered).