Tag: tracking

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:

https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#automatic_cookie_domain_configuration

08th March 2016