Filtering your own traffic from Google Universal Analytics is done slightly differently to the older version. Back in 2012 I wrote a short guide on How to Filter Your Own Visits from Google Analytics and thought I’d produce an updated one for Universal Analytics.
The principle is similar. We still create a subfolder to trigger the ‘ignore me’ cookie setting and then we use a Custom Dimension to ensure the rest of the visit/session is ignored.
As stated before, this method is an alternative to filtering out traffic based on IP information
We need to do the following:
- Create a subfolder on your site that you will use to set the masking cookie.
- Create a Custom Dimension.
- Configure Google Analytics to filter the subfolder you are using.
- Configure Google Analytics to filter both the Custom Dimension value
- Create a default web document (probably index.html) inside this folder and configure it to set the masking cookie and then redirect back to the site root.
1) Create the Subfolder
This is the URL you will use to set the cookie and exclude your resulting traffic from the Analytics results.
Something like http://www.sitename.com/hideme would work well.
2) Set a Custom Dimension within Analytics
From within Analytics, go to the Admin view and under Property select custom definitions.
Click + New Custom Dimension
Enter HideVisit in the name field
Set the scope to User and click Create
(This scope means that unless browser history / cookies are cleared out, your sessions will continue to be masked. If you want a little more control, set this to session which will only apply to that visit).
This basically tells Analytics to listen for the setting of this custom dimension (think of it like a variable).
3) Create Filter to Hide the initial visit
We need two filters. One to hide the initial visit to the /mask folder that sets the cookie and then one for the rest of the scope (Hit / Session / User).
Goto Admin and then under view click Filters
Click + New Filter
Set the filter as follows:
Name: Hide Folder
Filter Type: Predefined Filter
exclude > traffic to the subdirectories > That are equal to
Subdirectory: /hideme/
Case Sensitive: No
Click Save
4) Create Filter to set the Cookie to Ignore the Session
Click + New Filter
Set the filter as follows:
Name: Hide My Visit
Filter Type: Custom Filter
Exclude
Filter Field: HideVisit (this is the name of your Custom Dimension created in step 1 above)
Filter Pattern: hidden
Case Sensitive: No
Click Save
Everything is now in place from an Analytics point of view, now we have to create the page that will do the work.
5) Create Default Web Document
By taking advantage of the default web document (usually index.html) we can use http://www.sitename.com/hideme as the URL that triggers the filter.
Create the following index.html within your /hideme folder (double click to select all for copy/paste):
<html> <head> <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','UA-99999999-99', 'sitename.com'); ga('set', 'dimension1', 'hidden'); ga('send','pageview'); </script> <title>Hide from Universal Analytics</title> <meta name="robots" content="noindex"> <META HTTP-EQUIV="refresh" CONTENT="1;URL=/"> </head> <body> Visit has been excluded from Universal Analytics.... </body> </html>
The index.html file uses a simple layout that incorporates your current Analytics Tracking code. Ensure you change UA-99999999-99 and sitename.com to your settings.
The script sets the Custom Dimension and then uses a Meta Redirect to go back to the root of your site.
Once this is complete, you can test the script by pointing your browser at http://www.sitename.com/hideme and ensure that you get the re-direct.
And that’s it you’re all done.
An important thing to note here is that you cannot rely on the Real Time Analytics view for testing. This doesn’t seem to take note of the filters properly so don’t rely on this for confirmation. You will see after a couple of days that your own visits to your website will now be excluded.
I hope you find this article useful and please feel free to post any questions in the comments.
I’ve tried this method to the letter but didn’t work. It still detects my visits.
Is it still current? Is there a way to check if it has correctly implented inside analytics?
Thank you so much for your effort in such detailed tutorial, though! 🙂
Hey Sergio and welcome to the site.
Yeah the information is still current, I’m using the same method myself. How are you testing to see if it’s working? Hopefully not with the Real Time view as that is confirmed not to use the filters.
Well, I just enter with Firefox in an uncommon language (I usually work with Chrome) where I executed your code.
And I look the next day, and the visit is counted…
My page is http://www.aestivum.com, and the cookie is set through http://www.aestivum.com/hideme
Thank you for your help!
Wait! I just noticed I didn’t change ‘sitename.com’, oh my!! Tomorrow I will confirm everything works fine or otherwise!
Hey Sergio. Hopefully this will be the issue. Also worth making sure you’ve updated the other placeholders like the Analytics tracking ID etc.
Something I overlooked to begin with was ensuring that the initial visit was filtered out too, otherwise when you first get to the site and before the value is set – your visit will be recorded.
It worked!! Great tutorial!!
Just to complete a little bit the tutorial. To create a filter only to view the internal visits with the include filter with the new dimension, what would be the right way?
Really pleased you got it working.
How to show only your own views is a good question.
I’ve started a forum thread here to try and help:
Show only your visits using Google Universal Analytics
Hi,
I thought of another approach using HTML5’s localStorage feature. The advantage over the cookie is that when you clean your browser’s cookies, localStorage values remain.
Interesting option Mathieu. Thanks for sharing.
Hi,
as for the subdirectory, how do you deal with indexing?
Simply excluding via robots.txt ?
Thanks,
Patrizio
Sorry, I wrote too fast, just seen the meta tag robots, noindex! 🙂
Hi Patrizio, glad you found what you were looking for. Even without the noindex or a robots.txt entry, unless you specifically link to this page from somewhere or manually submit it to the search engines – it’s very unlikely they would find it.
At last, a convenient solution for the new Universal Analytics, and all well explained. – Just waiting a couple of days to see it it works !
Thanks for a great post.