views:

809

answers:

7

I have added the JavaScript that I need to the bottom of my pages so that I can make use of Google Analytics. Only problem is that I am sure that it is counting all my development work as hits. Seeing as I probably see some of those pages a hundred times a day it will really skew my readings. Is there a way to turn it off from a particular IP address or is this something that should be built into my build process so it only gets added when I build for deployment?

+16  A: 

Yeah, you go into Analytics Settings, edit your site, and +Add Filter to define a filter that excludes your IP address.

I'm not clear on whether past data is ever regenerated with filters applied, so you may only have the benefit of them moving forward.

chaos
A [newly created] filter only applies on future data.
Török Gábor
That is perfect. I am doing this proactively. I have not yet actually added the javascript Google Analytics requires. I will put the filter in place and then deploy.
uriDium
+6  A: 

If You are behind NAT or You can't for other reason give Your IP to Google Analytics, then the simplest method is to set the google analytics domain to localhost (127.0.0.1), from now when You open Your browser, all request to Google Analytics will be directed to Your working station, without knowledge of Google Analytics.

astropanic
this, sir, is the simplest solution I have ever seen to this problem! +1 from me
Nir Levy
+1 you don't need to add the filter to every GA account
Eduardo Molteni
How exactly is this done?
yc
simply edit your host file http://en.wikipedia.org/wiki/Hosts_(file)
astropanic
+9  A: 

If you're not using static IP, setting IP filters on GA can't help you.

Set an environment variable and conditionally display it. Take the following Ruby on Rails code, for instance:

<% unless RAILS_ENV == "development" %>
    <!-- your GA code -->
<% end %>

You can extend this behavior every language/framework you use on any operating system. On PHP, you can use the getenv function. Check it out the Wikipedia page on Environment Variables to know how to proceed on your system.

Nando Vieira
This is of limited use as it only applies if the development machine and the system under test are the same one.
JoshJordan
+1  A: 

Probably not helpful to you, but I solved this problem by writing a custom ASP.NET server control that injects the required JavaScript. I then added the live URL to web.config and then only made the control visible when the host name matched the live URL in web.config.

Dan Diplo
+1. I do the same thing.
David
A: 

I use Ad Blocker for Firefox, it can specifically block the Google analytics tracking script. Since firefox is my primary development browser it works great until i need to test my work in other browsers.

Adrian Guido
A: 

get the request host variable.

So wrap an if statement around the analytics javascript like this (Ruby-esque pseudocode):

<body>
<shtuff>dfsfsdf</shtuff>
if not (request.host == 'localhost')
  #analytics code here
elsif (request.host == the server's ip/domain)
  #analytics code here
else
  #do nothing
end
</body>
A: 

Like people are mentioning you can either host the google-analytics.com domain locally or setup a function to see if you are working in your development network.

Keep in mind if http://www.google-analytics.com/ga.js does not load and your using onclick javascript functions to help track clicks on page elements.

IE: onclick="javascript:pageTracker._trackPageview('/made/up/folder/reference');

Your going to have JavaScript errors that will stop jQuery or other robust JavaScript functions from functioning.

Jason Gegere