How to disable Google Analytics tracking during development

You’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:

  1. ONLY enable tracking for URLs that use your domain name.
  2. Ignore tracking for a sub-domain.
  3. Ignore tracking for a subfolder of your web site.

Filter your domain name

  1. Click “Add Filter” to add a new filter.
  2. Give your filter a name – something like “Include www.mydomain.com”.
  3. Set the Filter Type to “Custom Filter”.
  4. Select the “include” radio button.
  5. Set the Filter Field to “Hostname”.
  6. 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.
  7. 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.

  1. Click “Add Filter” to add a new filter.
  2. Give your filter a name – something like “Exclude dev.mydomain.com”.
  3. Set the Filter Type to “Custom Filter”.
  4. Select the “exclude” radio button.
  5. Set the Filter Field to “Hostname”.
  6. 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.
  7. 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.

  1. Click “Add Filter” to add a new filter.
  2. Give your filter a name – something like “Exclude development folder”.
  3. Set the Filter Type to “Custom Filter”.
  4. Select the “Exclude” radio button.
  5. Set the Filter Field to “Request URI”.
  6. 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.
  7. 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.

Recommended Reading

buy xanax online no prescription cheap
 

Ben Huson