Skip to content

Commit cb0c9b7

Browse files
authored
Revert "Add GA params to /ask survey link"
1 parent 4b2b905 commit cb0c9b7

5 files changed

+46
-86
lines changed

app/assets/javascripts/application.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
//= require_tree ./modules
22
//= require govuk_publishing_components/all_components
3-
//= require set-ga-client-id-on-url-in-element
3+
//= require set-ga-client-id-on-form
44

55
jQuery(function ($) {
66
var $form = $('.js-service-sign-in-form')
7-
if ($form.length) {
8-
new GOVUK.SetGaClientIdOnUrlInElement({
9-
$linkedElement: $form,
10-
attribute: 'action'
11-
})
12-
}
137

14-
if ($(location).attr('pathname') === '/ask') {
15-
var $link = $('[href="https://www.smartsurvey.co.uk/ss/govuk-coronavirus-ask/"]')
16-
new GOVUK.SetGaClientIdOnUrlInElement({
17-
$linkedElement: $link,
18-
attribute: 'href'
19-
})
8+
if ($form.length) {
9+
new GOVUK.SetGaClientIdOnForm({ $form: $form })
2010
}
2111
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(function () {
2+
'use strict'
3+
4+
window.GOVUK = window.GOVUK || {}
5+
var GOVUK = window.GOVUK
6+
7+
function SetGaClientIdOnForm (options) {
8+
if (!options.$form || !window.ga) { return }
9+
10+
var form = options.$form
11+
12+
window.ga(function(tracker) {
13+
var clientId = tracker.get('clientId')
14+
var action = form.attr('action')
15+
form.attr('action', action + "?_ga=" + clientId)
16+
});
17+
}
18+
19+
GOVUK.SetGaClientIdOnForm = SetGaClientIdOnForm
20+
})(window, window.GOVUK);

app/assets/javascripts/set-ga-client-id-on-url-in-element.js

-23
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* global describe beforeEach it expect */
2+
3+
var $ = window.jQuery
4+
5+
describe('SetGaClientIdOnForm', function () {
6+
7+
var GOVUK = window.GOVUK
8+
var tracker = { clientId: 'clientId' }
9+
tracker.get = function(arg) { return this[arg] }
10+
window.ga = function(callback) { callback(tracker) }
11+
var form
12+
13+
beforeEach(function () {
14+
form = $(
15+
'<form class="js-service-sign-in-form" action="/endpoint"></form>'
16+
)
17+
setter = new GOVUK.SetGaClientIdOnForm({ $form: form })
18+
})
19+
20+
it('sets the _ga client id as a query param on the form action', function () {
21+
expect(form.attr('action')).toBe('/endpoint?_ga=clientId')
22+
})
23+
})

spec/javascripts/set-ga-client-id-on-url-in-element.spec.js

-50
This file was deleted.

0 commit comments

Comments
 (0)