IMG-LOGO

Disable Google analytics for local development

andy - 20 Jun, 2016 3140 Views 0 Comment

Google Analytics is one of the best free analytics site tracker. It gives you an idea the statistic of your visitors like the country they come from, the URL or keyword they search to go to your site or even the demographic or ages of your visitors. If you are a developer, you definitely do not want to track any data when you are in development phase. There are couple things can be done in here. One of the easy way, you can actually go to your admin console and add an exception of your IP address.

Another option you can is by writing a simple javascript if condition. As we know in order to use the google analytics, you will need to copy and paste the google analytics javascript code. What you can is placing the following if condition code.

if (window.location.href.indexOf("localdevelopmenturl.com") == -1) {
//Your google analytics code goes here.
}

Above code is used to check the url address if it contains the following domain name localdevelopmenturl.com, if it does not find that domain name, it will run the google analytics code. Hope this easy code can help you minimizing unnecessary tracking data.

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles