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

Set LUX sampling to 1% #2145

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
- Don't include changes that are purely internal. The CHANGELOG should be a
useful summary for people upgrading their application, not a replication
of the commit log.


## Unreleased

* Set LUX's sampling rate to 1% ([PR 2145](https://github.com/alphagov/govuk_publishing_components/pull/2145))

## 24.14.1

* Fix wrong label value for event tracking on menu button ([PR #2139](https://github.com/alphagov/govuk_publishing_components/pull/2139))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@
*/


/* ! Remember to keep the settings at the end of this file when updating LUX.
/* ! Remember to keep these 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.
*
* ! And the sample rate needs to be set inside the main function that's
* assigned to `LUX`:

* * `LUX.samplerate = 1` to set sample rate to 1% of users.
*/

var LUX_t_start = Date.now(),
LUX = window.LUX || {};
LUX = function() {
// -------------------------------------------------------------------------
// Settings
// -------------------------------------------------------------------------
// Set the sample rate to 1% to avoid all events being sent.
LUX.samplerate = 1
// -------------------------------------------------------------------------
/// End
// -------------------------------------------------------------------------

var gaLog = [];
dlog("lux.js evaluation start.");
var version = "214",
Expand Down Expand Up @@ -829,6 +842,10 @@ LUX = function() {
}();
var LUX_t_end = Date.now();

// -----------------------------------------------------------------------------
// 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.
Expand All @@ -842,3 +859,10 @@ LUX.beaconMode = "simple";
// `LUX.getDebug()` in the browser's console will show the history of what's
// happened.
LUX.debug = false;

// Forces sampling - useful for when used with `debug = true`
// LUX.forceSample()

// -----------------------------------------------------------------------------
// End of more settings
// -----------------------------------------------------------------------------
20 changes: 19 additions & 1 deletion docs/real-user-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ Setting the beacon mode to `"simple"` turns the non-default image method on:
LUX.beaconMode = 'simple'
```

### Debug (bonus mode)
### Sample rate

LUX defaults to sending every event to Speedcurve - this can be changed by setting `LUX.samplerate` to a integer:

```javascript
LUX.samplerate = 1 // Whole number from 1 to 100.
```

This then only sends 1% of visits.

**This must be set at the top of the main `LUX` function or it will default to 100% sample rate.**

### Debugging (bonus mode)

```javascript
LUX.debug = true
Expand All @@ -53,6 +65,12 @@ Usefully, running `LUX.getDebug()` in the browser's console will show the histor
LUX.getDebug()
```

Sampling can also be forced by placing `LUX.forceSample()` at the end of the file:

```javascript
LUX.forceSample()
```

[Performance API]: https://developer.mozilla.org/en-US/docs/Web/API/Performance_API

[LUX]: https://speedcurve.com/features/lux/
Expand Down