#GTMTips: Simple Way To Exclude Internal Visits From Google Analytics
With so many people working from home or remotely in these turbulent times, it’s time to revisit one of my oldest articles, and discuss the options you have for excluding or segmenting internal traffic in Google Analytics.
The traditional method of IP address exclusion is not necessarily the best option anymore, unless all your employees use a specific VPN to connect to the site.
In this article, we’ll go through some of the tools you have at your disposal.
XThe Simmer Newsletter
Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava into your email inbox!
Tip 111: Exclude internal visits from Google Analytics
In my opinion, the simplest and most elegant way to exclude an arbitrary mass of users is to use the URL query parameter method I’ll outline below.
The URL query parameter method
The way it works is that all employees, remoters, and other users whose traffic should be counted as internal should visit the site using a specific URL query parameter. With Google Tag Manager, you can take this query parameter and send it as a User-scoped Custom Dimension to Google Analytics.
You can then create a view filter that excludes this particular Custom Dimension from your main reporting views, or you can use segments to identify the traffic in the reports.
To get started, you’ll need to create a new URL query variable in Google Tag Manager.
The URL query variable
Go to Variables, scroll down to User-Defined Variables, and click the NEW button to create a new variable.
Choose URL as the type.
Set Component Type to Query, and Query Key to internal
.
Name the variable something like URL - Query - internal
and save the variable.
The Custom Dimension
In Google Analytics, go to Admin, and click Custom Definitions in the middle column (Property settings). Choose Custom Dimensions.
Click + NEW CUSTOM DIMENSION to create a new Custom Dimension.
Create a User-scoped dimension, and name it Internal Traffic
.
Once it’s created, make note of its Index number.
Modify your Google Analytics tag
In Google Tag Manager, find the Page View tag, and open it for editing.
If you haven’t done so already, check Enable overriding settings in this tag.
Expand More Settings, then Custom Dimensions, and click +Add Custom Dimension to add a new Custom Dimension.
Set the Index of the row to the Custom Dimension index number you got from Google Analytics, and set the Dimension Value as the variable you just created.
Save the changes.
TEST!
Now you can visit the site. First, visit the page without the query parameter. You should see your Google Analytics tag fire, and the Custom Dimension where you added the URL variable to should show undefined
. That’s good - we don’t want to send a value to GA unless it’s true
.
Then, add ?internal=true
(or &internal=true
if the URL already has a query string) to the end of the URL, before any possible hash fragment (#hash
), and hit enter to reload the page.
This time you should see your Google Analytics tag pick the string true
and send it as the value of the Custom Dimension to Google Analytics.
That’s it! Now you’re populating the User-scoped Custom Dimension with the value true
for all users who visit the site with the query parameter internal=true
.
Create a view filter
You could simply use segments to separate the traffic into internal and the rest, but perhaps you want to use View filters instead to avoid polluting your view with internal traffic.
This is what the view filter would look like:
When this filter is activated, all sessions from users who have the value true
sent even once to GA will be filtered out of the Google Analytics view.
How to make the users’ data reappear
If you want to roll this back for any given user, all they have to do is visit the site with the internal
query parameter, and use literally any other value except true
.
So they could visit with internal=false
or internal=ratamahatta
- anything goes.
As soon as they send a non-true
value to Google Analytics as the value of the internal
parameter, they will be counted among non-internal traffic again.
Other options
If you think using query parameters is cumbersome, you could write a simple URL rewrite rule, which redirects visits to e.g. office.domain.com
to www.domain.com/?internal=true
. That way users would need to just remember the domain name instead of having to add the URL parameter.
Alternatively, you could suggest to users to install a browser extension that automatically blocks their hits from given websites. This is simple to do as well, but does require a specific browser to be used.
If the users use a VPN when on company hours, you can configure the VPN IP for exclusion in Google Analytics, or you can modify the VPN to add an HTTP header (x-internal-traffic
or something), which your web server can then translate to a dataLayer.push()
.
There are many ways to skin the cat, but the key is that there’s almost certainly a manual step that all internal users need to perform. The query parameter is a set-and-forget method, and that’s why I prefer it personally.
Summary
This article was a reintroduction of a six-year-old solution of mine, and never before has it been more timely. With the COVID-19 pandemic raging, more and more people are working remotely, leading to a surprisingly potent problem of how to block this traffic from your main reporting views in Google Analytics.
The URL query parameter solution is simple, because optimally your users only need to do this once per browser. Naturally, with e.g. Safari’s ITP and its short cap on cookie expiration, it’s not actually quite that simple. But with tracking prevention, nothing is.
Other solutions were listed at the end of the article, but I’d love to hear your feedback - do you have ideas / solutions that are missing from this article? Please share them in the comments!