diff --git a/app/assets/javascripts/analytics.js b/app/assets/javascripts/analytics.js new file mode 100644 index 000000000..e1b871cf8 --- /dev/null +++ b/app/assets/javascripts/analytics.js @@ -0,0 +1,56 @@ +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); diff --git a/app/assets/javascripts/errorTracking.js b/app/assets/javascripts/errorTracking.js deleted file mode 100644 index 3b7053841..000000000 --- a/app/assets/javascripts/errorTracking.js +++ /dev/null @@ -1,22 +0,0 @@ -(function(Modules) { - "use strict"; - - Modules.TrackError = function() { - - this.start = function(component) { - - if (!ga) return; - - ga( - 'send', - 'event', - 'Error', - $(component).data('error-type'), - $(component).data('error-label') - ); - - }; - - }; - -})(window.GOVUK.Modules); diff --git a/app/templates/admin_template.html b/app/templates/admin_template.html index a78581cfd..d1d51df89 100644 --- a/app/templates/admin_template.html +++ b/app/templates/admin_template.html @@ -128,10 +128,7 @@ ga('set', 'anonymizeIp', true); ga('set', 'displayFeaturesTask', null); ga('set', 'transport', 'beacon'); - // strip UUIDs - page = (window.location.pathname + window.location.search).replace( - /[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}/g, '…' - ) - ga('send', 'pageview', page); + page = window.location.pathname + window.location.search; + ga('send', 'pageview', stripUUIDs(page)); {% endblock %} diff --git a/app/templates/views/service-settings/set-basic-view.html b/app/templates/views/service-settings/set-basic-view.html index 535d9b70c..118e13f39 100644 --- a/app/templates/views/service-settings/set-basic-view.html +++ b/app/templates/views/service-settings/set-basic-view.html @@ -9,7 +9,11 @@ {% block maincolumn_content %}