Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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