-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1483 from alphagov/include-ga-param-in-signins
Pass _ga client id to external signon services
- Loading branch information
Showing
6 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
//= require_tree ./modules | ||
//= require govuk_publishing_components/all_components | ||
//= require set-ga-client-id-on-form | ||
|
||
jQuery(function ($) { | ||
var $form = $('.js-service-sign-in-form') | ||
|
||
if ($form.length) { | ||
new GOVUK.SetGaClientIdOnForm({ $form: $form }) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters