Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly anonymize IP for Tag Manager code?

In Google Tag Manager we get this code for placing on pages

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ADSAFASDF');</script>

Here we can find the code we should use for anonymizing IP https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization

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

Where should I place it? If I place it right after the code (before ending /script tag or inside separate script) using Tag Assistant Chrome extension I can see the error

Invalid call to gtag(), the Global site snippet is not installed

How to properly insert the code and where?

like image 815
Ivan Topić Avatar asked Nov 28 '25 19:11

Ivan Topić


1 Answers

Google Tag Manager doesn't process or store IPs. It is the Google Analytics tag inside of Google Tag Manager that you need to configure to anonymize IPs.

Go to GTM & edit your Google Analytics Tag(s) or Google Analytics Settings Variable:

  1. Go to More Settings > Fields to Set
  2. Add a new field. Configure the field with:
    1. Field name: anonymizeIp
    2. Field value: true
like image 124
vinoaj Avatar answered Dec 01 '25 15:12

vinoaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!