Setting up Google analytics with built-in consent state manager. Allowing Google Analytics to adapt to the consent given. ( consent mode explained )

Untitled

In case consent is not given ('ad_storage': 'denied'), Google Analytics runs without cookies en send cookieless pings.

Enabe consent overview

In tagmanager go Adim > Container settings > Enable consent overview

Untitled

Create a Tag template & set permission.

The template nees permessions to set consent state & Read cookie value(s)

Untitled

Setting the defaults

const setDefaultConsentState = require('setDefaultConsentState');

setDefaultConsentState({
  'ad_storage': 'denied',
  'analytics_storage': 'denied',
  'functionality_storage': 'granted',
  'personalization_storage': 'granted',
  'security_storage': 'granted'
});

Reading your cookies

var cookie_analytics = getCookieValues('cookieconsent')[0];
var cookie_ads = getCookieValues('cookieconsent')[0];

Update the Consent state accordingly.

const updateConsentState = require('updateConsentState');

if(cookie_analytics.indexOf('accept') == 0) {
   updateConsentState({
  'analytics_storage': 'granted'
    }); 
     }
  }

if(cookie_ads.indexOf('accept') == 0) {
   updateConsentState({
    'ad_storage': 'granted'
    }); 
     }
  }

Make sure your GA configuration Tag uses the consent setting

Untitled

Activate your cosent template via the new trigger