Privacy is always an issue on the web, especially when using tracking services like Google Analytics. Therefore Google offers a functionality to anonymize the last octet of the transfered IP address. It is a function to improve the privacy of users visiting your website, without losing lots of data or insights. (You will not be able to get information about the location of the user in detail, but still all other information like visits, duration, traffic, etc.)
Prior to expanding the tracking code, you should read through the following:
The _gat global object is used to create and retrieve tracker objects, from which all other methods are invoked. Therefore the methods in this list should be run only off a tracker object created using the _gat global variable. All other methods should be called using the _gaq global object for asynchronous tracking.
— via developers.google.com, Tracking Code
For asynchronous tracking this is the new line:
Finally the recommended asynchronous anonymized snippet should look like this:
Alternatively, the traditional anonymized snippet should look like this:
Attention: Make sure that for the traditional snippet you are only adding _gat._anonymizeIp(); without the _gaq.push!
UPDATE: Now, with the upcoming of Universal Analytics, there is another version of the Analytics snippet which is called analytics.js. It’s now easier and more intuitive to anonymize Analytics globally:
So your new snippet will look somethink like this:
Moreover with Universal Analytics it’s even possible to completely opt-out a visitor (which will have the same effect as the Google Analytics Opt-out Browser Add-on):
Attention: According to the Analytics Dev Guide it’s important that the window property is set before the tracking code is called! If the property is not set or set to false, the tracking will work as usual. Also make sure, that this property is set on each page where you want to disable the Universal Analytics tracking.
So how is this going to work? First of all you’ll have to provide the opt-out facility:
A click on the link will execute gaOptout(); make sure to place the opt-out script before the analytics.js snippet:
It is important to check if the anonymized snippet is now working properly. If everything is alright, the 1 x 1 pixel tracking image (__utm.gif) must have an aip parameter of 1 (otherwise the parameter is completely missing). This parameter prevents Google from manipulating the complete IP address.
During further problems take a closer look at the official Tracking Troubleshooting.
Furthermore there are various other Guidelines to making Google Analytics lawful (in Germany):