diff --git a/CHANGELOG.md b/CHANGELOG.md index b29632758e..a7c78a82f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ## Unreleased +* Fix error in LUX script ([PR #3592](https://github.com/alphagov/govuk_publishing_components/pull/3592)) * Prepend page path when tracking anchor links in GA4 ([PR #3590](https://github.com/alphagov/govuk_publishing_components/pull/3590)) ## 35.15.1 diff --git a/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js b/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js index 7914928dd8..ef95c59f85 100644 --- a/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +++ b/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js @@ -538,6 +538,10 @@ // ------------------------------------------------------------------------- // Settings // ------------------------------------------------------------------------- + // This ID usually appended to the end of the lux.js as a query string when + // using the SpeedCurve hosted version - but we have to include it here as + // this is self hosted. + LUX.customerid = 47044334; // Set the sample rate to 1% to avoid all events being sent. LUX.samplerate = 1; // ------------------------------------------------------------------------- @@ -1494,10 +1498,9 @@ } return getHighPercentileINP(); } + // function simplified for our use, original would get the customerid from the script src URL + // but we set it inside the code in this file, so this function just returns that function getCustomerId() { - if (!LUX.customerid) { - LUX.customerid = thisScript.src.match(/id=(\d+)/).pop(); - } return LUX.customerid || ""; } function avgDomDepth() { @@ -2200,11 +2203,6 @@ // More settings // --------------------------------------------------------------------------- // - // This ID usually appended to the end of the lux.js as a query string when - // using the SpeedCurve hosted version - but we have to include it here as - // this is self hosted. - LUX.customerid = 47044334; - // Setting debug to `true` shows what happening as it happens. Running // `LUX.getDebug()` in the browser's console will show the history of what's // happened. diff --git a/docs/real-user-metrics.md b/docs/real-user-metrics.md index a9f0ef1c9a..ee3bee47f2 100644 --- a/docs/real-user-metrics.md +++ b/docs/real-user-metrics.md @@ -28,9 +28,9 @@ The customer ID is an identifier for the site using LUX, not for the user visiti 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. +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. Because of this that part of the script would fail. Instead, we modify the `getCustomerId()` function to simply return `LUX.customerid`. -Because of this the customer ID needs to be set at the end of the `lux.js` file: +Because of this the customer ID needs to be set in the `lux.js` file: ```javascript LUX.customerid = 47044334