trackbridge-consent
The CMP-wiring skill. Connects Cookiebot, OneTrust, Iubenda, or your custom consent layer to tracker.updateConsent. Includes the consent-replay-on-page-load pattern so you don’t make the user re-click on every visit.
It does not install or pick a CMP. It wires whatever you have.
Frontmatter
Section titled “Frontmatter”name: trackbridge-consentdescription: Use when integrating Trackbridge with a Consent Management Platform (Cookiebot, OneTrust, Iubenda, custom CMP), implementing GDPR/CCPA Consent Mode v2, or wiring updateConsent callbacks. Covers ad_storage cookie gating and the deferred-persistence behavior on consent grant.When it triggers
Section titled “When it triggers”- “Wire Trackbridge to Cookiebot”
- “Connect my OneTrust banner to the SDK”
- “Set up Consent Mode v2”
- “GDPR consent for the click-ID cookies”
- Adding a CMP after the SDK is already in place
Prerequisites
Section titled “Prerequisites”- Browser tracker created via
trackbridge-setupwithconsentMode: 'v2'configured. - A CMP loaded in your layout — Cookiebot script tag, OneTrust SDK, Iubenda Consent Solution, or a custom banner with grant/deny callbacks.
- The CMP must load before
createBrowserTrackerruns, so its callbacks are available by the time the tracker initializes.
What it touches
Section titled “What it touches”- The component or page where the CMP callbacks are wired (typically your root layout or a dedicated
ConsentProvidercomponent). - Adds
tracker.updateConsent(...)calls in the appropriate event handlers. - Optionally: writes a small helper to read the CMP’s saved consent on page load and replay it.
What it asks
Section titled “What it asks”- Which CMP? Picks from Cookiebot / OneTrust / Iubenda / custom.
- Where to wire (component path).
- For OneTrust: which group IDs map to
ad_storageandanalytics_storage(the OneTrust defaults areC0004for Targeting andC0002for Performance, but projects often customize). - For custom: how to read the user’s saved choice (cookie name, localStorage key, etc.).
- Whether to also call
gtag('consent', 'update', ...)from the same callbacks (defaults: yes, ifgtagis loaded).
What it won’t do
Section titled “What it won’t do”- Choose or install a CMP.
- Show its own banner.
- Server-side enforce consent. The skill explains: consent on the server is your application’s responsibility — if a user denied consent, don’t fire
serverTracker.trackConversionfrom your code. - Delete existing cookies on consent revocation. The skill mentions this is up to the application; the SDK does not delete.
What it produces
Section titled “What it produces”For Cookiebot (in your layout or a ConsentProvider):
'use client';import { useEffect } from 'react';import { tracker } from '@/lib/tracker.client';
export function ConsentBridge() { useEffect(() => { function onAccept() { tracker.updateConsent({ ad_storage: window.Cookiebot.consent.marketing ? 'granted' : 'denied', ad_user_data: window.Cookiebot.consent.marketing ? 'granted' : 'denied', ad_personalization: window.Cookiebot.consent.marketing ? 'granted' : 'denied', analytics_storage: window.Cookiebot.consent.statistics ? 'granted' : 'denied', }); } function onDecline() { tracker.updateConsent({ ad_storage: 'denied', ad_user_data: 'denied', ad_personalization: 'denied', analytics_storage: 'denied', }); } window.addEventListener('CookiebotOnAccept', onAccept); window.addEventListener('CookiebotOnDecline', onDecline); window.addEventListener('CookiebotOnLoad', onAccept); // replay on return visits return () => { window.removeEventListener('CookiebotOnAccept', onAccept); window.removeEventListener('CookiebotOnDecline', onDecline); window.removeEventListener('CookiebotOnLoad', onAccept); }; }, []); return null;}For OneTrust, Iubenda, and custom: structurally identical, with different event APIs. See Wiring with a CMP for the full set of patterns.
Behavior the skill makes sure you understand
Section titled “Behavior the skill makes sure you understand”- Pre-grant click identifiers live in memory. A user lands on
?gclid=...before interacting with the banner. The SDK captures the value but doesn’t write the cookie. If consent is granted, the in-memory value is persisted. If denied, it’s discarded on tab close. - Replay on every page load is required. Don’t make the user re-consent every visit. The skill always wires a CMP-specific replay mechanism.
- Trackbridge’s consent is separate from gtag’s.
tracker.updateConsentdoes not callgtag('consent', 'update', ...). The skill offers to wire both from the same callback.
Example
Section titled “Example”You: I have Cookiebot installed. Wire it to Trackbridge.
Claude (router → consent): I see Cookiebot's script in app/layout.tsxand lib/tracker.client.ts has consentMode: 'v2'.
Where would you like the wiring? I'd suggest a small ConsentBridgecomponent in app/layout.tsx — runs once, attaches the listeners.
You: Sure.
Claude: Creating components/ConsentBridge.tsx. It listens forCookiebotOnAccept, CookiebotOnDecline, and CookiebotOnLoad (thereplay on return visits). Mounted in app/layout.tsx.
I'll also wire gtag('consent', 'update', ...) from the same callbacksso GA4's cookie behavior matches.
To verify: open the site in a fresh incognito window with DevTools →Application → Cookies open. Land with ?gclid=test123. Confirm no_tb_gclid cookie. Click Accept on the banner. Confirm _tb_gclidappears with value test123.Verification (the skill walks you through this)
Section titled “Verification (the skill walks you through this)”- Fresh incognito window, DevTools → Application → Cookies.
- Land on the site with
?gclid=test123. - No
_tb_gclidcookie should be present (consent not yet given). - Click Accept on the banner.
_tb_gclid=test123now appears.- Reload the page (no URL param). Cookie persists.
- Repeat with Decline. No cookie is written even with
?gclid=test123in the URL.
If step 5 doesn’t update the cookie, the CMP callback isn’t reaching updateConsent. The skill suggests adding a console.log inside the callback to confirm.
See also
Section titled “See also”- Consent Mode v2 — what
ad_storageactually gates. - Wiring with a CMP — the full prose version with all four CMPs.
tracker.updateConsent()— the API surface.