Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass _ga client id to external signon services #1483

Merged
merged 1 commit into from
Sep 16, 2019

Conversation

bilbof
Copy link
Contributor

@bilbof bilbof commented Sep 12, 2019

On pages such as https://www.gov.uk/log-in-file-self-assessment-tax-return/sign-in/prove-identity
we redirect users to services such as tax.service.gov.uk to complete their sign in.

This will pass the _ga cookie as the _ga param as part of cross-domain tracking, so that we can measure user journeys across domains.

This will only pass the _ga param to other .gov.uk services. Currently these are:

Pages to check:

The urls we redirect to are defined in service_sign_on content item details.choose_sign_in.options (example).

Further work is required on the signin.service.gov.uk to make use of the _ga param and ensure it is included in further redirects.

Trello: https://trello.com/c/ORdXWurC/101

@bevanloon bevanloon temporarily deployed to government-frontend-pr-1483 September 12, 2019 14:02 Inactive
andysellick
andysellick previously approved these changes Sep 12, 2019
@bilbof
Copy link
Contributor Author

bilbof commented Sep 12, 2019

I'm going to do some reading to find out whether the cookie will work, or if we need to pass a value generated by the analytics.js library instead.

@bilbof bilbof force-pushed the include-ga-param-in-signins branch from 2ed6c11 to 2431c7a Compare September 12, 2019 16:30
@bevanloon bevanloon temporarily deployed to government-frontend-pr-1483 September 12, 2019 16:31 Inactive
@bilbof bilbof requested a review from andysellick September 12, 2019 16:31
@bilbof
Copy link
Contributor Author

bilbof commented Sep 12, 2019

@andysellick I need to get the client id from the analytics.js library, rather than simply using the cookie, so I've added a bit of JS to do that magic. Please could I get some more 👀 on this?

@andysellick andysellick dismissed their stale review September 12, 2019 19:07

Further changes made :)

On pages such as https://www.gov.uk/log-in-file-self-assessment-tax-return/sign-in/prove-identity
we redirect users to services such as tax.service.gov.uk
to complete their sign in.

This will pass the client id as a _ga param as part of
cross-domain tracking, so that we can measure user journeys
across domains.

This will only pass the _ga param to other .gov.uk services.
Currently these are:
tax.service.gov.uk
www.signin.service.gov.uk
www.ruralpayments.service.gov.uk

Further work is required on the signin.service.gov.uk to
make use of the _ga param and ensure it is included in
redirects.

Trello: https://trello.com/c/ORdXWurC/101
window.ga(function(tracker) {
var clientId = tracker.get('clientId')
var action = form.attr('action')
form.attr('action', action + "?_ga=" + clientId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this won't work as intended if the action URL already includes query parameters. Do you know if any action URLs include query parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The form currently submits without query parameters for all URLs (apart from the _ga param).

https://github.com/alphagov/government-frontend/pull/1483/files#diff-1e002ab60ce763d5443df324a62b2bcfR22

I checked the service sign in pages published by publisher from https://github.com/alphagov/publisher/tree/master/lib/service_sign_in and they seem to work (some of those rendered by the Heroku app are linked to in the description).

I considered using url = new URL(action) and then do something like url.searchParams.set('_ga', 'clientId') which would handle the case of multiple query params. But the constructor isn't supported by Internet Explorer (https://developer.mozilla.org/en-US/docs/Web/API/URL#Browser_compatibility).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 👍

if ($form.length) {
new GOVUK.SetGaClientIdOnForm({ $form: $form })
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the module system in the govuk_frontend_toolkit would be able to handle this. https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/javascript.md#modules

That's used elsewhere in this app, in the track-radio-group.js file. Is that something you considered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can do, I'd need to roll the behaviour into the track-radio-group module since that module is already applied to the form at https://github.com/alphagov/government-frontend/pull/1483/files#diff-1e002ab60ce763d5443df324a62b2bcfR17, unless there's a way to apply two modules to the same element?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I didn't anticipate a one module per element restriction, but it looks from the code like that's the case [1].

1: https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/modules.js#L31

In which case, I'd just stick with your current approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will do.

Copy link
Contributor

@cbaines cbaines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@bilbof bilbof merged commit 7cef9fb into master Sep 16, 2019
@bilbof bilbof deleted the include-ga-param-in-signins branch September 16, 2019 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants