Skip to content

Commit

Permalink
Remove tracking for verify users
Browse files Browse the repository at this point in the history
What

Remove tracking for verify users

Why

This tracking is no longer required
  • Loading branch information
gclssvglx committed Nov 11, 2021
1 parent 9f4dffb commit cef9d63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 140 deletions.
47 changes: 4 additions & 43 deletions app/assets/javascripts/modules/track-radio-group.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
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) {
this.element = element
}

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)

Expand All @@ -42,40 +29,14 @@ 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) {
value = 'submitted-without-choosing'
} else {
value = element.value
}

if (withHint) {
value += '-with-hint'
}
return value
}

Expand Down
98 changes: 1 addition & 97 deletions spec/javascripts/track-radio-group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand All @@ -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' }
)
})
})
Expand Down

0 comments on commit cef9d63

Please sign in to comment.