Skip to content

Commit f2a97cf

Browse files
committed
add force particiaptions to AB test participations
1 parent 8b0d402 commit f2a97cf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

dotcom-rendering/src/client/abTesting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getCookie, isUndefined } from '@guardian/libs';
2+
import { getForcedParticipationsFromUrlFlat } from '../lib/getAbUrlHash';
23

34
const AB_COOKIE_NAME = 'gu_client_ab_tests';
45

@@ -37,6 +38,7 @@ const getABTestParticipations = (): ABParticipations => {
3738
return {
3839
...getClientParticipations(),
3940
...window.guardian.config.serverSideABTests,
41+
...getForcedParticipationsFromUrlFlat(window.location.hash),
4042
};
4143
};
4244

dotcom-rendering/src/lib/getAbUrlHash.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ export const getForcedParticipationsFromUrl = (
2121

2222
return {};
2323
};
24+
25+
export const getForcedParticipationsFromUrlFlat = (
26+
windowHash: string,
27+
): Record<string, string> => {
28+
if (windowHash.startsWith('#ab')) {
29+
const tokens = windowHash.replace('#ab-', '').split(',');
30+
return tokens.reduce<Record<string, string>>((obj, token) => {
31+
const [testId, variantId] = token.split('=');
32+
33+
if (testId && variantId) {
34+
return {
35+
...obj,
36+
[testId]: variantId,
37+
};
38+
}
39+
40+
return obj;
41+
}, {});
42+
}
43+
44+
return {};
45+
};

0 commit comments

Comments
 (0)