diff --git a/app/assets/javascripts/modules/track-radio-group.js b/app/assets/javascripts/modules/track-radio-group.js index 107c76024..4543df4f9 100644 --- a/app/assets/javascripts/modules/track-radio-group.js +++ b/app/assets/javascripts/modules/track-radio-group.js @@ -1,12 +1,5 @@ window.GOVUK = window.GOVUK || {} -window.GOVUK.Modules = window.GOVUK.Modules || {} - -// This callback is triggered by the script attached to the DOM by the -// checkVerifyUser function. It has to be outside the module because the script -// can't access the running instance of TrackRadioGroup -window.GOVUK.TrackRadioGroupVerify = function (data) { - window.GOVUK.triggerEvent(document, 'have-verify-data', { detail: data }) -}; +window.GOVUK.Modules = window.GOVUK.Modules || {}; (function (Modules) { function TrackRadioGroup (element) { @@ -14,25 +7,19 @@ window.GOVUK.TrackRadioGroupVerify = function (data) { } TrackRadioGroup.prototype.init = function () { - document.addEventListener('have-verify-data', function (event) { - this.reportVerifyUser(this.element, event.detail) - }.bind(this)) - this.track(this.element) if (this.crossDomainTrackingEnabled(this.element)) { this.addCrossDomainTracking(this.element) } - - this.checkVerifyUser(this.element) } - TrackRadioGroup.prototype.track = function (element, withHint) { + TrackRadioGroup.prototype.track = function (element) { this.element.addEventListener('submit', function (event) { var options = { transport: 'beacon' } var submittedForm = event.target var checkedOption = submittedForm.querySelector('input:checked') - var eventValue = this.eventTrackingValue(checkedOption, withHint) + var eventValue = this.eventTrackingValue(checkedOption) GOVUK.analytics.trackEvent('Radio button chosen', eventValue, options) @@ -42,29 +29,7 @@ window.GOVUK.TrackRadioGroupVerify = function (data) { }.bind(this)) } - // The analytics data should include whether the user has previously signed in - // to Verify this simulates the behaviour of JSONP, returning a true or false - // value from Verify - TrackRadioGroup.prototype.checkVerifyUser = function (element) { - var url = 'https://www.signin.service.gov.uk/hint' - var timestamp = Math.floor(Date.now() / 1000) - var script = document.createElement('script') - script.setAttribute('src', url + '?callback=window.GOVUK.TrackRadioGroupVerify&_=' + timestamp) - document.body.appendChild(script) - } - - TrackRadioGroup.prototype.trackVerifyUser = function (element, data) { - this.reportVerifyUser(element, data) - } - - TrackRadioGroup.prototype.reportVerifyUser = function (element, data) { - if (data != null && data.value === true) { - GOVUK.analytics.trackEvent('verify-hint', 'shown', { transport: 'beacon' }) - this.track(element, data.value) - } - } - - TrackRadioGroup.prototype.eventTrackingValue = function (element, withHint) { + TrackRadioGroup.prototype.eventTrackingValue = function (element) { var value = null if (typeof element === 'undefined' || element === null) { @@ -72,10 +37,6 @@ window.GOVUK.TrackRadioGroupVerify = function (data) { } else { value = element.value } - - if (withHint) { - value += '-with-hint' - } return value } diff --git a/spec/javascripts/track-radio-group.spec.js b/spec/javascripts/track-radio-group.spec.js index d12ce6326..abc9009e6 100644 --- a/spec/javascripts/track-radio-group.spec.js +++ b/spec/javascripts/track-radio-group.spec.js @@ -49,100 +49,6 @@ describe('A radio group tracker', function () { ) }) - it('tracks govuk-verify-with-hint event when clicking submit if user has visited verify', function () { - var data = { - status: 'OK', - value: true - } - tracker.trackVerifyUser(element, data) - element.find('input[value="govuk-verify"]').trigger('click') - element.find('button').trigger('click') - - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'verify-hint', 'shown', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify-with-hint', { transport: 'beacon' } - ) - }) - - it('does not track govuk-verify-with-hint event when clicking submit if user has not visited verify', function () { - var data = { - status: 'OK', - value: false - } - tracker.trackVerifyUser(element, data) - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'verify-hint', 'shown', { transport: 'beacon' } - ) - element.find('input[value="govuk-verify"]').trigger('click') - element.find('button').trigger('click') - - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify-with-hint', { transport: 'beacon' } - ) - }) - - it('does not track govuk-verify-with-hint event when clicking submit if verify value is not boolean', function () { - var data = { - status: 'OK', - value: 'bar' - } - tracker.trackVerifyUser(element, data) - element.find('input[value="govuk-verify"]').trigger('click') - element.find('button').trigger('click') - - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'verify-hint', 'shown', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify-with-hint', { transport: 'beacon' } - ) - }) - - it('does not track govuk-verify-with-hint event when clicking submit if verify response is null', function () { - var data = null - tracker.trackVerifyUser(element, data) - element.find('input[value="govuk-verify"]').trigger('click') - element.find('button').trigger('click') - - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'verify-hint', 'shown', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify-with-hint', { transport: 'beacon' } - ) - }) - - it('does not track govuk-verify-with-hint event when clicking submit if verify response is not an object', function () { - var data = 'string' - tracker.trackVerifyUser(element, data) - element.find('input[value="govuk-verify"]').trigger('click') - element.find('button').trigger('click') - - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'verify-hint', 'shown', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify', { transport: 'beacon' } - ) - expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify-with-hint', { transport: 'beacon' } - ) - }) - it('tracks no choice when clicking submit and checked nothing', function () { element.find('button').trigger('click') @@ -153,8 +59,6 @@ describe('A radio group tracker', function () { describe('cross domain tracking enabled', function () { beforeEach(function () { - tracker.trackVerifyUser(element, { status: 'OK', value: true }) - spyOn(GOVUK.analytics, 'addLinkedTrackerDomain') element.attr('data-tracking-code', 'UA-xxxxxx') @@ -176,7 +80,7 @@ describe('A radio group tracker', function () { element.find('button').trigger('click') expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith( - 'Radio button chosen', 'govuk-verify-with-hint', { trackerName: 'testTracker', transport: 'beacon' } + 'Radio button chosen', 'govuk-verify', { trackerName: 'testTracker', transport: 'beacon' } ) }) })