-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
240 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { IsoCountry } from '../internationalisation/country'; | ||
import type { CountryGroupId } from '../internationalisation/countryGroup'; | ||
|
||
export const breakpoints = { | ||
mobile: 320, | ||
mobileMedium: 375, | ||
mobileLandscape: 480, | ||
phablet: 660, | ||
tablet: 740, | ||
desktop: 980, | ||
leftCol: 1140, | ||
wide: 1300, | ||
}; | ||
|
||
type Breakpoint = keyof typeof breakpoints; | ||
|
||
type BreakpointRange = { | ||
minWidth?: Breakpoint; | ||
maxWidth?: Breakpoint; | ||
}; | ||
|
||
export type Audience = { | ||
offset: number; | ||
size: number; | ||
breakpoint?: BreakpointRange; | ||
}; | ||
|
||
type AudienceType = IsoCountry | CountryGroupId | 'ALL' | 'CONTRIBUTIONS_ONLY'; | ||
|
||
type Audiences = { | ||
[key in AudienceType]?: Audience; | ||
}; | ||
|
||
export type AcquisitionABTest = { | ||
name: string; | ||
variant: string; | ||
testType?: string; | ||
}; | ||
|
||
export type Variant = { | ||
id: string; | ||
}; | ||
|
||
export type Test = { | ||
variants: Variant[]; | ||
audiences: Audiences; | ||
isActive: boolean; | ||
canRun?: () => boolean; | ||
// Indicates whether the A/B test is controlled by the referrer (acquisition channel) | ||
// e.g. Test of a banner design change on dotcom | ||
// If true the A/B test participation info should be passed through in the acquisition data | ||
// query parameter. | ||
// In particular this allows 3rd party tests to be identified and tracked in support-frontend | ||
// without too much "magic" involving the shared mvtId. | ||
referrerControlled: boolean; | ||
// If another test participation is referrerControlled, exclude this test | ||
excludeIfInReferrerControlledTest?: boolean; | ||
seed: number; | ||
// An optional regex that will be tested against the path of the current page | ||
// before activating this test eg. '/(uk|us|au|ca|nz)/subscribe$' | ||
targetPage?: string | RegExp; | ||
// Persist this test participation across more pages using this regex | ||
persistPage?: string | RegExp; | ||
omitCountries?: IsoCountry[]; | ||
// Some users will see a version of the checkout that only offers | ||
// the option to make contributions. We won't want to include these | ||
// users in some AB tests | ||
excludeContributionsOnlyCountries: boolean; | ||
}; | ||
|
||
export type Tests = Record<string, Test>; | ||
|
||
export type Participations = Record<string, string | undefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as storage from '../storage/storage'; | ||
import type { Participations } from './models'; | ||
|
||
function getParticipationsFromSession( | ||
key: string = 'abParticipations', | ||
): Participations | undefined { | ||
const participations = storage.getSession(key); | ||
if (participations) { | ||
try { | ||
return JSON.parse(participations) as Participations; | ||
} catch (error) { | ||
console.error( | ||
'Failed to parse abParticipations from session storage', | ||
error, | ||
); | ||
return undefined; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
const landingPageParticipationsKey = 'landingPageParticipations'; | ||
function getLandingPageParticipationsFromSession(): Participations | undefined { | ||
return getParticipationsFromSession(landingPageParticipationsKey); | ||
} | ||
|
||
function setLandingPageParticipations(participations: Participations) { | ||
storage.setSession( | ||
landingPageParticipationsKey, | ||
JSON.stringify(participations), | ||
); | ||
} | ||
|
||
export { | ||
getParticipationsFromSession, | ||
getLandingPageParticipationsFromSession, | ||
setLandingPageParticipations, | ||
}; |
Oops, something went wrong.