12TH JANUARY 2015 / WEB ANALYTICS
Blocking your tags firing from your own IPs with Google Tag Manager
The subject about how to exclude your own visits from GA has been commented before loads of times, most of time filters are used to keep out our own visits from Google Analytics , but some other tools may not have the possibility to filter out our own visits. This is why we're going to use Google Tag Manager to block all our tracking pixels, conversions pixels, custom tags, or whatever tag type we want.
As our site is certainly using some kind of server-side language, this should be a problem at all :) . Let's see an example about how could we do this using PHP :
Any other language will be able to do this
As you see all languages give you access to the "REMOTE_ADDR" header variable, but this will fail if the user's behind a proxy. So usually we'll want to check for "HTTP_X_FORWARDED_FOR" and it's not present we'll use "REMOTE_ADDR", this is up to the developers to print the visitor IP Address is the best way they can.
Now, let's setup 2 new macros, one of them will take care of reading our user_ip value from the dataLayer, the other will be a lookup table macro that will will use this first macro for the condition:
Now we have 2 ways to go, either using a blocking rule to our tags (we'll be using this if we want to block certain tags as we should now Blocking Rules prevail over Firing Rules ) , adding a new condition to our existing rules (if we want to block all tags depending on a generic rule, like "All Pages" :
There we go, now we could easily avoid sending data to Google Analytics from our Office IPs , but for any other tag that we're using withn Google Tag Manager.