Extension to add Google Analytics tracking code to your SilverStripe templates.
It includes tracking for all external links & "assets" downloads using pure JavaScript, so no external libraries are needed.
- Unobtrustive tracking - attaches to document.body.onclick and monitors all clicks at time of click, rather than on page load (ie: works with links including those generated by Ajax etc on the page after page load).
- File downloads (from the assets folder) are tracked as events "Downloads".
- Outgoing links are tracked as events "Outgoing Links".
- Tracking for both outgoing links and downloads have built-in (500ms) delay if no target is set to allow for GA tracking.
- Tracking of 404 & 500 page errors (tracked as an events) - Note: you must Save & Publish both your error pages after module installation.
- Development mode is commented out to prevent false tracking. It only actually works in live mode.
- SilverStripe 3+
In your _config.php or _ss_environment.php add your GA tracking code
define('GaTrackingCode', 'UA-xxxxxx');
as well as an optional secondary tracker
define('GaTrackingCodeSecondary', 'UA-yyyyyy');
To include tracker with external JavaScript resource (download/outgoing tracking), simply add
$GoogleAnalytics
or to include tracker and download/outgoing tracking inline, simply add
$GoogleAnalyticsInline
To start tracking, make sure your website is in Live mode
define('SS_ENVIRONMENT_TYPE', 'live');