In line with GDPR regulations, websites operating inside and outside the UK and the EU, need to anonymize the IP addresses for all users on their website. This seems complicated, but with Google Analytics, this is fairly simple to implement.

As a digital marketing consultant, this is one of the first things I check for during a website audit. It’s common practice to mask IP addresses, but for older websites, this might have been missed. Don’t forget, it was not always under regulation to mask IP addresses.

Why do you need to ‘anonymize’ an IP address?

An IP address (Internet Protocol address) is a series of numbers that identifies any device on a network. This includes the device’s physical location.

Many data protection authorities prevent the storage of full IP address information. So to comply with regulations, many websites can not collect IP addresses – so therefore you have to anonymize them.

To anonymize and IP address is also referred to as ‘IP masking’.

How does Google Analytics anonymize an IP address?

Check if a website has IP masking

It’s easy to see if a website has IP masking.

First go to said website, right click, and click on ‘view page source’. Then using Ctrl + F for search, type ‘_ip’. This should now highlight the IP masking detail on the analytics tracking code.

Check if a website has IP masking

As long as the code { 'anonymize_ip': true }); is after the UA tracking code, IP masking is enabled.

If the website is using an older version of Google Analytics, ‘ga’, the code you are looking for is: ga('set', 'anonymizeIp', true);

How to mask IP addresses in Google Analytics

Note: If you are using the new Google Analytics 4 (GA4), IP addresses are masked automatically, so you don’t need to do anything.

Mask IP addresses in Google Analytics using ‘gtag’

First you need to log in to the backend of your website, and find the section. This is usually in the code of your website. In wordpress websites, this is in the theme editor settings. For other platforms, there may be a section called in the navigation.

Sometimes the section might be referred to as the ‘header’.

For gtag, find or search for the UA tracking code. It should look like this (without IP masking):

gtag('config', 'UA-000000000-0');

To add IP masking, go between the ') at the end and paste in this exact text:

, { 'anonymize_ip': true }

So the final line of code should look like this:

gtag('config', 'UA-000000000-0', { 'anonymize_ip': true });

Mask IP addresses in Google Analytics using ‘ga’

With the older version of Google Analytics, you can find this the same way, it should be in the section of the website.

For ga, find or search for the UA tracking code. It should look like this (without IP masking):

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');

To add IP masking, add a new line of code under the ga('create' line of code, and then paste in this exact text:

ga('set', 'anonymizeIp', true);

The final code should look something like this:

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');

That’s it. Now your website complies with data protection regulations. For a technical explanation of how Google Analytics anonymizes IP addresses, visit the Google Analytics Help Forum.


For more guides and resources, checkout my digital marketing resources hub, for more guides on Google Analytics, Google Search Console and much more.

Don’t forget to look for IP masking in your next website audit. Share this with your friends and colleagues, and leave a comment below ⬇