From ab0fbbe552510fa5afdaacc14444868ff8126cc8 Mon Sep 17 00:00:00 2001 From: Ian James Date: Tue, 15 Jun 2021 14:50:13 +0100 Subject: [PATCH] Fixes and tweaks to RUM --- .../vendor/lux/lux-polyfill.js | 7 ++++++ .../vendor/lux/lux.js | 25 +++++++++++++------ docs/real-user-metrics.md | 6 +++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-polyfill.js b/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-polyfill.js index c09c60a31d..66be7f8290 100644 --- a/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-polyfill.js +++ b/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-polyfill.js @@ -1,5 +1,12 @@ /* eslint-disable */ +/* + * Part of Speedcurve's LUX script, which allows us to run real user metrics on + * pages using the public layout template. + * + * See docs/real-user-metrics.md for more information. + */ + LUX = (function () { var a = "undefined" !== typeof LUX && "undefined" !== typeof LUX.gaMarks diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux.js b/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux.js index 8dd91e5f7f..352d3ae622 100644 --- a/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux.js +++ b/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux.js @@ -1,13 +1,22 @@ /* eslint-disable */ -// ! Remember to keep the settings at the end of this file when updating LUX. -// -// The settings are: -// * `LUX.customerid = 47044334` to let LUX know who this is -// * `LUX.beaconMode = "simple"` to fire the beacon as an image, which is now -// allowed by the content security policy. -// * `LUX.debug = false` turns debugging on and off. Left set to false - and -// kept in the file so it's easier to remember that this can be turned on. +/* + * Part of Speedcurve's LUX script, which allows us to run real user metrics on + * pages using the public layout template. + * + * See docs/real-user-metrics.md for more information. + */ + + +/* ! Remember to keep the settings at the end of this file when updating LUX. + * + * The settings are: + * * `LUX.customerid = 47044334` to let LUX know who this is + * * `LUX.beaconMode = "simple"` to fire the beacon as an image, which is now + * allowed by the content security policy. + * * `LUX.debug = false` turns debugging on and off. Left set to false - and + * kept in the file so it's easier to remember that this can be turned on. + */ var LUX_t_start = Date.now(), LUX = window.LUX || {}; diff --git a/docs/real-user-metrics.md b/docs/real-user-metrics.md index 7d9bdd0b4e..31f5d34230 100644 --- a/docs/real-user-metrics.md +++ b/docs/real-user-metrics.md @@ -10,12 +10,14 @@ The LUX scripts should only be loaded when a user has opted into usage tracking. ## Custom changes when updating LUX -The scripts for the real user metrics are loaded from our servers - this allows us to know what is contained within the scripts and reduce the risk of unwelcome things being added to GOV.UK +The scripts for the real user metrics are loaded from our servers - this allows us to know what is contained within the scripts and reduce the risk of unwelcome things being added to GOV.UK. Because of this, the scripts are audited before being updated and then two extra lines are added to make sure it works correctly. These two lines set the customer ID and turn on beacon mode. ### Customer ID +The customer ID is an identifier for the site using LUX, not for the user visiting the site. It won't change from page to page, or from visitor to visitor. + When loading `lux.js` from Speedcurve's CDN, the customer ID is appended to the end of the URI as a query string. The script looks for a script in the DOM with a source of `lux.js`, and from that extracts the customer ID. Rails adds a fingerprint to the URI which means that `lux.js` becomes (for example) `lux.self-7137780d5344a93190a2c698cd660619d4197420b9b1ef963b639a825a6aa5ff.js` and the script can't find itself. @@ -55,6 +57,6 @@ LUX.getDebug() [LUX]: https://speedcurve.com/features/lux/ -[Public Layout component]: components.publishing.service.gov.uk/component-guide/layout_for_public +[Public Layout component]: https://components.publishing.service.gov.uk/component-guide/layout_for_public [csp-govuk-app-config]: https://github.com/alphagov/govuk_app_config/blob/87e445eccee5fba2449a170d5ba628e8a380fcb8/lib/govuk_app_config/govuk_content_security_policy.rb#L36-L38