How to disable Tracking via Google Tag Manager

If you ever had the problem of doing maintenance on your website and seeing a spike in your analytics reports as a result of this internal traffic, then keep on reading.

Essentially what we want to do is keep track of whether a user wants to be tracked or not, and if not, prevent some or all tags from firing by disabling tracking. This is useful for when you don’t want employees of your own company cluttering up the analytics for your website. The easiest way to do this is via a tag management system (TMS). If you are not using Google Tag Manager (GTM) or Tealium iQ for example, you should.

In this post we assume that you are using a TMS. The examples will be based on Google Tag Manager.

Detecting Stealth Users

I will use the term Stealth Users for users who do not wish to be tracked. The way we are going to know whether a user wants to be stealthy or not, is by having them visit the website (one time) with a specific query string parameter attached to it. If this parameter is attached, we will place a cookie on the user’s browser to detect if the user wishes to be a Stealth User. In your TMS you will need to create some code that will create this cookie when the parameter is detected.

In Google Tag Manager this can be done by launching the following Custom HTML tag on every page:

Detecting the cookie

To detect the cookie in Google Tag Manager you need to create a Custom JavaScript Variable. I’m not using a First Party Cookie Variable because the first visit with the disable_tracking parameter would still be tracked. This is the code that you can place in the Variable (let’s call it “No Tracking”):

line

Subscribe to our newsletter and receive a monthly update with new posts and industry news

Stopping tags from firing

To stop tags from firing we need to first configure a trigger. Let’s call it “No Tracking” as well, to avoid confusion…
To make this trigger fire for all events we need to pick “Custom Event”, set the event name to “.*” and enable RegEx matching for the event name.

Then we have to add a filter so that this trigger will only fire when the No Tracking cookie is found. So select the Variable “No Tracking” and when this variable equals “true”, the trigger should fire.

gtm

Now we have to assign this trigger as the exception trigger for all the tags we wish to stop from firing when the cookie is detected. This may be a bit of an annoying task if you have a lot of tags but once it’s done, it’s done!

Your tags list should now look something like this:

disable trackingAn alternative to using this trigger is to modify all the existing triggers that you wish to stop from firing when this cookie is detected, and just add the ‘No Tracking equals true’ filter to them. Personally I prefer the exception triggers on tags, but you are of course free to choose.

Now all that is left to do is distributing the url to your site with the query parameter to all the people that should visit the site in Stealth mode. The link should look like this (don’t forget the question mark): http://www.example.com/?disable_tracking

The Stealth Users should visit the site with this link on all of the browsers they are using on all the devices via which they will visit the site, so that the cookie gets set on each browser. The cookie will last for 10 years, by that time the device will (hopefully) already be replaced by a newer model.

One last thing to keep in mind is that you will not see any calls to your analytics (for example “/collect” calls to GA) in your browser debugger. If you need to see your calls, delete the cookie named “disable_tracking” and you will see your calls again. Remember that when you’re done, you should visit the site with the above mentioned URL again to prevent tags from firing again in the future.

Any questions? Any recommendations to fine-tune the above procedure? Let us know!

Leave a Reply