Google Universal Analytics.js tracking code for SilverStripe
An extension to add Google Universal Analytics
gtag() tracking code (not to be confused with Google Tag Manager) to your Silverstripe templates.
It automatically includes optional unobtrusive event tracking for all outbound links & "asset downloads", as well as event tracking for 404 and error pages, email & telephone links.
gtag()functions in your other code.
pageviewtracking for all configured accounts, including tracking of 404 & 500 page errors (tracked as "Page Not Found" / "Page Error" events).
hitCallbackfor tracking for outgoing links to register before load (ie: when no link
targetis set) to ensure tracker is successfully run before redirection.
SS_ENVIRONMENT_TYPEis not live, or if page URL matches ?flush= to prevent bad data capture.
Additional event tracking is automatically enabled by default for:
mailto:) links are tracked as "Email Links".
tel:) links are tracked as "Phone Links".
Event category names (eg: "Outgoing Links", "Downloads" etc) can be configured in your yaml config.
Note: Event tracking only works with regular (left-or-middle) mouse button clicks (including combinations with Ctrl/Shift/Meta keys). Tracking is bypassed if the user right-clicks on a link and selects an action from the context menu (open in new tab, save as etc...). Unfortunately there is no way around this without disabling the content menu entirely.
For the deprecated
analytics.js tracking method for Silverstripe 4, please refer to the analytics.js branch.
For Silverstripe 3, please refer to the Silverstripe3 branch.
You can install it via composer with
composer require axllent/silverstripe-analytics-js
Once installed the extension is automatically loaded if you provide at least one tracking account in your config yaml file (eg)
Axllent\AnalyticsJS\AnalyticsJS: tracker: - ['config', 'UA-1234567-1']
The syntax is very similar to the official documentation, so things like secondary trackers or other configurations can be easily added.
Please refer to the Configuration.md for all configuration options.
To start live tracking, make sure your website is in
live mode, or if running in
staging that you
track_in_dev_mode: true option.
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem