Google Analytics with IP anonymization

The German legislation provides in the Telemedia Act (TMG) that user data when using cookies - as in this case in Google Analytics - for storage and Transfer to Google servers must be anonymized. In order to use Google Analytics with data protection compliant with anonymization, the following changes to the current Analytics Code (Universal Analytics) are necessary.
Note: Google has changed all properties to Universal Analytics. For this reason, we refrain from displaying the obsolete method.
Note: The X characters in line 7 must be replaced by their own 11-digit property number sequence.

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'XX-XXXXXXXX-X', 'auto');
  ga('set', 'anonymizeIp', true);
  ga('send', 'pageview');
</script>

The code should be set directly from the closing tag for best performance so as not to interfere with the loading of the website. See also the article Optimize website load time.
The manual insertion of the code has the advantage that the script is then loaded exactly in the right place, and thus does not block the loading process. which is not guaranteed with some plugins. In addition, some plugins also bring unwanted advertising and unwanted features_ (bloatware).

We are here for you

To contact form

Categories: