|
1 | 1 | import type { ABTest, ABTestAPI } from '@guardian/ab-core'; |
| 2 | +import { ABTests } from '@guardian/ab-testing'; |
2 | 3 | import { |
3 | 4 | bypassCommercialMetricsSampling, |
4 | 5 | EventTimer, |
@@ -31,6 +32,15 @@ const clientSideTestsToForceMetrics: ABTest[] = [ |
31 | 32 | /* keep array multi-line */ |
32 | 33 | ]; |
33 | 34 |
|
| 35 | +const shouldCollectMetricsForBetaTests = (userTestParticipations: string[]) => { |
| 36 | + const userParticipationConfigs = ABTests.filter((test) => |
| 37 | + userTestParticipations.includes(test.name), |
| 38 | + ); |
| 39 | + return userParticipationConfigs.some( |
| 40 | + (test) => test.shouldForceMetricsCollection, |
| 41 | + ); |
| 42 | +}; |
| 43 | + |
34 | 44 | const useBrowserId = () => { |
35 | 45 | const [browserId, setBrowserId] = useState<string>(); |
36 | 46 |
|
@@ -89,20 +99,22 @@ export const Metrics = ({ commercialMetricsEnabled, tests }: Props) => { |
89 | 99 |
|
90 | 100 | const userInServerSideTest = Object.keys(tests).length > 0; |
91 | 101 |
|
92 | | - const betaParticipations = betaABTest?.getParticipations() ?? {}; |
| 102 | + const userBetaParticipations = betaABTest?.getParticipations() ?? {}; |
93 | 103 |
|
94 | | - const userInBetaABTest = Object.keys(betaParticipations).length > 0; |
| 104 | + const collectBetaTestMetrics = shouldCollectMetricsForBetaTests( |
| 105 | + Object.keys(userBetaParticipations), |
| 106 | + ); |
95 | 107 |
|
96 | 108 | const shouldBypassSampling = useCallback( |
97 | 109 | (api: ABTestAPI) => |
98 | 110 | willRecordCoreWebVitals || |
99 | 111 | userInServerSideTest || |
100 | | - userInBetaABTest || |
| 112 | + collectBetaTestMetrics || |
101 | 113 | clientSideTestsToForceMetrics.some((test) => |
102 | 114 | api.runnableTest(test), |
103 | 115 | ), |
104 | 116 |
|
105 | | - [userInServerSideTest, userInBetaABTest], |
| 117 | + [userInServerSideTest, collectBetaTestMetrics], |
106 | 118 | ); |
107 | 119 |
|
108 | 120 | useEffect( |
|
0 commit comments