0

I enabled anonymizeIp for Google Analytics tracking on my website and since changing that, the filters that should exclude requests from my test and staging environments based on IP do not work anymore.

I tried setting up a specific cookie exclusion rule and setting a 'test_environment' cookie on my local machine (according to the answers to this question: How do you exclude yourself from Google Analytics on your website using cookies?)

However, I use cross-domain tracking (linking) and it seems that my 'test_environment' cookie value is simply being ignored. It might be that the cookie of my linked domain is used instead of the local test environment cookie.

Is it possible to combine cookie based exclusion/filtering with cross-domain tracking?

1
  • It might be easier to put in a conditional on your sites, so test and staging send tracking data to a completely separate analytics account (if you even want to track them). On mine I have a condition so only Prod sends things through a Prod GTM container; Staging sends things through a totally separate Staging GTM container which in turn sends to a separate GA that's only for Staging.
    – WebElaine
    Aug 13, 2019 at 16:12

1 Answer 1

1
  • Simple way: use https://tools.google.com/dlpage/gaoptout.

  • Complicated way:

    1. create custom dimension, scope: user
    2. after saving load the page twice and notice dimension name, i.e. dimension1
    3. create HTML file "exclude internal users from GA" with GA snippet, which sets your custom dimension (dimension1) to "internal", like:

      <script> //<![CDATA[ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXX-X', 'auto'); ga('set', 'anonymizeIp', true); ga('set', 'dimension1', 'internal'); ga('send', 'pageview', { 'hitCallback': function() { window.location.href = '/'; } }); //]]> </script>

    4. Visit this page by yourself and let it visit by your colleagues
    5. To be able to create filter GA should get some data into this dimension - wait a bit.
    6. Create filter: exclude → filterfield=usertype, filter pattern=internal

Conclusion: after you save the filter, all users visited your HTML page will be excluded from GA.

PS: The cookie, which makes this possible remains in the browser forever. "Forever" means for this kind of cookie an expiration after two years. Using a CRM it is possible to create an automated workflow, which sends email an crew members with recommendation to click a link and refresh a cookie. However there could be more smart approaches for this.

2
  • 1
    Nice answer. Wouldn't it last two years according to the cookie expiration date?
    – Emirodgar
    Jan 13, 2020 at 16:07
  • Sure. 4eva means something like "maximum possible lifetime allowed by G(od)oogle"
    – Evgeniy
    Jan 13, 2020 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.