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

Remove jq from set ga client #2260

Merged
merged 2 commits into from
Nov 4, 2021
Merged

Conversation

JonathanHallam
Copy link
Contributor

What

Remove jQuery from the set ga client id file.

Why

We're using an old and unsupported version of jQuery for browser support reasons. Rather than upgrade, it's far better to remove our dependence.

jQuery makes writing JavaScript easier, but it doesn't do anything that you can't do with vanilla JavaScript, because it's all written in JavaScript.

Once it's removed, we no longer have to worry about upgrading it, and users don't have to download the jQuery library when they visit GOV.UK.

Trello

https://trello.com/c/bqdisKbm/277-from-jquery-from-government-frontend-set-ga-client-id-on-formjs-and-applicationjs-moderate-js-knowledge-required

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

@govuk-ci govuk-ci temporarily deployed to government-f-remove-jq--jt1zyx October 28, 2021 13:43 Inactive
@JonathanHallam JonathanHallam force-pushed the remove-jq-from-set-ga-client-id branch from b73db0e to ffb37c3 Compare November 3, 2021 15:37
Copy link
Contributor

@andysellick andysellick left a comment

Choose a reason for hiding this comment

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

🚀

The only code in application.js is to initialise the ga tracker
so they're being done at the same time. I've removed one `get`
but not the other because the `tracker` object is defined by google
while the `form` object is a standard HTML element

You will notice that the application.js calls on the `getElementsByClassName`
method which can return multiple results. Then we're only using the first
element of that list. This isn't ideal but we have confidence that this
class can only be used once on each page which makes this fine.

Call route for the set-ga-client-id-on-form
- application.js is the only file that calls on it
- it only applies it to elements with the `js-service-sign-in-form` class
- that class is only created by [this partial](https://github.com/alphagov/government-frontend/blob/main/app/views/content_items/service_sign_in/_choose_sign_in.html.erb#L25)
- that partial is only rendered by [this page](https://github.com/alphagov/government-frontend/blob/main/app/views/content_items/service_sign_in.html.erb#L8) by way of a method in [this presenter](https://github.com/alphagov/government-frontend/blob/main/app/presenters/service_sign_in/choose_sign_in_presenter.rb#L5)
- This means we can be confident there's only one element of that class on a page, huzah!
tracker is an object that comes directly from google. This is why the `get`
method call has been kept on it, it's not a jQ object so the method is
defined by google rather than jQ. I've renamed the `tracker` object in the
tests to make it more obvious that it's something we don't have ownership
over
@JonathanHallam JonathanHallam force-pushed the remove-jq-from-set-ga-client-id branch from ffb37c3 to 3d40e41 Compare November 4, 2021 10:30
@JonathanHallam JonathanHallam merged commit 635c4f9 into main Nov 4, 2021
@JonathanHallam JonathanHallam deleted the remove-jq-from-set-ga-client-id branch November 4, 2021 11:41
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.

3 participants