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 devel
Just as an additional option for this, I have a development server with lots of different sites and developers. This meant that I wasn't particularly happy with the 3 main options
Rather than implementing the various options in the other answers here I approached the problem in the following way. In the global httpd.conf (rather than a site specific one) I used the apache module mod_substitute to simulate the effect the hosts file fix in another answer has, but for every development site, and every developer automatically.
Enable the module
CentOS: Open /etc/conf/httpd.conf
and add the following line
LoadModule substitute_module modules/mod_substitute.so
Ubuntu/Debian: Run the following command
sudo a2enmod substitute
Once you've got the module enabled add the following lines to your httpd global config file
CentOS: /etc/conf/httpd.conf
Ubuntu/Debian: /etc/apache2/httpd.conf
# Break Google Analytics
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|.google-analytics.com|.127.0.0.1|n"
Then restart apache
CentOS: service httpd restart
Ubuntu/Debian: /etc/init.d/apache2 restart
What this does is replace all text matching .google-analytics.com with .127.0.0.1 when apache serves the page so your page renders with analytics code similar to the below example
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.127.0.0.1/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();