How to configure Google Consent Mode V2

Modified on Mon, 1 Jul at 12:41 AM

illow is already a Google-certified CMP and you can implement Google Consent Mode V2


As a Google-certified CMP, you can integrate illow directly from Google Tag Manager and in this way integrate Google Consent Mode V2 as well. To know more about what is Google Consent mode V2, check out our latest blog.


Set up Google Consent Mode V2 using GTM (recommended)

When you implement illow through Google Tag Manager, it is already integrated automatically with Google Consent Mode V2. You can do it, and no technical experience is needed at all.


Learn here how to do it in less than 2 minutes!

Want a step-by-step setup? Check out the full guide here.




Manual setup (if you can not use GTM)

If you are integrating the Consent Banner by copying and pasting the script tag directly in the HTML code, you need to add a second code snippet to comply with Google's consent requirements. In other words, KEEP the banner script tag and ADD the following one.


1. Add the following <script> tag to the <head> of your pages:


REMEMBER TO REPLACE  <your-site-id>  with your actual Site ID shown in the platform


For Global/GDPR banners:

<script>
(function(siteId, win, doc) {
    var cookieName = 'illow-consent-' + siteId;
    var cookies = doc.cookie.split(';');
    var cookie = cookies.map((c) => c.split('=')).find(([name]) => name.trim() === cookieName);
    var consentStr = cookie ? cookie.slice(1).join('=').trim() : undefined;

    var consent = {};
    consentStr?.split('|').map((v) => v.split('=')).forEach(([k, v]) => {
      consent[k] = v === 'true';
    });

    // Initialize the data layer for Google Tag Manager (this should mandatorily be done before the Privacy Controls and Cookie Soluion is loaded)
    win.dataLayer = win.dataLayer || [];
    function gtag() {
        win.dataLayer.push(arguments);
    }
    win.gtag = win.gtag || gtag;
    
    win.gtag("consent", "default", {
        ad_storage: consent.marketing ? 'granted' : 'denied',
        analytics_storage: consent.preferences ? 'granted' : 'denied',
        functionality_storage: consent.preferences ? 'granted' : 'denied',
        personalization_storage: consent.preferences ? 'granted' : 'denied',
        security_storage: consent.preferences ? 'granted' : 'denied',
        ad_user_data: consent.marketing ? 'granted' : 'denied',
        ad_personalization: consent.marketing ? 'granted' : 'denied',
    });

    window.gtag('set', {
      'ads_data_redaction': !consent.marketing,
      'url_passthrough': !consent.marketing || !consent.preferences,
    });
})("your-site-id", window, document);
</script>


For US opt-out banners:

<script>
    (function(siteId, win, doc) {
    var cookieName = 'illow-consent-' + siteId;
    var cookies = doc.cookie.split(';');
    var cookie = cookies.map((c) => c.split('=')).find(([name]) => name.trim() === cookieName);
    var consentStr = cookie ? cookie.slice(1).join('=').trim() : undefined;

    var consent = {};
    consentStr?.split('|').map((v) => v.split('=')).forEach(([k, v]) => {
      consent[k] = v === 'true';
    });

    // Initialize the data layer for Google Tag Manager (this should mandatorily be done before the Privacy Controls and Cookie Soluion is loaded)
    win.dataLayer = win.dataLayer || [];
    function gtag() {
        win.dataLayer.push(arguments);
    }
    win.gtag = win.gtag || gtag;
    
    win.gtag("consent", "default", {
        ad_storage: consent.optedIn !== false ? 'granted' : 'denied',
        analytics_storage: consent.optedIn !== false ? 'granted' : 'denied',
        functionality_storage: consent.optedIn !== false ? 'granted' : 'denied',
        personalization_storage: consent.optedIn !== false ? 'granted' : 'denied',
        security_storage: consent.optedIn !== false ? 'granted' : 'denied',
        ad_user_data: consent.optedIn !== false ? 'granted' : 'denied',
        ad_personalization: consent.optedIn !== false ? 'granted' : 'denied',
    });

    window.gtag('set', {
      'ads_data_redaction': consent.optedIn === false,
      'url_passthrough': consent.optedIn === false,
    });
})("your-site-id", window, document);
</script>


Find attached the minified versions of the code for the different types of banners.


To learn more about Consent Mode, take a look at the official blog of the Google Marketing Platform, the Google Analytics Help, the official Set up consent mode on websites of Google and the gtag.js guide.


No-code setup (if you can not use GTM or add embedded code)

If you are integrating the Consent Banner by copying and pasting the script tag directly in the HTML code but you can not add a second block of code, you can still add a flag to the initial code snippet to comply with Google's consent requirements.


Change the code snippet from:

<script src="https://platform.illow.io/banner.js?siteId=<your-site-id>"></script>


To:

<script src="https://platform.illow.io/banner.js?siteId=<your-site-id>&includeGCMDefault=true"></script>


white_check_markeyesraised_hands::skin-tone-2

Troubleshooting
Need help troubleshooting missing Consent Mode or TCF signals on Google tags? Contact us!

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 at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article