How to disable and ignore Google Analytics tracking during development

While I was finishing off the last few tweaks of Redlight, an open-source E-Commerce template, I begun to notice my Google Analytics dashboard was recording page views and events from my local development environment. Since I use Google Analytics for a lot of my open-source and client projects, I decided to investigate this further and find a solution.

After a quick Google bashing I found a few answers, but none seemed to be a quick and clean approach to the problem. One of the solutions proposed was to add a custom exclude filter by IP address, however, since I generally work in several different places during my work day, this did not seem to be a viable solution to my problem.

Eventually I stumbled upon some Google Analytics documentation which explained how a developer can customise the cookie settings for creating a ga Javascript object. Amongst these settings, there is a cookieDomain option which enables a user to define the domain which is allowed to register and send Google Analytics data. The default value for this is auto, however, this can be customised to your own production domain, for example:

As you can see from the above snippet, I have defined the domain for the webpage as an parameter value when creating a ga object. This enables us to restrict the domain for any Google Analytics events and/or page views on your application.

If you would like more information, please check out the Google Analytics documentation:

08th March 2016

Any thoughts?

Your email address will not be published. Required fields are marked *


CAPTCHA * Time limit is exhausted. Please reload CAPTCHA.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">