Google Analytics is a great tool and can help you gauge your site’s user-friendliness and visitor patterns. It’s free, so there really aren’t many reasons why not to use it.
One small issue that I ran into is that there are times when you do not want user actions to be logged.
For me this happens whenever I am working on/testing/debugging a site on a local server before uploading it to the Internets. Clearly, I do not want my page re-freshes and clicking patterns logged.
I wrote a very simple PHP wrapper for Google Analytics to help me get around this issue.
The way it works is quite simple:
- You specify a list of server addresses
- The wrapper checks the address of the server the script is running on, and if it is in the list, Google Analytics script is not included in the page
You can download the script here. Modify the definition of the LocalServers variable in ccGoogleAnalytics.php. It currently excludes logging on 127.0.0.1, 192.168.1.100, 192.168.1.101.
Here is a sample implementation (also contained in test.php in the package):
include "include/ccGoogleAnalytics.php"; $AnalyticsInstance = new ccGoogleAnalytics("GoogleID"); $AnalyticsInstance->LogUserActivity();
You will need to replace ‘GoogleID’ with your analytics ID, which typically looks like