How to configure Google script (Google Consent Mode)

Created by illow Info, Modified on Thu, 26 Jan 2023 at 04:39 PM by illow Info

Consent Mode configures the Google tags and scripts on a third-party website to modify how they use each visitor’s data, based on the visitor’s consent status. It can enable a website to treat certain users’ data anonymously while processing other users’ data as normal. The Mode consists of two settings, which customize how Google tags behave before and after a visitor accepts or declines cookies and processing of their data.


There’s a good chance that your brand’s website has some Google tags and scripts, deployed via global site tags (gtag.js) or Google Tag Manager. These pieces of code enable applications like Google Analytics and Google Ads to measure how visitors interact with the site, including which pages they visited, and whether or not they converted into customers.


Google tags have been a fundamental piece of digital marketing infrastructure for many years. However, the tags have lately come into tension with data and privacy regulations such as the GDPR, which specify that websites need users’ consent in order to process data and issue cookies in certain contexts. In recent years, regulators and browsers have cracked down on potentially privacy-breaching technologies such as third-party cookies, leading to an industry-wide conversation about how digital marketing can better respect users’ privacy preferences.


This doesn’t mean to say that brands can no longer benefit from web analytics, ad retargeting, and other user-data-driven marketing tactics. But they do need to use tech which can differentiate between consenting and non-consenting users, and which handles each user’s data in a way that fits their consent status.


Consent Mode, which launched in beta on 3 September 2020, is one of Google’s solutions to this requirement.* The feature currently works with tags and scripts for Google Analytics, Google Tag Manager, Google Ads, Floodlight and Conversion Linker.


1. Initialize the data layer

First, you need to initialize the data layer for Google Tag Manager. If you use Google Analytics, you probably have this code in the <head> of your pages:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="<https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID>"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }
    gtag('js', new Date());
    gtag('config', 'GA_MEASUREMENT_ID');
</script>

 It is very important that you deny the permissions before initializing it


It has to become:

<script>
    // Initialize the data layer for Google Tag Manager (this should mandatorily be done before the Privacy Controls and Cookie Solution is loaded)
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }
    // Default consent mode is "denied" for both ads and analytics as well as the optional types, but delay for 2 seconds until the Privacy Controls and Cookie Solution is loaded
    gtag("consent", "default", {
        ad_storage: "denied",
        analytics_storage: "denied",
        ads_data_redaction : "denied",
        functionality_storage: "denied", // optional
        personalization_storage: "denied", // optional
        security_storage: "denied", // optional
    });
    // Improve ad click measurement quality (optional)
    gtag('set', 'url_passthrough', true);
    // Further redact your ads data (optional)
    gtag("set", "ads_data_redaction", true);
</script>
// Global site tag (gtag.js) - Google Analytics 
<script async src="<https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID>"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }
    gtag('js', new Date());
    gtag('config', 'GA_MEASUREMENT_ID'); //replace GA_MEASUREMENT_ID with the ID of your Google Analytics property
</script>

Google Tag Manager

For this you have to add a new tag:

  1.  New > Tag Configuration
  2.  Select the custom HTML option
  3.  Paste the following code snippet
<script>
    // Initialize the data layer for Google Tag Manager (this should mandatorily be done before the Privacy Controls and Cookie Solution is loaded)
    window.dataLayer = window.dataLayer || [];
    function gtag() {
        dataLayer.push(arguments);
    }
    // Default consent mode is "denied" for both ads and analytics as well as the optional types, but delay for 2 seconds until the Privacy Controls and Cookie Solution is loaded
    gtag("consent", "default", {
        ad_storage: "denied",
        analytics_storage: "denied",
        ads_data_redaction : "denied",
        functionality_storage: "denied", // optional
        personalization_storage: "denied", // optional
        security_storage: "denied", // optional
        wait_for_update: 2000 // milliseconds
    });
    // Improve ad click measurement quality (optional)
    gtag('set', 'url_passthrough', true);
    // Further redact your ads data (optional)
    gtag("set", "ads_data_redaction", true);
</script>

 It is very important that the trigger is Consent Initialization - All Pages

    4. Save and publish it




To learn more about Consent Mode, take a look at the official blog of the Google Marketing Platform, the Google Analytics Help or the gtag.js guide.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article