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.
Before you paste the prompt
Section titled “Before you paste the prompt”- 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.
- Add the domain of your website.
- Copy your Domain Group ID from the install snippet. It is not a secret: every visitor’s browser sees it.
The prompt
Section titled “The prompt”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 stepsfor 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, andno 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.
Rules for the agent
Section titled “Rules for the agent”- The tag goes in
<head>, as the first script.<meta>,<title>and<link>may come before it. - It loads synchronously: no
async, nodefer, notype="module", no lazy loading. - 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.
- It loads from
https://cdn.kookiok.com/consent.js?id=.... Do not bundle, copy, proxy or pin it. - Never edit generated or vendored files (
node_modules,dist,.next,.nuxt,vendorand the like). In a monorepo, install in the package that renders the site; with several, ask which. - A project that renders no HTML has nowhere to put the tag: stop and say so.
Where the tag goes
Section titled “Where the tag goes”Plain HTML and server templates
Section titled “Plain HTML and server templates”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>React, Vue or Svelte on Vite
Section titled “React, Vue or Svelte on Vite”First in <head> of index.html. Not in main.tsx or main.ts: bundled code runs too late.
Next.js, App Router
Section titled “Next.js, App Router”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:
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.
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".
Next.js, Pages Router
Section titled “Next.js, Pages Router”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.
<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:
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>SvelteKit
Section titled “SvelteKit”First in <head> of src/app.html, above %sveltekit.head%. Not in +layout.svelte.
WordPress
Section titled “WordPress”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.
Google Tag Manager
Section titled “Google Tag Manager”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.
Trackers and embeds
Section titled “Trackers and embeds”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 installanalytics) 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.
Google Consent Mode v2
Section titled “Google Consent Mode v2”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.
Content-Security-Policy
Section titled “Content-Security-Policy”If the site sends this header, it has to allow:
| Directive | Value | Without it |
|---|---|---|
script-src | https://cdn.kookiok.com | no banner |
connect-src | https://api.kookiok.com | choices are not recorded |
style-src | 'unsafe-inline' | the banner has no styles |
font-src | https://api.kookiok.com | a fallback font, on banners that use a self-hosted one |
img-src | data: | missing check marks |
'unsafe-inline' for styles loosens the policy: show the person that line and ask.
Verify
Section titled “Verify”In the browser, in a private window:
- The banner is on the screen.
- Console:
typeof window.Kookiok?.getConsentis"function", and no warning says that consent.js is included more than once. - Network, before any choice:
consent.jsanswers 200, and there is no request to an analytics, advertising or embed host. - Console:
document.querySelectorAll('[data-ag-blocked]')lists what is held. - 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.
Tell the person
Section titled “Tell the person”- 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).