There are two typical ways of stopping your internal requests from appearing in and skewing your Google Analytics metrics. Both are outlined in this article from Google, but they boil down to two options:
- Filter by IP
- Filter by cookie
Both are ok choices, but the first becomes unmanageable without a static IP, and doesn’t fit the laptop-based mobile development style that I prefer; and the second relies upon your ability to set and remember to maintain a cookie. And set and maintain said cookie on the browsers of your coworkers, regardless of their tech-savvitity. Oh, if only there were an easier way!
An Easier Way
I wanted a simple way of excluding my and co-worker’s traffic that would be convenient for me, and dead-simple for them, and after starting with Google Search, and ending with Magento Connect, I decided there was nothing out there that fit exactly what I was looking for, so I figured I’d write one.
The end result is Google Analytics Exclude, a tiny extension to Magento which adds an ‘Exclude This Browser’ option to the Magento Admin backend that we know and love. Cookie-based, but not filter-based, you just need to enable it in all browsers that you want excluded from your Google Analytics results. No configuration of Google needed, no special cookie-setting pages required, or static IP’s desired, you can set it with one click and forget it (unless of course you clear your cookies). Also, you can visit the Magento Google API configuration page at any time to verify the cookie is still enabled.
This extension worked so well for us that I decided to package it up and release it for free. Best of all, it’s compatible with Fooman’s GoogleAnalyticsPlus extension. Download Google Analytics Exclude from Magento Connect, or from GitHub; either way, I hope you find it useful:
- GitHub Repository Page: https://github.com/foxrunsoftware/GoogleAnalyticsExclude
- Magento Connect Page: Google Analytics Exclude
Google Analytics Filters
For completeness I decided that I had better also experiment with and outline the filter option of excluding from Google Analytics. There are two main drawbacks I can identify with this method:
- You still appear in the Real Time (Beta) view. Perhaps not the end of the world, but annoying and disconcerting
- This relies on a deprecated function
_setVar(), so who knows how long it will continue to ‘work’.
Needless to say Google Analytics Exclude suffers from neither of these shortcomings, since it simply suppresses the Google Analytics tracking code itself.
Step 1 – Define the Filter
Log in to your Google Analytics account and click the ‘gear’ icon located in the top-right:
Select your account if not already selected. Click on the ‘Filters’ tab, then click ‘+ New Filter’. Configure the filter as follows:
- Filter Name
- This can be whatever you want, but ideally something descriptive
- Filter Field
- This must be ‘User Defined’ and is why the deprecated
_setVar()function must be used. The replacement function
_setCustomVar()function sets custom variables, which apparently can not be used to exclude traffic
- Filter Pattern
- This can also be whatever you like, but make it descriptive, and it must match the value you use in
Save your filter
Step 2 – Create a Page to _setVar()
_setVar() prior to the
var _gaq = _gaq || ; _gaq.push(['_setAccount', 'UA-12345678-1']); _gaq.push(['_setVar','ga_exclude']); // deprecated, but still functional _gaq.push(['_trackPageview']);
Remember to substitute your own analytics ID for
UA-12345678-1 (which can be found by logging into your analytics account). Also, you can pass whatever value you like to
_setVar(), so long as it matches what you configured for Filter Pattern above.
Download a complete example script: ga_exclude.html.gz
Step 3 – Visit the Page
Remember that like Google Analytics Exclude this method relies on setting cookies in your browser. Because of this:
- Your script that we created in Step 2 must be placed on the server that hosts the site you wish to exclude traffic from
- You must visit that page from every browser, on every computer you wish to exclude traffic from. And, assuming you never clear your cookies, you must remember to re-visit this page to refresh the cookie within about 2 years lest it expire
Or, you can just install Google Analytics Exclude, the easy and practical way to exclude your traffic from Google Analytics, and avoid much of the headache.