IP anonymization with Google Analytics

How to use IP anonymization with gtag.js?

Written by NelsonLast update 2 months ago

The best practice to comply with the latest privacy regulations is to use Google Consent Mode. However, in most cases this will result inaccurate data in Google Analytics. 

In case you decide not to use Google Consent Mode and have correct data in Google Analytics, it might be a good idea to anonymize visitor IP address and be sure that no user's private data is stored on Google Analytics servers. 

This article will help you to make sure user's IP address is anonymized properly on the Google Analytics end. You can find more information in the official documentation about IP anonymization.

IP anonymization with gtag.js

To anonymize IP addresses for all events, update the  config for your property by setting the value of the anonymize_ip parameter to true:

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

This has to be done during initial initialization, not as a separate line of code.

IP anonymization with analytics.js

Add this code before sending a first pageview:

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

IP anonymization with Google Tag Manager

Step 1: Add Google Analytics (Universal Analytics) tag if not added yet. 

Step 2: In tag configuration mark Enable overriding settings in this tag, go to More Settings > Fields to Set > +Add field > Select anonymizeIp

Step 3: Fill in true in the Value field: 

Step 4: Click Save to save your changes and then Submit to publish them.

IP anonymization with GA 4

There is no need to make any adjustments in GA 4, IP anonymization is enabled by default.

Did this answer your question?