How to disable Google Analytics tracking during development
Thursday, 4th October 2007You’ve put your Google Analytics tracking code into all pages of your web site, but then what happens when you want to test your site locally or at a diffent URL where you host a development environment?
You need to make sure your Analytics profile is set to only track pages when there are hosted at your domain and not while you are testing and developing your site. To do this you need to set up filters within your Analytics account.
Once logged in to your Analytics account, the Filter Manager is located at the bottom right of the page. Click “Filter Manager” to view the filters for your account.
There are a few filters you may need to add to achieve the following, particularly if you use a sub-domain or sub-folder of your web site as a development environment:
- ONLY enable tracking for URLs that use your domain name.
- Ignore tracking for a sub-domain.
- Ignore tracking for a subfolder of your web site.
Filter your domain name
- Click “Add Filter” to add a new filter.
- Give your filter a name – something like “Include www.mydomain.com”.
- Set the Filter Type to “Custom Filter”.
- Select the “include” radio button.
- Set the Filter Field to “Hostname”.
- Set the Filter Pattern to “
www\.mydomain\.com$“.
The slashes are required to escape full stops (and any other regular expression characters including hyphens).
The dollar sign indicates the end of the domain name.
You should not include the “www” of your domain name if the site can be accessed without it or you require tracking to be enabled for sub-domains. - Select the profiles for which you would like to enable this filter.
If you need to track pages across several domains, you should set your filter patterns to “mydomain\.com$|otherdomain\.com$” using a pipe character to separate the domains.
Exclude a sub-domain
If you have not included the www prefix from your filter above because you want to track sub-domains, you may wish to block a sub-domain – for example, if you were using it as a development environment.
- Click “Add Filter” to add a new filter.
- Give your filter a name – something like “Exclude dev.mydomain.com”.
- Set the Filter Type to “Custom Filter”.
- Select the “exclude” radio button.
- Set the Filter Field to “Hostname”.
- Set the Filter Pattern to “
dev\.mydomain\.com$“.
The slashes are required to escape full stops (and any other regular expression characters including hyphens).
The dollar sign indicates the end of the domain name. - Select the profiles for which you would like to enable this filter.
Exclude a sub-folder
You may want to exclude files in a folder on your web site from being tracked. You could obviously not put the Google Analytics tracking code in these pages. However, if you use a folder for previewing pages before uploading them to your live site, this would be impractical so here’s how you block tracking for pages in a folder.
- Click “Add Filter” to add a new filter.
- Give your filter a name – something like “Exclude development folder”.
- Set the Filter Type to “Custom Filter”.
- Select the “Exclude” radio button.
- Set the Filter Field to “Request URI”.
- Set the Filter Pattern to “
^/devfolder/“.
Forward slashes are required to escape hyphens (and any other regular expression characters).
The “^” indicates the start of the directory structure. - Select the profiles for which you would like to enable this filter.
Catch All
I also find it useful to set up a ‘catch all’ profile for my site in Google Analytics. I use this profile without any filter to track ALL hits, wether they have occurred on a staging or development server, or on the live site. This enables me to test any changes to tracking code I have may in my development environment by checking my ‘catch all’ profile before releasing to the live server.
Alternatively you could set up a profile that exclude hits to the live site but includes them from anywhere else. The process is similar to creating a filter to include your domain name (mentioned above) – the only difference is you need select the “exclude” radio button instead.
December 5th, 2007 at 11:42 am
Well done, Ben! You’ve answered all my questions re: what to do about development sites and GA.
March 5th, 2008 at 2:54 am
Thank you for the tips!!!
April 21st, 2008 at 8:56 am
Hi Ben,
Thanks for the post…
I want to test my analytics code on Dev environment before taking it live.
Our Dev server is not on http://www... so Google wont be able to access it using the URI… This should be the common setting that people do…
What is the solution in such a case?
Thanks in advance
April 21st, 2008 at 9:40 am
[...] tried to Google this, but so far haven’t found anything significant exceptthis, and even that doesn’t have exactly what I am talking [...]
April 21st, 2008 at 3:00 pm
I am little confused here. Why would you guys want to put google analytics on a test env?
April 21st, 2008 at 7:48 pm
I guess you may want to enable analytics for a dev site to test you have it set up correctly – particularly if you want to test some of the more advanced functionality of Google Analytics such as the JavaScript tracking functions or e-commerce functionality.
It appears that the tracking code only seems to work if you are using it over an http:// (or https://) connection. If you have a proper development site set up on a local server or at an IP address, this should be fine. However it won’t track anything you open locally on your computer or network over a file:// connection.
If you want to track a development environment separately from your live site you do not need to create a new Analytics account. Instead just create a new profile and use filters (as mentioned in the above post) to filter hits based on the hostname within your live and dev profiles.
February 3rd, 2009 at 5:54 am
Thanks for the post as it answered my question on how to exclude page urls that are from my local dev environment.
Does it filter existing data? If so, does it take a while before your filter is effective?
February 13th, 2009 at 7:55 pm
Thanks for sharing the info.
It’s quite useful.
August 6th, 2009 at 8:03 pm
Great info Ben – Thank you