Analytics
3.6K members online now
3.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

EU Cookie opt out for Google Analytics

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

 

If this has bee answered I apologies but I have been unable to find it.

 

I am running google analytics on my website as I am in the EU I need to offer a Cookies opt-out. I have spent a few days but cannot find how to do this. I must be missing something.

 

How do I add this to my website so it is tied to my GA account, so if someone does opt-out that actually do that?

 

Thanks in advance for your help.

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Robert L
November 2015

Re: EU Cookie opt out for Google Analytics

Top Contributor
# 2
Top Contributor
This is when you realize you need a cookie to validate that you accept the use of cookies :-)

Based on policy acceptance, set the following window property to true or false:

window['ga-disable-UA-XXXXX-Y'] = true;
VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Robert L
November 2015

Re: EU Cookie opt out for Google Analytics

Top Contributor
# 2
Top Contributor
This is when you realize you need a cookie to validate that you accept the use of cookies :-)

Based on policy acceptance, set the following window property to true or false:

window['ga-disable-UA-XXXXX-Y'] = true;
VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Re: EU Cookie opt out for Google Analytics

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi thank you for the reply Julien. when I put that into my site with the change of UA-XXXXX-Y it has not worked. I am new to code, I am sure I am not doing something I should. Can you help me a little more please.

EU Cookie opt out for Google Analytics

[ Edited ]
Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

Hi Julien,

 

I've got a similar situation to the original poster, except I'm in Canada. I'm fairly familiar with JavaScript. Is that the only piece of code I need to add to a button click event in order to mark the current visitor as opted-out? And also am I correct in saying that if I create a button that sets that property to true, the user opts back in?

 

Also just to clarify, we're using gtag.js.

EU Cookie opt out for Google Analytics

Top Contributor
# 5
Top Contributor

Hi there, 

this still applies, even with gtag.js

 

See https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

EU Cookie opt out for Google Analytics

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

Hi Julien, thanks for the reply! I've read the documentation, but I'm still a bit confused on how to implement it and ensure it's working. I've been having a hard time finding any example code. Would you be able to shed any light? It mentions that the window property must be set before any calls to gtag. But I'm not sure what that means exactly, in the context of Analytics. I also want to be able to check if it's actually working properly.

EU Cookie opt out for Google Analytics

Top Contributor
# 7
Top Contributor

It really depends on whether you want opting out to be dynamic, i.e. cookie-based.

 

At any rate the variable should be set at the top of the HEAD tag, seeing how GTM will start working as soon as the bottom of the HEAD tag is reached.

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Re: EU Cookie opt out for Google Analytics

Top Contributor
# 8
Top Contributor
<html>
<head>
    <script>
        window['ga-disable-UA-XXXXX-Y'] = true;
    </script>

   <!-- more header goodness here -->
  
  <!-- GTM or gtag.js goes here --> 

</head>
<body>
    Your content goes here
</body>
</html>
VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

EU Cookie opt out for Google Analytics

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Hi Julien, thanks for your replies, I appreciate your time and help!

We do want it to be a dynamic implementation. Here's what we're looking to accomplish: When visiting the site, the user will be given the option to opt-out of tracking via a message. The message will have a button to either close the prompt, or turn off tracking. If the user does opt-out, we'll likely have a link in the footer to opt back in if they wanted to (that link would only show up if they've already opted out).

EU Cookie opt out for Google Analytics

Top Contributor
# 10
Top Contributor

Then you have to play around with cookie management to display the opt-out prompt (that sets the cookie) or trigger GA tracking is cookie is present and showing acceptance

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan