What is IP Anonymization (or IP Masking)
In simple words, IP Anonymization or IP Masking is sending a visitor’s IP to Google Analytics servers by deleting/masking the last octet of the IPv4 address (last 80 bits for IPv6). Here’s an example;
Visitors IP: 12.214.31.144
Masked IP: 12.214.31.0
IP anonymization occurs before any data storage or processing takes place. Hense Google does not store or process complete IP addresses at any given point.
IP anonymization in GA4
IP anonymization is always enabled for GA4 properties & no manual action is required.
IP anonymization in Universal Analytics (UA)
IP anonymization is an opt-in feature where we need to explicitly tell GA to enable this feature by adding a parameter to your tracking code.
IP anonymization with analytics.js
To enable anonymize IP feature, add the below line of code to your existing analytics.js tracking code
ga('set', 'anonymizeIp', true);
Example
<!-- Google Analytics -->
<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-XXXXX-Y', 'auto');
ga('send', 'pageview');
ga('set', 'anonymizeIp', true);
</script>
<!-- End Google Analytics -->
IP anonymization with gtag.js
For gtag.js, add the below code;
gtag('config', '<GA_MEASUREMENT_ID>', { 'anonymize_ip': true });
Example
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<GA_MEASUREMENT_ID>', { 'anonymize_ip': true });
</script>
IP anonymization with GTM
To enable IP anonymization via Google Tag Manager (GTM), we can utilize the field to set option under more settings in our Google Analytics Settings Variable.
- Edit your Google Analytics Settings variable
- Click on More Settings > Fields to Set > Add Field
- Under field name type
anonymizeIp
(can be selected from the drop-down list) - For the Value field, type
true
- Save your changes & enable preview mode test before publishing the container.
If you’re not using the Google Analytics Settings variable, the field can be set on your pageview tag as well. Refer to the below screenshot & do the necessary changes to your tag.
How to check IP anonymization enabled?
- Go to your website
- Open up Developer Tools in your browser
- Go to the Network tab & type
collect
in the filter box
- Refresh your page
- Click on the row with the value
analytics.js
under the initiator column
- Go to the Query String Parameters section & look for value
aip: 1
If you are able to see this value, this means you have successfully enabled IP Anonymization in your GA UA property.
0 Comments