How to configure Google Consent Mode V2

Modified on Thu, 08 Feb 2024 at 04:05 PM

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.


Implement illow with Google Consent Mode V2 (recommended)

When you implement Google through Google Tag Manager, 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 cannot use GTM)

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',
    });

    // Improve ad click measurement quality (optional)
    gtag('set', 'url_passthrough', !consent.marketing);

    // Further redact your ads data (optional)
    gtag("set", "as_data_redaction", !consent.marketing);
})("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',
    });

    // Improve ad click measurement quality (optional)
    win.gtag('set', 'url_passthrough', consent.optedIn !== false);

    // Further redact your ads data (optional)
    win.gtag("set", "as_data_redaction", 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 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