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

Update LUX to activate when usage cookies are accepted #2154

Merged
merged 1 commit into from
Jul 5, 2021

Conversation

injms
Copy link
Contributor

@injms injms commented Jun 21, 2021

What

Updates LUX loading strategy to measure (but not report) the page experience of users that haven't yet accepted cookies.

LUX sets a cookie so that users metrics can be seen from page to page - this requires LUX to set a cookie. To ensure that this wasn't tracking users that opted out, both the LUX JavaScript "snippet" and the reporting JavaScript were loaded on the page after a user had accepted cookies.

The LUX snippet is loaded as a JavaScript file as GOV.UK content security policy doesn't allow inline JavaScript. This is loaded first, and measures the user's experience - and then does nothing else.

The rum-loader.js checks a users preferences, and will only load lux-reporter.js if a user has opted in. If either the cookie-consent event has been fired or the usage tracking cookie was set, the lux-reporter.js script is loaded.

The lux-reporter.js script then sends the measurements off to be analysed; since this JavaScript sets cookies, this file is only loaded if a user has allowed usage cookies.

Other changes worth noting:

  • LUX "snippet" is in the lux-measurer.js file
  • The self hosted lux.js (usually loaded from Speedcurve's CDN) is in the lux-reporter.js file
  • Tests added and updated to check for reporting when a user has clicked on the cookie banner

Will help with alphagov/static#2516

Why

This change ensures that the user's privacy preferences are respected and the crucial first page load on a cold cache can be accurately reported.

Visual Changes

None

@bevanloon bevanloon temporarily deployed to govuk-publis-update-lux-9azaby June 21, 2021 15:14 Inactive
@injms injms marked this pull request as ready for review June 21, 2021 15:27
Copy link
Contributor

@alex-ju alex-ju left a comment

Choose a reason for hiding this comment

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

Excellent work on this, Ian!

if (parsedCookie.usage === true) {
insertScript(scriptSrc)
} else {
window.addEventListener('cookie-consent', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@alex-ju alex-ju mentioned this pull request Jun 22, 2021
@bevanloon bevanloon temporarily deployed to govuk-publis-update-lux-9azaby June 22, 2021 14:54 Inactive
@bevanloon bevanloon temporarily deployed to govuk-publis-update-lux-9azaby June 22, 2021 14:57 Inactive
@injms injms force-pushed the update-lux-loading-strategy branch 2 times, most recently from 88e654a to bc60c6f Compare July 5, 2021 13:08
Previously LUX was only fired on pages once usage tracking cookies had
been accepted - this updates the set up to measure as soon as the page
loads, but only sends that information once a user has accepted usage
tracking cookies[1]. Information is sent when the event `cookie-consent`
is fired, or when the usage cookie has been set to true.

The LUX JavaScript files have been renamed to make it a bit clearer what
each particular script does.

[1]: https://support.speedcurve.com/en/articles/4468508-using-lux-with-cookie-consent-banners
@injms injms force-pushed the update-lux-loading-strategy branch from 5ca8dd3 to e5eef0b Compare July 5, 2021 13:30
@injms injms merged commit 4983561 into master Jul 5, 2021
@injms injms deleted the update-lux-loading-strategy branch July 5, 2021 13:38
injms added a commit that referenced this pull request Jul 5, 2021
Includes:

 * Update LUX to activate when usage cookies are accepted (#2154)
@injms injms mentioned this pull request Jul 5, 2021
injms added a commit that referenced this pull request Jul 5, 2021
Includes:

 * Update LUX to activate when usage cookies are accepted (#2154)
 * Add custom dimension to segment page views by Brexit audience type (#2186)
injms added a commit to alphagov/static that referenced this pull request Jul 5, 2021
This updates the `core_layout` template to match the updates made in the
component gem[1], which also needed to be updated at the same time.

[1]: alphagov/govuk_publishing_components#2154
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