File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 11import { getCookie , isUndefined } from '@guardian/libs' ;
2+ import { getForcedParticipationsFromUrlFlat } from '../lib/getAbUrlHash' ;
23
34const 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
Original file line number Diff line number Diff line change @@ -21,3 +21,28 @@ 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
30+ . replace ( '#ab-' , '' )
31+ . split ( ',' )
32+ . map ( ( token ) => token . replace ( / ^ a b - / , '' ) ) ;
33+ return tokens . reduce < Record < string , string > > ( ( obj , token ) => {
34+ const [ testId , variantId ] = token . split ( '=' ) ;
35+
36+ if ( testId && variantId ) {
37+ return {
38+ ...obj ,
39+ [ testId ] : variantId ,
40+ } ;
41+ }
42+
43+ return obj ;
44+ } , { } ) ;
45+ }
46+
47+ return { } ;
48+ } ;
You can’t perform that action at this time.
0 commit comments