mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-09 19:04:33 -04:00
Add event tracking to window.GOVUK.analytics
app/assets/javascripts/errorTracking.js sent events to `window.ga`. This extends the API of `window.GOVUK.Analytics` to include support for sending events so all calls to `window.ga` can use it instead of direct access. This use of `window.ga` was missed from the initial work on `window.GOVUK.Anaytics`.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
window.GOVUK = window.GOVUK || {};
|
||||
|
||||
// Stripped-down wrapper for Google Analytics, based on:
|
||||
// https://github.com/alphagov/static/blob/master/app/assets/javascripts/analytics_toolkit/analytics.js
|
||||
// https://github.com/alphagov/static/blob/master/doc/analytics.md
|
||||
const Analytics = function (config) {
|
||||
window.ga('create', config.trackingId, config.cookieDomain);
|
||||
|
||||
@@ -34,6 +34,29 @@
|
||||
|
||||
};
|
||||
|
||||
// https://developers.google.com/analytics/devguides/collection/analyticsjs/events
|
||||
Analytics.prototype.trackEvent = function (category, action, options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
var evt = {
|
||||
eventCategory: category,
|
||||
eventAction: action
|
||||
};
|
||||
|
||||
if (options.label) {
|
||||
evt.eventLabel = options.label;
|
||||
delete options.label;
|
||||
}
|
||||
|
||||
if (typeof options === 'object') {
|
||||
$.extend(evt, options);
|
||||
}
|
||||
|
||||
window.ga('send', 'event', evt);
|
||||
|
||||
};
|
||||
|
||||
window.GOVUK.Analytics = Analytics;
|
||||
|
||||
})(window);
|
||||
|
||||
Reference in New Issue
Block a user