Consent Mode and the Data Layer
Google Consent Mode v2 integrates with GTM through the gtag consent API — which itself is built on top of the data layer. When a user interacts with your consent banner (CMP), the CMP pushes consent state updates to the data layer, and GTM (via Consent Mode) adjusts all tag behaviour accordingly.
The Default Consent State
Consent Mode requires a default consent state to be set before GTM loads. This defines how tags behave before the user makes a consent choice (or if they do not interact with the banner):
<script>
// Must run BEFORE GTM snippet
window.dataLayer = window.dataLayer || [];
function gtag(){ window.dataLayer.push(arguments); }
gtag('consent', 'default', {
'analytics_storage': 'denied', // No analytics cookies until consent given
'ad_storage': 'denied', // No ad cookies until consent given
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'functionality_storage': 'granted', // Necessary cookies always granted
'security_storage': 'granted',
'wait_for_update': 500 // ms to wait for CMP to update consent before tags fire
});
</script>
// GTM snippet here
Updating Consent (CMP Callback)
When the user accepts or declines on the consent banner, your CMP should push an update:
// Called by CMP when user accepts all cookies
function onUserAcceptAll() {
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted'
});
}
// Called by CMP when user declines non-essential
function onUserDeclineAll() {
gtag('consent', 'update', {
'analytics_storage': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied'
});
}
How GTM Responds to Consent State
GTM tags have a Consent Settings configuration where you can require specific consent types:
- GA4 Configuration tag: requires
analytics_storage: granted - Google Ads Conversion tag: requires
ad_storage: granted - Meta Pixel tag: requires
ad_storage: granted
When consent is denied, GTM either blocks the tag completely or fires it in a "cookieless" mode (depending on the platform's Consent Mode integration). GA4 in Consent Mode fires without user-identifying cookies and uses modelled data to estimate audience sizes.
Checking Consent in GTM Preview
In GTM Preview Mode, the "Consent" tab shows current consent state for each consent type. You can test your CMP integration by watching consent states change as you interact with the consent banner — denied should switch to granted when you accept.
Summary
Consent Mode signals are pushed to the data layer via the gtag() function (which internally calls dataLayer.push). Set default consent state before GTM loads, then update via CMP callbacks when the user makes a choice. GTM adjusts tag behaviour based on consent state — tags requiring analytics_storage will not set cookies until analytics consent is granted. Verify consent state changes in GTM Preview Mode's Consent tab.
See our Consent Mode v2 Implementation service for complete setup.
Need Consent Mode and data layer integrated? Contact Adslytics.
Need expert tracking setup?
Our Google Tag Manager experts have delivered 500+ tracking setups with a 98% success rate.
Get a Free Consultation →