IP Anonymization (IP Masking) in Google Analytics Universal Analytics & GA4

by | Jan 10, 2021 | Google Analytics, Google Tag Manager | 0 comments

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:

Masked IP:

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);


<!-- Google Analytics -->
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
ga('set', 'anonymizeIp', true);
<!-- End Google Analytics -->

IP anonymization with gtag.js

For gtag.js, add the below code;

gtag('config', '<GA_MEASUREMENT_ID>', { 'anonymize_ip': true });


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

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.

  1. Edit your Google Analytics Settings variable
  2. Click on More Settings > Fields to Set > Add Field
  3. Under field name type anonymizeIp (can be selected from the drop-down list)
  4. For the Value field, type true
  5. Save your changes & enable preview mode test before publishing the container.
Codechilli - codechilli blog ga ip anonymization 01

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.

Codechilli - codechilli blog ga ip anonymization 02

How to check IP anonymization enabled?

  1. Go to your website
  2. Open up Developer Tools in your browser
  3. Go to the Network tab & type collect in the filter box
Codechilli - codechilli blog ga ip anonymization 03
  1. Refresh your page
  2. Click on the row with the value analytics.js under the initiator column
Codechilli - codechilli blog ga ip anonymization 04
  1. Go to the Query String Parameters section & look for value aip: 1 
Codechilli - codechilli blog ga ip anonymization 05

If you are able to see this value, this means you have successfully enabled IP Anonymization in your GA UA property.


Submit a Comment

Your email address will not be published. Required fields are marked *

What we do

We create brilliant digital products that help our clients get ahead and stay there.


Digital Marketing

We were born from digital and it remains our core capability of communication. We activate all of our studios (strategy, brand, data analytics, and technology) to work in harmony to deliver the right message to the right audience at the right time on the right platform.


Digital Analytics

Digital marketing thrives on data. No matter what type of site/app you have, whether it’s a large e-commerce site, a personal website, a site for a small business, or a high scale app people used to order food, it’s essential to understand how people interact with your web/app. We’re at your disposal.


Web Development

As your modern-day business card, your website is a digital biopsy of your essence. Through qualitative and quantitative research and analysis, we distill the essence of your brand and express it through user-centric design to create a bespoke digital experience.

Let's Talk

about your next project.

Share This