To enable Google Consent Mode v2 on your website, you need to have a cookie banner solution. If you have a Cookiebot CMP subscription, the Cookiebot script will automatically send the appropriate signals to Google on consent submission. You will manually need to ensure that a default state is set though.
This can be achieved with three methods, based on the implementation method of your Cookiebot script:
Google Tag Manager implementation
If you deploy Cookiebot via a GTM container, you need to enable Consent Mode within the Cookiebot tag by checking the box (see image below). Then define the default consent states, setting 'denied' or 'granted' for each parameter (see image below).
Check that the template is updated to the newest version.To implement Cookiebot via the Cookiebot CMP Template Gallery Tag inside Google Tag Manager (GTM), refer to our GTM deployment guide instead.
Wordpress implementation
If you have installed the Cookiebot Wordpress Plugin, you can simply enable Google Consent Mode (see image below) and have the plugin updated to the newest version.
Inline script implementation
Google Consent Mode is an API which Cookiebot CMP integrates with.
When you have installed the Cookiebot CMP tag directly on your site, you can set default (prior consent) settings via the Google consent API-integration by adding the following code snippet to your website template.
<script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('consent', 'default', {
'ad_personalization': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'personalization_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 500,
});
gtag("set", "ads_data_redaction", true);
gtag("set", "url_passthrough", false);
</script>
Region-specific settings
To change the default behavior of your tags for users from certain regions, specify a region in your consent command. By providing a region value, you can fine-tune defaults based on your users' geographic locations.
If two default consent commands occur on the same page with values for a region and subregion, the more specific region takes effect. For example, if you have ad_storage set to granted for the region US and ad_storage set to denied for the region US-CA, a visitor from California will have the more specific US-CA setting take effect.
These regional settings must be set in order from most to least specific.
For example:
<script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
// EU-specific settings
gtag('consent', 'default', {
'ad_personalization': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'personalization_storage': 'denied',
'region': [
'GB','AT','BE','BG','CH','CY','DE','DK','EE','ES','FI',
'FR','GG','GR','HR','HU','IE','IM','IT','JE','LT','LU',
'LV','MT','NL','PL','PT','RO','SE','SI','SK'
],
'wait_for_update': 500,
});
// Default settings
gtag('consent', 'default', {
'ad_personalization': 'granted',
'ad_storage': 'granted',
'ad_user_data': 'granted',
'analytics_storage': 'granted',
'functionality_storage': 'granted',
'personalization_storage': 'granted',
'security_storage': 'granted',
'wait_for_update': 500,
});
gtag('set', 'ads_data_redaction', true);
gtag('set', 'url_passthrough', false);
</script>URL passthrough
When a user rejects cookies, there is a fallback solution to pass the data that would normally be stored in the "_ga" cookie by adding it to the URL as a query parameter.
To enable this, set URL passthrough to "true" with gtag("set", "url_passthrough", true);
Renaming the dataLayer
If you've renamed the dataLayer, update the script to use the new name. For example, if you renamed the dataLayer to "gtmDataLayer", change the first line to
window.gtmDataLayer = window.gtmDataLayer || [];
Default values
Default consent can be set per region. You can change the values of the default consent types to "granted" or "denied" to default to an opt-in before the end user has submitted consent, for example allowing for a default opt-in under CCPA.
Trigger configuration
If you configure a tag to require "Additional Consent", you tell the tag it can only load if consent has been given.
If you previously applied cookie consent triggers to tags with "built-in consent" (such as Google Ads, Analytics, Floodlight, and Conversion Linker), you can use default triggers like "All pages" again.
For more information about configuring triggers for consent, check our guide here.
Google Consent Mode and TCF
If you use TCF 2.2 in addition to Google Consent Mode, a TCData update (TCData.enableAdvertiserConsentMode) allows Google to infer ad_storage, ad_personalization, and ad_user_data settings from the TC string. This incorporates Consent Mode v2 updates directly into the TC string.
To reduce potential issues related to network loading times, we recommend also implementing the consent mode script with the default consent states manually to ensure no Google tags can fire without consent.
Comments
20 comments
@Edward from the email that Google sent out if you are an Ads user:
I have been searching this code from few days, and it has helped me very much. It is very much clear and beneficial for this type of websites
Thank you that was helpful
good information
Great guide! Implementing Google Consent Mode with Cookiebot is essential for balancing compliance and analytics. Make sure to test the setup thoroughly to ensure consent signals are being passed correctly. Thanks for the detailed steps!"
Using Google Consent Mode with Cookiebot is a smart way to maintain GDPR compliance while preserving analytics functionality. Double-check the configuration to ensure seamless integration and accurate data collection. Helpful resource!
Implementing Google Consent Mode also ensures compliance with privacy laws by adjusting Google tags based on user consent. It helps maintain analytics while respecting user preferences for data collection.
Thank you that was helpful
good info.
Implement Google Consent Mode by adding the Google tag and configuring it to respect user consent for ads and analytics before loading related cookies.
Add Google Consent Mode script before tags, then update consent based on user choice.
Thanks, this guide really helped me understand how to properly set up Google consent mode with region-specific defaults.
Clear explanation — the region-specific settings example was especially useful.
Thanks for the detailed breakdown! This is extremely helpful for ensuring a consistent and smooth Google Consent Mode v2 setup—especially regional defaults and inline script tips. Definitely bookmarking it!
Thanks for this clear breakdown, it really helps clarify how to properly set up Google Consent Mode v2 with Cookiebot. The regional settings and default consent examples are especially useful. Good reminder to always place the default script before GTM or gtag.js to avoid firing tags without consent.
thanks for sharing
I’ve had to work through similar consent mode setups on one of my own projects, Starbucks Calorie Counter, and the hardest part was keeping analytics stable when users hadn’t given permission yet. Seeing all the default state logic explained this clearly really helps. Getting the script order right makes a huge difference in how reliably tags fire, especially when tracking needs to stay lightweight and privacy compliant. This article fills in a lot of gaps that most guides skip.
I recently implemented Google Consent Mode v2 on my Shopify gaming site and ran into tracking issues because I hadn’t properly configured regional defaults. After adding the inline consent script before gtag.js and setting EU defaults to denied, GA4 data became consistent.
Most of my traffic comes from my Stumble Guys beginner guide, so accurate and compliant tracking was essential. The URL passthrough feature also helped maintain limited measurement when users rejected cookies. Appreciate the clear explanation on region ordering and script placement — easy details to overlook.
nice information...
Please sign in to leave a comment.