Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-04-27 08:11:24

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Anonymiser function in google analytics

I very much know about the GA discussion but our site still needs it as we need to give reports to our funders.

I am trying to figure out how to anonymise the IPs so as to comply with GDPR. At the moment we are using the code below and I also found this link which indicates how to do it but I’m not sure how to include it in the code. Any advice would be appreciated.

<script>
_uacct = "UA-xxxxxx-1";
urchinTracker();
</script>

<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2018-04-27 08:24:48

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Anonymiser function in google analytics

This was the general JavaScript I was using for GA on various sites:

<script>
(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','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('set', 'transport', 'beacon');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>

Offline

#3 2018-04-27 08:33:27

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Anonymiser function in google analytics

With your legacy method, you just need to add the line:

_gaq.push(['_gat._anonymizeIp']);

as described here. Phil’s is the current suggested method.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2018-04-27 10:43:35

trenc
Plugin Author
From: ⛵️, currently Göteborg, SE
Registered: 2008-02-27
Posts: 574
Website GitHub

Re: Anonymiser function in google analytics

If you use the new google tag manager you can use this:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1"></script>
<script>
	window.dataLayer = window.dataLayer || [];
	function gtag(){dataLayer.push(arguments);}
	gtag('js', new Date());
	gtag('config', 'UA-XXXXXXXX-1', { 'anonymize_ip': true });
</script>

Digital nomad, sailing the world on a sailboat: 32fthome.com

Offline

#5 2018-04-27 13:17:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: Anonymiser function in google analytics

Thank you all… That’s a lot of choices. I went with Julian’s suggestion as it was the closest to my existing code.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB