Skip to content

tracker.updateConsent()

Updates the tracker’s internal consent state. Call this from your CMP’s grant/deny callbacks. The SDK stores all four signal categories for forward-compatibility but only acts on ad_storage — that’s what gates the _tb_* first-party cookies.

tracker.updateConsent(update: ConsentUpdate): void;
type ConsentUpdate = {
ad_storage?: ConsentValue;
ad_user_data?: ConsentValue;
ad_personalization?: ConsentValue;
analytics_storage?: ConsentValue;
};
type ConsentValue = 'granted' | 'denied';

All four fields are optional. Whichever you pass is updated; the rest carry their previous values forward. The update is synchronous — there’s no Promise to await.

TransitionEffect
ad_storage becomes 'granted' (from any other state)Any click identifiers held in memory are immediately persisted to the _tb_* cookies.
ad_storage becomes 'denied' (from any other state)The SDK stops writing new cookies. Existing cookies are not deleted by the SDK — clear them yourself if your privacy policy requires it.
ad_storage value is unchangedNo-op for cookie writing; the new state is still recorded.

ad_user_data, ad_personalization, and analytics_storage are stored but currently do not affect SDK behavior. They’re recorded so that future SDK versions and downstream consumers (gtag itself, your own logging) can read a consistent snapshot.

Section titled “Example: replay saved consent on every page load”
import { tracker } from '@/lib/tracker.client';
const saved = readConsentCookie();
if (saved) {
tracker.updateConsent({
ad_storage: saved.marketing ? 'granted' : 'denied',
ad_user_data: saved.marketing ? 'granted' : 'denied',
ad_personalization: saved.marketing ? 'granted' : 'denied',
analytics_storage: saved.analytics ? 'granted' : 'denied',
});
}

Don’t wait for the user to re-click the banner on every visit. Replay their saved choice as soon as the tracker is initialized.

window.addEventListener('CookiebotOnAccept', () => {
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',
});
});

For OneTrust, Iubenda, and custom CMPs, see Wiring with a CMP.