How to implement consent mode for Google Tag Manager

Author:

Implementing Consent Mode for Google Tag Manager (GTM) is crucial for compliance with privacy regulations such as GDPR and CCPA. Consent Mode allows you to manage the behavior of Google tags based on the consent status of your users. This means that tracking can be adjusted according to whether users have given consent for analytics or marketing cookies.

Overview of Consent Mode

Consent Mode adjusts the behavior of Google tags based on user consent status for various types of cookies, such as:

  • Analytics cookies: Used for Google Analytics tracking.
  • Ads cookies: Used for advertising purposes, such as Google Ads.

When Consent Mode is implemented, GTM can send a signal to Google services about the consent status, allowing you to continue measuring conversions and user interactions even when users deny consent for cookies.

Steps to Implement Consent Mode in Google Tag Manager

Here’s a detailed guide on how to set up Consent Mode in GTM:

Step 1: Update Google Tag Manager to Support Consent Mode

  1. Log in to your GTM Account: Go to Google Tag Manager and log in to your account.
  2. Create or Update Your GTM Container:
    • If you don’t have a container, create a new one. If you have one, ensure it’s updated to the latest version.
  3. Add the Consent Mode Code:
    • Before the GTM container code on your website, you need to add the following code snippet to set the initial consent state:
    html
    <script>
    function gtag(){dataLayer.push(arguments);}
    window.dataLayer = window.dataLayer || [];
    gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied',
    'wait_for_update': 500 // Optional
    });
    </script>
    • This code snippet sets the default consent for both ad and analytics storage to “denied.” You can adjust the consent state based on your users’ choices.

Step 2: Create a Consent Management Solution

To gather consent from users, you’ll need to implement a Consent Management Platform (CMP) or a custom consent dialog that allows users to opt in or out of different types of cookies.

  1. Implement the CMP:
    • Choose a CMP that fits your needs (e.g., OneTrust, Cookiebot, or a custom-built solution).
    • Ensure that your CMP is set up to ask users for consent regarding both analytics and ad cookies.
  2. Trigger Consent Updates:
    • Based on the user’s selection in the consent dialog, you’ll need to call the gtag function to update the consent status.

    For example, if a user consents to analytics but denies ads, you could use:

    html
    gtag('consent', 'update', {
    'ad_storage': 'denied',
    'analytics_storage': 'granted'
    });
    • This code should be executed when the user makes a choice regarding their consent preferences.

Step 3: Configure Tags in Google Tag Manager

  1. Open Your GTM Container: Go to the GTM dashboard and select your container.
  2. Update Google Analytics Tags:
    • Click on “Tags” in the left sidebar.
    • Select your Google Analytics tag (Universal Analytics or GA4) or create a new one.
    • In the tag configuration, make sure that the tag is set to fire based on user consent status.
  3. Add a Consent Check:
    • In the tag configuration, under “Advanced Settings,” use the “Enable this tag when” setting to restrict firing based on the consent status.
    • You can use the built-in variable {{Consent Status}} to define when the tag should fire (e.g., fire only when analytics storage is granted).

Step 4: Set Up Custom Events for Consent Changes

To track user consent actions as events in Google Analytics, you can set up custom events in GTM.

  1. Create a New Trigger:
    • Go to “Triggers” and click “New.”
    • Select “Custom Event” as the trigger type.
    • Name the trigger (e.g., “Consent Granted” or “Consent Denied”).
    • In the Event Name field, enter the name of the event that corresponds to consent actions (e.g., “consent_granted” or “consent_denied”).
    • Choose “All Custom Events” or specify conditions to fire the trigger.
  2. Create a New Tag for Analytics Events:
    • Go to “Tags” and create a new tag.
    • Select “Google Analytics: Universal Analytics” or “GA4 Event.”
    • For Universal Analytics, set the Track Type to “Event” and fill in the necessary fields (Category, Action, Label).
    • Choose the trigger you created in the previous step.

Step 5: Testing Your Setup

  1. Enter Preview Mode: Click on the “Preview” button in GTM to enter preview mode.
  2. Test Consent Dialog: Open your website and interact with the consent dialog.
  3. Check Tag Firing:
    • Ensure that the correct tags fire based on the user’s consent choices.
    • You can monitor the data layer in the preview pane to verify the consent status and tag firing behavior.
  4. Review Analytics: Check the Google Analytics Real-Time reports to confirm that the events are being recorded based on user consent.

Step 6: Publish Your Changes

Once you have tested and verified that everything is working as intended:

  1. Submit Changes: Click on “Submit” in GTM to publish your changes.
  2. Version Name and Description: Add a version name and description (e.g., “Implemented Consent Mode”).
  3. Publish the Container: Click “Publish” to make your changes live.

Best Practices

  • Regularly Review Consent: Ensure you have a mechanism to refresh user consent periodically, as regulations may change and user preferences can evolve.
  • Privacy Policy: Update your privacy policy to reflect how you handle user consent and data processing.
  • Testing: Regularly test your consent implementation to ensure it works as expected across various scenarios.

Conclusion

Implementing Consent Mode in Google Tag Manager is essential for maintaining compliance with privacy regulations while still collecting valuable analytics data. By following the steps outlined above, you can set up a system that respects user privacy and enables effective tracking. This setup not only enhances user trust but also allows for better insights into user behavior, helping you make data-driven decisions for your website or application.