How to cleanly remove the statistics
There are a number of ways you can remove page views from Google Analytics, for example:
- Using Google Analytics filters on Google’s website
How to set up the tracking code
Old tracking code (default tracking code):
Modified tracking code:
In CasperJS, ensure the correct user agent is set:
I opted to use a Chrome user agent, with an extension on the end to denote CasperJS (and the version).
If you use Drupal, then you can just use the following code in your own custom module:
Update 1st May 2013
Have updated the JS alter hook to be more robust, as the original code was causing JS errors on Drupal search pages. If you have used the old code, please update the the new code (found above).
Wait can you exclude other services from Google Analytics?
If you look at the above regex on the user agent matching, you can see I have added Pingdom into there as well. This is merely an example to show you the flexibility of this solution. You can adjust the regex to match the user agents you want to block.
If you remove CasperJS from Google Analytics in another fashion (or don’t bother and have a reason), or have some improvements, let me know in the comments.