I've starting modifying my analytics code as follows:
if (!/staging|localhost/.test(window.location.hostname)) _gaq.push(['_setAccount', 'UA-XXXXX-X']);
In brief, if we're on our staging server, don't set the web property ID . This results in the tracker using a default ID -- something like "UA-99999-9".
- The analytics code functions normally, but any data is sent to the default web property ID. This is nice because it's possible to verify that the analytics code is working.
Note: I used to put the conditional on the _trackPageview call -- The problem with this is that other analytics code (like _trackEvent, etc) will still be sending data.