Skip to content

Commit dff7ae3

Browse files
committed
[FEATURE] Set A/B testing cookie via JavaScript only with consent
LUX Enterprise adds the selected variant as data-lux-abtestingvariant to the HTML instead of sending a cookie from the server. LUX JavaScript now sets the session cookie LUXABTEST only if tracking is active (opt-in or autoenable), as required by § 25 TDDDG. Refs: #84039
1 parent 4b21337 commit dff7ae3

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎Documentation/Technical/Campaigns/AbTesting.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ Buttons allows you to change to edit view of a page or to pageoverview module wi
6060

6161
##### Technical notes
6262

63+
###### Cookie and consent
64+
65+
The selected variant is stored in a session cookie with name `LUXABTEST` (value `A`, `B`, etc.) to show the same
66+
variant on further page visits. This cookie is set by LUX JavaScript only if tracking is active (autoenable or opt-in).
67+
Without consent, a variant is shown, but no cookie is set - so a visitor could see another variant on the next page
68+
visit.
69+
6370
###### Enforce a variant
6471

6572
You can simply add a new (or rename an existing) cookie with name `LUXABTEST` and set the value to `A` or `B` etc.

‎Resources/Private/Build/JavaScript/Frontend/Lux.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ function LuxMain() {
636636
addLinkListenerListener();
637637
addRedirectListener();
638638
addAbTestingListener();
639+
setAbTestingCookie();
639640
} else {
640641
trackIteration++;
641642
if (trackIteration < 200) {
@@ -843,6 +844,21 @@ function LuxMain() {
843844
}
844845
};
845846

847+
/**
848+
* Remember the A/B testing variant in a session cookie (only called with an active tracking/consent)
849+
*
850+
* @returns {void}
851+
*/
852+
var setAbTestingCookie = function() {
853+
var abTestingContainer = document.querySelector('[data-lux-abtestingvariant]');
854+
if (abTestingContainer !== null && document.cookie.split('; ').some(function(cookie) {
855+
return cookie.indexOf('LUXABTEST=') === 0;
856+
}) === false) {
857+
document.cookie = 'LUXABTEST=' + abTestingContainer.getAttribute('data-lux-abtestingvariant')
858+
+ '; path=/; SameSite=Strict';
859+
}
860+
};
861+
846862
/**
847863
* Delay a click to a link to give AJAX some time to do a bit magic
848864
*

‎Resources/Public/JavaScript/Lux/Lux.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Resources/Public/JavaScript/Lux/modern/chunks/Lux.mjs‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)