Advanced Consent Mode v2 Implementation: A Technical UK Guide
💡Key Takeaways
- ✅Advanced Consent Mode allows Google tags to load before consent is given, sending anonymous 'cookieless pings' to enable data modeling.
- ✅It requires setting a 'denied' default consent state for all GCMv2 parameters *before* any other Google or CMP scripts fire.
- ✅The CMP script is responsible for listening to user choices and sending a consent 'update' command.
- ✅The correct implementation order is critical: 1. Default Consent Snippet, 2. CMP Script, 3. Google Tag / GTM Container.
- ✅This guide provides the full, copy-paste-ready JavaScript code for setting the crucial default consent state.
Advanced vs. Basic Consent Mode: What’s the Difference?
Once you've implemented a certified CMP, you have a choice: Basic or Advanced Consent Mode. While both are compliant, they have vastly different impacts on your data.
- Basic Consent Mode: Blocks all Google tags from loading until the user gives consent. If they say no, you get zero data for that user.
- Advanced Consent Mode: Allows Google tags to load before the user interacts with the consent banner. By default, the tags are in a restricted, 'denied' state. In this state, they send anonymous, cookieless pings to Google.
These cookieless pings are the fuel for Google's data modeling. Without them, modeling is far less accurate. Therefore, Advanced Consent Mode is the recommended approach for data recovery.
The Golden Rule: Script Loading Order
For Advanced Consent Mode to work, the sequence in which scripts load in your website's <head> is non-negotiable. Get this wrong, and the entire setup fails.
- Default Consent State Snippet: The very first thing must be a small piece of code that tells Google tags to assume consent is 'denied' for everything.
- Your CMP Script: The script from your Consent Management Platform comes next.
- Your Google Tag (gtag.js) or GTM Container: Finally, your main Google tracking script loads.
This order ensures that by the time your Google Tag loads, it already knows to be in a restricted state, awaiting an update from the CMP.
The Complete Code for Setting Default Consent
This is the most critical piece of code for an Advanced implementation. It must be placed in the <head> of every page, immediately before your CMP and Google Tag scripts.
This code is complete and production-ready. It sets the default for all four GCMv2 parameters to 'denied'.
<!-- Google Consent Mode v2 Default Snippet -->
<script>
// Define dataLayer and the gtag function to ensure they are available.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set the default consent state to 'denied' for all parameters.
// This command MUST execute before Google tags or your CMP script are loaded.
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
</script>
<!-- End Google Consent Mode v2 Default Snippet -->
How Does the Consent State Get Updated?
You do not need to write the code for the 'update'. Your Google-certified CMP is designed to handle this automatically. When a user clicks "Accept" on your banner, the CMP script will execute a command like this behind the scenes:
// This is handled by your CMP, you do not need to add this code.
gtag('consent', 'update', {
'ad_storage': 'granted',
'analytics_storage': 'granted'
// ...and so on for other parameters
});
This 'update' command overrides the 'denied' default for that user and all subsequent pages they visit, allowing Google tags to function normally and collect full data.
Configuring Google Tags in GTM
With the default snippet correctly placed, your Google tags in GTM need no special consent configuration. Simply ensure that for your Google Ads and GA4 tags, under Advanced Settings > Consent Settings, the "Built-In Consent Checks" are active and no "Additional Consent Checks" are specified. GTM will automatically respect the 'denied' or 'granted' signals managed by your CMP and default snippet.
Unlocking Data Modeling with Advanced Mode
By correctly implementing the default consent snippet and ensuring the right script order, you enable Advanced Consent Mode. This not only keeps you compliant but also provides Google with the necessary anonymous signals to model and recover a significant portion of the data from users who decline consent, giving you a more complete picture of your website's performance.
Need an Expert to Review Your Code?
Advanced Consent Mode implementation can be tricky. Book a technical audit to verify your setup, prevent data loss, and ensure your modeling is activated correctly.
Start a Conversation