Cookie Consent
A cookie consent banner that matches your site, plus the switch every other app obeys: nothing that needs consent is stored until the visitor allows it. Ask everywhere or only in the EU/UK/Switzerland, keep proof of consent, show a cookie table built from your apps, and connect your own banner or consent tool.
Beta. Cookie Consent is in beta: it works, but things may still break. If something breaks, report it.
On the store: Cookie Consent in Consent and privacy, pricing.
Free on any number of sites. You need a free account to claim and download it: see the store page.
Requirements
Section titled “Requirements”- Cloudflare® plan: Cloudflare free plan
- Works on: Cloudflare Workers; Cloudflare Pages; A site on its own server (VPS or cloud) with DNS on Cloudflare, through a Worker route in front of it (beta, tested on a live server) (hosts)
- Version: 0.6.8 (needs core 0.29.0 or later; it comes in the same download)
- Runs on the Cloudflare free plan, in the same D1 database as your other apps. No third-party script, no outside requests, no account elsewhere.
- Once installed, visitors in the EU, EEA, UK and Switzerland see a cookie banner and tags that need consent wait for their answer. Everyone else sees no banner and every app and tag works as before. Change who is asked in Settings, When to ask.
- Consent records are stored in your D1 database: a random id, the choices, the policy version, the time and the visitor’s country. No IP address, no browser details. One small write per choice made (not per page view).
- The banner is added to pages as they are served, so page views run through the apps (as with link tagging and forms). It is not legal advice: whether and where you must ask depends on your site and your visitors.
- Cost per visit: no writes on a page view; one small write each time a visitor makes a choice, and an old-records cleanup at most every 6 hours. Consent choices are always saved (not part of the logging budget); if the Cloudflare free database limit is reached, new choices cannot be recorded until midnight UTC.
What it adds to the site
Section titled “What it adds to the site”- Addresses it answers:
/_consent/save - Edits pages as they are served: yes
- Has a say when a page is not found: no
- Uses the site’s brand: yes
- Core capabilities it uses:
optout - Database tables (in the site’s own D1 database):
consent_records
Cookies and browser storage
Section titled “Cookies and browser storage”What the app sets in a visitor’s browser. Anything that is not necessary waits for consent.
| Name | Category | Kept in | Lasts | What it is for |
|---|---|---|---|---|
_site_consent |
necessary | cookie | up to 1 year (the owner can shorten it) | Remembers the cookie choices you made on this site (and a random id for the record of that choice), so you aren’t asked again on every page. (only after a choice is made) |
Agent tools
Section titled “Agent tools”Cookie Consent adds 6 tools to the site’s own agent connection. The short text under each name is what an agent sees in its tool list; the full notes are what site_tool_help returns. The shared rules for confirm, dry_run and on apply to every tool.
Read (changes nothing)
Section titled “Read (changes nothing)”consent_settings
Section titled “consent_settings”The consent banner settings (including usOptOutLink), who is asked and who isn’t, warnings, and recommendations (call apply only if the owner agrees). Not legal advice.
Read only: changes nothing.
Full notes (what site_tool_help returns):
The status is one line. Warnings include a missing policy link. recommendations [{id, text, why, apply: {tool, args}}] are the admin’s suggestions in its own words: explain each to the owner in one or two plain sentences and call apply.tool with apply.args only if they agree.
Takes no input.
consent_cookies
Section titled “consent_cookies”Every cookie and browser-storage item the site and its apps set, with category, duration and purpose (what a cookie table shows).
Read only: changes nothing.
Takes no input.
consent_stats
Section titled “consent_stats”Consent statistics: how many visitors accepted, rejected or chose, per day.
Read only: changes nothing.
| Field | Type | Required | What it is |
|---|---|---|---|
range |
7, 30, 90 |
no | Days (default 30). |
Change
Section titled “Change”consent_settings_save
Section titled “consent_settings_save”Change the consent banner settings (PATCH: send only what changes; consent_settings shows them). mode: regions | everywhere | never (regions is recommended). To show the app’s banner send {source:“own”, banner:true}. Changes the live site within about 30 seconds: confirm legal requirements with the owner before turning consent off. Read the answer’s warnings. Risky input (the answer says which) does nothing until called again with confirm:true.
Changes the site.
Full notes (what site_tool_help returns):
mode regions is the default for new installs: only visitors from the countries in regions see the banner, by default the EU, EEA, UK and Switzerland; an unknown country is asked; everyone else gets every tag straight away. never: nobody is asked. Sites installed before 0.3.0 keep their saved mode (often never); suggest regions, change it only if the owner agrees. mode never while ad or analytics tags are live does nothing until you call again with confirm:true (the answer says why). usOptOutLink: the US “Do Not Sell or Share My Personal Information” link, shared with Tag Manager: off, auto (added at the end of every page for US visitors) or own (the owner placed <a href=“#do-not-sell”>…</a>). source: own (this site decides: with banner:true the app shows its own banner; with banner:false the site’s own banner calls siteConsent.set(…)), a consent tool (cookiebot, onetrust, cookieyes, termly), or generic (another tool, read from a cookie or localStorage key). A “Cookie settings” link or button reopens the banner: href=“#cookie-settings” or siteConsent.open(). Warnings include, for example, a missing privacy policy link. ownRows: category is preferences, analytics, marketing or necessary (anything else is stored as necessary); storage is cookie, localStorage or sessionStorage (anything else is stored as cookie). Rows without a name are dropped.
| Field | Type | Required | What it is |
|---|---|---|---|
mode |
"never", "everywhere", "regions" |
no | regions is the recommended choice. |
usOptOutLink |
"off", "auto", "own" |
no | The US Do Not Sell or Share link (shared with Tag Manager). |
regions |
list of strings | no | Two-letter country codes (mode regions). |
source |
"own", "cookiebot", "onetrust", "cookieyes", "termly", "generic" |
no | own (default; with banner:true the app shows its own banner), cookiebot, onetrust, cookieyes, termly, or generic. |
banner |
boolean | no | Show our banner (false when the site has its own). |
gcm |
string | no | Google Consent Mode v2: auto (default) or off. |
cookieDays |
integer | no | |
records |
boolean | no | Keep a record of each choice (proof of consent). |
retentionDays |
integer | no | |
style |
string | no | Banner style, e.g. bar or box. |
side |
string | no | left or right (box style). |
title |
string | no | |
message |
string | no | |
acceptLabel |
string | no | |
rejectLabel |
string | no | |
chooseLabel |
string | no | |
saveLabel |
string | no | |
policyUrl |
string | no | Link to the site’s privacy or cookie policy. |
policyText |
string | no | |
buttonClass |
string | no | The site’s own button classes. |
floating |
boolean | no | |
ownRows |
string | no | Extra cookie table rows as JSON text: [{“name”:“_ga”,“category”:“analytics”,“purpose”:“…”,“duration”:“2 years”,“storage”:“cookie”}]. Replaces the whole list. |
generic |
string | no | |
confirm |
boolean | no | true only after an answer asked for it, with confirm_token. |
confirm_token |
string | no | The answer’s confirmToken, sent with confirm:true and the same input. |
dry_run |
boolean | no | true: save nothing; answers wouldSave (the full record) and the warnings. |
consent_ask_again
Section titled “consent_ask_again”Raise the policy version so every visitor is asked for consent again (after a real change to your cookies or policy). DESTRUCTIVE: does nothing until called again with confirm:true.
Changes the site. Destructive: does nothing until it is called again with confirm.
| Field | Type | Required | What it is |
|---|---|---|---|
confirm |
boolean | no | Leave out first (the answer says what would happen); then true, with confirm_token. |
confirm_token |
string | no | The answer’s confirmToken, sent with confirm:true and the same input. |
consent_records_prune
Section titled “consent_records_prune”Permanently delete consent records (the log of visitors’ choices) older than N days. High risk (they are the proof of consent): needs “confirm”: “DELETE”, after the owner agrees. DESTRUCTIVE, HIGH RISK: does nothing until the owner agrees and you send “confirm” as the exact text the first answer names.
Changes the site. Destructive: does nothing until it is called again with confirm.
| Field | Type | Required | What it is |
|---|---|---|---|
days |
integer | yes | |
confirm |
string | no | Leave out first: the answer names the text to send. Send it only after the owner agrees. |
confirm_token |
string | no | The answer’s confirmToken, sent with confirm:true and the same input. |
Core events
Section titled “Core events”It sends and listens to none.
How events work: core events.
Works with your other apps
Section titled “Works with your other apps”Connects with no setup, in any install order: Analytics, Tag Manager, Popups.