Forum Moderators: DixonJones

Message Too Old, No Replies

Google Analytics: Anonymize IP: How?

Where to make the setting/change

         

ken_b

5:57 pm on Feb 2, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I found this page:
[developers.google.com...]
about this that says to use this code:
ga('set', 'anonymizeIp', true);

But where do I find/put it?

ken_b

6:36 pm on Feb 2, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK so looking at the analytics code on my pages I see a similar command just befor the

ga('send', 'pageview');
</script>

Do I just paste
ga('set', 'anonymizeIp', true);

in there like this?
ga('send', 'pageview');
ga('set', 'anonymizeIp', true);
</script>

robzilla

6:38 pm on Feb 2, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In your tracking code, but it depends on your implementation. The ga() function is for analytics.js, the previous implementation (i.e. before gtag.js).

Might as well update your tracking code to gtag.js, while you're at it. Then you'd use something like this:

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


If you're using analytics.js, you already have something like this:
 ga('create', 'UA-XXXXXX-1', 'auto');
ga('send', 'pageview');

To which you'd add:
ga('set', 'anonymizeIp', true); 

ken_b

7:05 pm on Feb 2, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks robzilla, that's just what I needed to know.

Much appreciated.