Files
notifications-admin/app/assets/javascripts/analytics.js
Chris Hill-Scott 8e6efadb23 Track virtual page view when enabling basic view
So we can see what pages people go to after turning it on.
2018-08-02 15:23:52 +01:00

57 lines
1.1 KiB
JavaScript

let stripUUIDs = string => string.replace(
/[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}/g, '…'
);
(function(Modules) {
"use strict";
function sendEvent(category, action, label) {
if (!ga) return;
ga('send', 'event', category, action, label);
}
function sendVirtualPageView(path) {
if (!ga) return;
ga('send', 'pageview', stripUUIDs('/virtual' + path));
}
Modules.TrackError = function() {
this.start = component => sendEvent(
'Error',
$(component).data('error-type'),
$(component).data('error-label')
);
};
Modules.TrackEvent = function() {
this.start = component => sendEvent(
$(component).data('event-category'),
$(component).data('event-action'),
$(component).data('event-label')
);
};
Modules.TrackFormSubmission = function() {
this.start = component => {
$(component).on('submit', function() {
let formData = $('input[name!=csrf_token]', this).serialize();
sendVirtualPageView(window.location.pathname + '?' + formData);
});
};
};
})(window.GOVUK.Modules);