How To Setup Google Analytics With Cookies To Be GDPR Compliant

GDPR COMPLIANT COOKIE CONSENT AND GOOGLE ANALYTICS

One of the constant questions many digital marketing teams had to face prior to May 25th, 2018 – GDPR deadline day, was: “How is our website GDPR compliant?”. Many websites now have implemented Cookie Consent notifications. This should have already been present previously, yet with GDPR there is a requirement to make these Optin-In and not just a notification.

By default, we must set Remarketing and Advertising Reporting Features to “Off” in Google Analytics. Now we will go about setting up Google Tag Manager to dynamically turn these settings on using our Cookie Consent form.

Google Analytics Adverising Tracking Setting

Is your Cookie Consent setup GDPR compliant?

So you have a Cookie Consent popup bar, sticky bar, and full-blown popup. How do we ensure that we only track visitors that click “Allow Cookies” or “Accept” to be tracked for the purposes of Remarketing or Audience creation using Google Analytics?

Google has a setting in Google Analytics that we will invoke using our Cookie Consent form.

Cookie Consent Popup

 

Getting Started – checklist

Let’s assume that you have the following setup on your website:

  • Google Tag Manager is deployed on all page loads.
  • You are using the Google Tag Manager to load your Universal Google Analytics tracking.
  • You have a Cookie Consent Popup or Notification Bar that has “Allow” or “Deny” options.

Building Cookie Consent settings in Google Tag Manager

Identify your cookie variable

Open up your website and using your web browser developer tools to view the Cookies being loaded by your site. Ensure you have deleted your Consent Cookie already. Now click on your notification cookie to “allow” or “accept” cookies. Reload the page and note the value this sets.

Cookie Consent Status in Developer Tools

In the case of my cookie consent form. The value that is set is “allow”.

Set Cookie Variable in Tag Manager

We need to set up a two new variable in Google Tag Manager to feed the value to the data-layer as Google Analytics requires a value of “true” to set the allowAdFeatures.

Firstly, lets set up our 1st party cookie variable.
I’ve called mine “Cookie Consent Status”.

Save the variable and move along to the second step.

Building a Lookup Table in Google Tag Manager for your Cookie Consent value

We must make a Lookup Table Variable. We need a Lookup Table Variable to convert our Cookie Consent Status value. The output value from our Cookie Consent form may be different to what Google Analytics requires for setting allowAdFeatures. Using a Lookup Table Variable we will convert our input values into either true or false for Google Analytics to be able to set the allowAdFeatures.

Lookup Cookie Consent Value for Google Analytics

We will give our variable a name like “Lookup Cookie Consent Status for GA”
We only require one input value of “allow” (in the case of my cookie consent form) to output “true”.
Set the default value to “false” as we are building a GDPR compliant Cookie Consent action. Setting a default value will ensure that we will only set “allowAdFeatures” to true when the user consents explicitly.

Dynamically setting the output value from your lookup variable to set “allowAdFeatures”

Next, we need to navigate to our Google Analytics tag in Tag Manager.
Under More Settings, add a Field Set.
Field Name = allowAdFeatures
Value = {{Lookup Cookie Consent for GA}} or whatever you choose to name your Lookup Table Variable.

add allowAdFeatures to fields on Google Analytics Tag

Save your settings and we should be ready to test that your cookie consent notification is now passing its value into Google Tag Manager where it is converted into a value for Google Analytics to dynamically set the “allowAdFeatures” to true if consent has been given by the user.

Test In Debug Mode

Lastly, you must test that the changes you have made are working correctly. Using either the Debug mode in Google TagManager or the Google TagManager Browser Extension you can turn on Debug mode. Once you have Debug mode on, navigate to your site and launch the Developer tools to view the console output for Google Analytics. If you see the allowAdFeatures setting being output as true or false, ensure this aligns with the Cookie setting for accepting cookies or declining them.

Leave Your Feedback On Cookie Consent

I’d love to hear from you if this article was of any help you. If there are any improvements I could make to the content or any different ways of implementing this technique, please leave a comment below.

Don’t forget to share this article if you think itwould beneift others with becoming GDPR compliant.

Leave a Comment

You have to agree to the comment policy.

sixteen − two =