Skip to content

Commit

Permalink
Merge pull request #1761 from alphagov/revert-1744-add-ga-param-for-ask
Browse files Browse the repository at this point in the history
Revert "Add GA params to /ask survey link"
  • Loading branch information
kevindew authored May 13, 2020
2 parents 3a65e6c + cb0c9b7 commit d8b5fbd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 86 deletions.
16 changes: 3 additions & 13 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
//= require_tree ./modules
//= require govuk_publishing_components/all_components
//= require set-ga-client-id-on-url-in-element
//= require set-ga-client-id-on-form

jQuery(function ($) {
var $form = $('.js-service-sign-in-form')
if ($form.length) {
new GOVUK.SetGaClientIdOnUrlInElement({
$linkedElement: $form,
attribute: 'action'
})
}

if ($(location).attr('pathname') === '/ask') {
var $link = $('[href="https://www.smartsurvey.co.uk/ss/govuk-coronavirus-ask/"]')
new GOVUK.SetGaClientIdOnUrlInElement({
$linkedElement: $link,
attribute: 'href'
})
if ($form.length) {
new GOVUK.SetGaClientIdOnForm({ $form: $form })
}
})
20 changes: 20 additions & 0 deletions app/assets/javascripts/set-ga-client-id-on-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function () {
'use strict'

window.GOVUK = window.GOVUK || {}
var GOVUK = window.GOVUK

function SetGaClientIdOnForm (options) {
if (!options.$form || !window.ga) { return }

var form = options.$form

window.ga(function(tracker) {
var clientId = tracker.get('clientId')
var action = form.attr('action')
form.attr('action', action + "?_ga=" + clientId)
});
}

GOVUK.SetGaClientIdOnForm = SetGaClientIdOnForm
})(window, window.GOVUK);
23 changes: 0 additions & 23 deletions app/assets/javascripts/set-ga-client-id-on-url-in-element.js

This file was deleted.

23 changes: 23 additions & 0 deletions spec/javascripts/set-ga-client-id-on-form.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* global describe beforeEach it expect */

var $ = window.jQuery

describe('SetGaClientIdOnForm', function () {

var GOVUK = window.GOVUK
var tracker = { clientId: 'clientId' }
tracker.get = function(arg) { return this[arg] }
window.ga = function(callback) { callback(tracker) }
var form

beforeEach(function () {
form = $(
'<form class="js-service-sign-in-form" action="/endpoint"></form>'
)
setter = new GOVUK.SetGaClientIdOnForm({ $form: form })
})

it('sets the _ga client id as a query param on the form action', function () {
expect(form.attr('action')).toBe('/endpoint?_ga=clientId')
})
})
50 changes: 0 additions & 50 deletions spec/javascripts/set-ga-client-id-on-url-in-element.spec.js

This file was deleted.

0 comments on commit d8b5fbd

Please sign in to comment.