Skip to main content

Google Consent Mode v2

If you use Google Tag Manager, GA4, or Google Ads, enable Google Consent Mode v2 so your tags wait for user approval before firing.

Enable it

{
googleConsentMode: {
enabled: true,
waitForUpdate: 500, // ms to wait for consent before loading tags
adsDataRedaction: true,
urlPassthrough: false,
},
onConsentChange: (consent) => {
console.log('Consent updated:', consent)
},
}

Order matters

The cookie consent plugin must be listed before any Google plugin so its default-denied consent signals are set before GTM/gtag loads:

plugins: [
[
'docusaurus-plugin-cookie-consent',
{
googleConsentMode: { enabled: true },
},
],
// Google plugins come after
['@docusaurus/plugin-google-gtag', { trackingID: 'G-XXXXXXXXXX' }],
];

How it works

  1. Before GTM loads, default consent for all categories is set to denied
  2. On page load, stored consent is applied immediately if present
  3. When the user consents, gtag('consent', 'update', ...) fires

GTM tag configuration

For tags inside GTM to respect this:

  1. Admin → Container Settings → Enable consent overview
  2. For each tag, set its consent requirement:
    • Analytics tags: require analytics_storage
    • Ads/marketing tags: require ad_storage
Plugin categoryGoogle consent signal(s)
analyticsanalytics_storage
marketingad_storage, ad_user_data, ad_personalization
functionalfunctionality_storage, personalization_storage
necessarysecurity_storage (always granted)