-
Notifications
You must be signed in to change notification settings - Fork 31
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
Use user benefits abtest #13137
Use user benefits abtest #13137
Changes from all commits
1a20e2f
f4e1bcc
c37f387
a289295
ec47ce5
0eebfa5
eef201d
f1d1b29
c277b82
cdc8ed6
c34fc4b
549714f
9709c95
9bf3269
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { isObject } from '@guardian/libs'; | ||
import { | ||
getOptionsHeadersWithOkta, | ||
type SignedInWithCookies, | ||
type SignedInWithOkta, | ||
} from '../../lib/identity'; | ||
import { fetchJson } from './fetchJson'; | ||
import type { UserBenefits } from './user-features'; | ||
|
||
type UserBenefitsResponse = { | ||
benefits: string[]; | ||
}; | ||
export const syncDataFromUserBenefitsApi = async ( | ||
signedInAuthStatus: SignedInWithOkta | SignedInWithCookies, | ||
): Promise<UserBenefits> => { | ||
const url = window.guardian.config.page.userBenefitsApiUrl; | ||
if (!url) { | ||
throw new Error('userBenefitsApiUrl is not defined'); | ||
} | ||
const response = await fetchJson(url, { | ||
mode: 'cors', | ||
...getOptionsHeadersWithOkta(signedInAuthStatus), | ||
}); | ||
if (!validateResponse(response)) { | ||
throw new Error('invalid response'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. presumably that will throw an alarm somewhere for us/sentry? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess? Not sure, this is the same as the previous implementation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true I guess the more pertinent question is how will you know that everything is working with the new API like it was before across a similar percentage of browsers |
||
} | ||
return { | ||
hideSupportMessaging: response.benefits.includes( | ||
'hideSupportMessaging', | ||
), | ||
adFree: response.benefits.includes('adFree'), | ||
}; | ||
}; | ||
|
||
const validateResponse = ( | ||
response: unknown, | ||
): response is UserBenefitsResponse => { | ||
return isObject(response) && Array.isArray(response.benefits); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { ABTest } from '@guardian/ab-core'; | ||
|
||
export const userBenefitsApi: ABTest = { | ||
id: 'UserBenefitsApi', | ||
start: '2020-05-20', | ||
expiry: '2025-12-01', | ||
author: 'Rupert Bates', | ||
description: | ||
'This test is being used to roll out the user benefits API in a gradual manner', | ||
audience: 2 / 100, // 2% | ||
audienceOffset: 0, | ||
successMeasure: | ||
'There are no new client side errors and the user benefits API copes with the load', | ||
audienceCriteria: 'Everyone', | ||
showForSensitive: true, | ||
canRun: () => true, | ||
variants: [ | ||
{ | ||
id: 'control', | ||
test: (): void => { | ||
/* no-op */ | ||
}, | ||
}, | ||
{ | ||
id: 'variant', | ||
test: (): void => { | ||
/* no-op */ | ||
}, | ||
}, | ||
], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is neat that both methods return value of the same shape (so can use
persistResponse
in both cases).