Guide: cookie banner
From one script tag to a fully custom integration — three paths, pick the one that fits.
Option 1 — One script tag (30 seconds)
Add one tag before </body>. The banner appears automatically, records every choice, and populates the cookie declaration table from your last scan.
<script src="https://croombit.com/cmp.js"
data-tc-api-key="pk_live_…"></script>data-tc-locale="es"— force a language instead of detecting the browser’sdata-tc-auto-show="false"— load silently and callwindow.croombit.show()yourself- Let visitors review or change their choice later: add
data-tc-open-preferencesto any link or button (see below)
Let visitors change their choice
Once a visitor has decided, the banner no longer shows. Put a link in your footer or account page and the same panel reopens with their current choices already set — they toggle what they want and save. Each save is a new, timestamped record in the vault.
<a href="#" data-tc-open-preferences>Cookie settings</a>
<!-- or, from your own code: -->
<button onclick="window.croombit.showPreferences()">Cookie settings</button>Closing the panel without saving leaves the existing choice untouched. Scripts that are already running keep running until the next page load; Google tags react immediately through Consent Mode.
pk_ key with your domain on its allowlist before the banner shows — see the Quickstart.Option 2 — Google Tag Manager (no code)
- Download the Croombit CMP tag template. In GTM: Templates → Tag Templates → New, then ⋮ → Import, pick the file and Save.
- In Tags → New, choose Croombit CMP.
- Enter your publishable key and choose a layout (bar, box, modal, or wall).
- Set the trigger to Consent Initialization — All Pages.
- Publish the container.
window.__tcConfig instead of data-* attributes, and only once the container has loaded. The banner looks and records the same as option 1, but tags that fire before the script finishes loading don't yet see the Consent Mode defaults — when holding back tags must be guaranteed, use option 1 first in <head>.Option 3 — Custom integration (full control)
Use this when you need to match an existing design system or drive the banner from your own UI framework. Uses the SDK — about 30 lines.
- Publish the purposes you’ll ask about — e.g.
analytics,marketing(see Consent statements). - Create a publishable key (
pk_…) and add your domain to its allowlist.
Step 1 — Create the client
import { CroombitClient } from '@croombit/sdk';
const tc = new CroombitClient({ baseUrl: 'https://api.croombit.com', apiKey: 'pk_live_…' });
// Identify the anonymous visitor by a first-party cookie you set yourself.
const visitor = 'cookie_id:' + getOrCreateVisitorCookie();Step 2 — Render the banner from your purposes
Don’t hard-code the copy — pull the exact published wording so the record matches what was shown.
const { purposes } = await tc.getPurposes({ locale: navigator.language });
for (const p of purposes) {
// p.key -> "analytics"
// p.text.title -> "Usage analytics"
// p.text.body -> "Helps us see which features get used…"
// p.defaultState -> "denied" (regional rules — always respect this)
renderToggle(p);
}Step 3 — Save the choice
async function onSave(choices /* { analytics: true, marketing: false, … } */) {
await tc.recordConsentBatch(
Object.entries(choices).map(([purpose, ok]) => ({
subject: visitor,
purpose,
state: ok ? 'GRANTED' : 'DENIED',
locale: navigator.language,
channel: 'cookie_banner',
})),
{ idempotencyKey: crypto.randomUUID() },
);
tc.notifyConsentChanged();
}Step 4 — Gate your tags
tc.gate(visitor, ['analytics'], () => {
loadGoogleAnalytics();
});tc.applyConsentMode(visitor, gtag) translates the state into a Consent Mode v2 gtag("consent","update",…) call for you.