-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathuse-goals-first-experiment.ts
38 lines (31 loc) · 1.44 KB
/
use-goals-first-experiment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { isEnabled } from '@automattic/calypso-config';
import { setPlansListExperiment } from '@automattic/calypso-products';
import { ONBOARDING_FLOW } from '@automattic/onboarding';
import { useMemo } from 'react';
import { useExperiment } from 'calypso/lib/explat';
import { getFlowFromURL } from '../../utils/get-flow-from-url';
export const EXPERIMENT_NAME = 'calypso_signup_onboarding_goals_first_flow_holdout_20241220';
/**
* Check whether the user should have the "goals first" onboarding experience.
*
* Returns [ isLoading, isGoalsAtFrontExperiment ]
*/
export function useGoalsFirstExperiment(): [ boolean, boolean ] {
const flow = useMemo( () => getFlowFromURL(), [] );
const [ isLoading, experimentAssignment ] = useExperiment( EXPERIMENT_NAME, {
isEligible: flow === ONBOARDING_FLOW && ! isEnabled( 'onboarding/force-goals-first' ),
} );
if ( isEnabled( 'onboarding/force-goals-first' ) ) {
return [ false, true ];
}
/**
* If the user is not eligible, we'll treat them as if they were in the
* holdout/control group so we can provide the existing experience.
*
* This fallback is necessary because experimentAssignment returns null when the user
* is not eligible, and we're using this hook within steps that are used by other flows.
*/
const variationName = experimentAssignment?.variationName ?? 'control';
setPlansListExperiment( EXPERIMENT_NAME, variationName );
return [ isLoading, variationName === 'treatment' ];
}