Implementing Consent Mode in Google Tag Manager (GTM) allows you to control how Google services (such as Google Analytics and Google Ads) collect data based on the user’s consent preferences. This is especially important for compliance with privacy regulations like the GDPR (General Data Protection Regulation) in the EU and the CCPA (California Consumer Privacy Act) in California. Consent Mode enables you to adjust the behavior of Google tags based on whether the user has granted consent for analytics or marketing cookies.
Here’s a step-by-step guide on how to implement Consent Mode with Google Tag Manager:
1. Understand Consent Mode Basics
Consent Mode works by allowing you to send consent signals to Google services (e.g., Analytics, Ads) about whether the user has consented to the use of specific types of cookies (analytics or advertising cookies). When Consent Mode is active, Google services will adjust the behavior of their tags, ensuring that they do not track or personalize content for users who haven’t given consent.
There are two types of consents that Consent Mode tracks:
analytics_storage: Whether the user has consented to the use of cookies for analytics tracking.ad_storage: Whether the user has consented to the use of cookies for advertising tracking.
Consent Mode sends the following signals:
- Granted: User consented to the storage and use of cookies.
- Denied: User did not consent to the storage and use of cookies.
- Default (Undefined): No user action has been taken yet, meaning no cookies should be set.
2. Set Up Google Tag Manager
Before implementing Consent Mode, you need to ensure that Google Tag Manager is installed correctly on your website.
Steps to Set Up GTM:
- Log in to your Google Tag Manager account.
- Create a new container if you haven’t already, or use an existing one.
- Install the GTM container code on your website. This includes the code snippet in both the
<head>and<body>tags of your HTML.
3. Add the Consent Mode Initialization Code
Consent Mode must be initialized on your site before any tags are fired. To do this, you’ll need to add the following JavaScript snippet to your website before any other GTM code. This initialization script should be placed in the <head> section of your HTML page.
Consent Mode Initialization Script:
This code initializes Consent Mode by setting the consent state to "denied" for both analytics_storage and ad_storage, meaning no cookies will be set by default. This ensures compliance with privacy regulations from the moment the page is loaded, before any tags are fired.
4. Modify Your Consent Management System (CMS)
Next, you need to integrate Consent Mode with your Consent Management Platform (CMP) or cookie consent solution. This allows the user to make their consent choices and for GTM to respond to those choices.
- Integrate CMP with GTM: You should configure your CMP to send consent states to Google Tag Manager. Once the user interacts with the consent banner (i.e., accepts or rejects cookies), the CMP should trigger an event in GTM.
- Pass Consent Data to GTM: After the user gives or denies consent, you will need to update the
gtagconsent state to reflect the user’s choices. The CMP should trigger an event that updates thegtag('consent', ...)with the user’s preferences.
Example code to update the consent state after user consent:
5. Modify GTM Tags to Respect Consent Mode
Once Consent Mode is initialized, you must ensure that your Google tags in GTM (such as Google Analytics, Google Ads, and other related tags) are set to respect the user’s consent preferences. By default, Google tags are configured to respect Consent Mode, but you may need to make sure that they are set up correctly.
Steps for Google Analytics:
- Create a Google Analytics Tag in GTM if you haven’t already.
- In the Tag Configuration section, choose Google Analytics: Universal Analytics.
- In the Tracking ID field, enter your Analytics tracking ID (e.g.,
UA-XXXXX-Y). - Scroll down to Fields to Set and add the following field:
- Field Name:
allowAdFeatures - Value:
{{Allow Ad Features}}(You will need to create a variable to track this condition based on the consent status)
- Field Name:
- In the Triggers section, ensure that this tag only fires after user consent has been gathered (i.e., after the CMP triggers the consent event).
Steps for Google Ads:
- Create a Google Ads Tag in GTM if you haven’t already.
- In the Tag Configuration section, select Google Ads Conversion Tracking.
- Enter your Conversion ID and Conversion Label.
- Similarly, in the Fields to Set section, make sure that the tag only fires if the user has granted ad storage consent.
6. Testing Consent Mode
After implementing the Consent Mode script and updating your tags, it’s crucial to test whether the system is working as expected.
Use GTM Preview Mode:
- GTM provides a preview mode where you can test your tags before they are published. You can use the Preview Mode in GTM to ensure that your tags are firing based on the consent status.
Verify with Google Tag Assistant:
- You can use the Google Tag Assistant browser extension to verify whether Consent Mode is working. This tool allows you to inspect which tags are firing on the page and if they are respecting the consent choices.
Check Google Analytics:
- Use Google Analytics Real-Time Reports to see if data is being sent only after the user has consented to the appropriate cookies.
7. Publishing Your Container
Once everything is set up and tested successfully, you can publish the changes in GTM.
- Go to Admin in your GTM container.
- Click on Submit to publish your changes.
8. Ongoing Compliance
Consent Mode needs to be reviewed periodically to ensure continued compliance with privacy regulations and that any new tags or changes in consent requirements are properly addressed.
Conclusion
Implementing Consent Mode in Google Tag Manager allows you to ensure compliance with privacy regulations while respecting user choices regarding cookies and data tracking. By using Consent Mode, you can control the behavior of tags based on user consent for analytics and advertising cookies, giving you flexibility and control over your website’s data collection practices. The process involves integrating your CMP with GTM, initializing Consent Mode, adjusting your tags, and testing to ensure that everything functions as expected. This approach helps you strike a balance between data collection and user privacy.