Skip to content

Commit ba9224f

Browse files
committed
bypass metrics sample rate for beta tests
1 parent 7de546b commit ba9224f

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

dotcom-rendering/src/components/Metrics.importable.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@guardian/core-web-vitals';
1111
import { getCookie, isString, isUndefined } from '@guardian/libs';
1212
import { useCallback, useEffect, useState } from 'react';
13-
import { useAB } from '../lib/useAB';
13+
import { useAB, useBetaAB } from '../lib/useAB';
1414
import { useAdBlockInUse } from '../lib/useAdBlockInUse';
1515
import { useDetectAdBlock } from '../lib/useDetectAdBlock';
1616
import { usePageViewId } from '../lib/usePageViewId';
@@ -77,6 +77,7 @@ const useDev = () => {
7777
*/
7878
export const Metrics = ({ commercialMetricsEnabled, tests }: Props) => {
7979
const abTestApi = useAB()?.api;
80+
const betaABTest = useBetaAB();
8081
const adBlockerInUse = useAdBlockInUse();
8182
const detectedAdBlocker = useDetectAdBlock();
8283

@@ -88,14 +89,20 @@ export const Metrics = ({ commercialMetricsEnabled, tests }: Props) => {
8889

8990
const userInServerSideTest = Object.keys(tests).length > 0;
9091

92+
const betaParticipations = betaABTest?.getParticipations() ?? {};
93+
94+
const userInBetaABTest = Object.keys(betaParticipations).length > 0;
95+
9196
const shouldBypassSampling = useCallback(
9297
(api: ABTestAPI) =>
9398
willRecordCoreWebVitals ||
9499
userInServerSideTest ||
100+
userInBetaABTest ||
95101
clientSideTestsToForceMetrics.some((test) =>
96102
api.runnableTest(test),
97103
),
98-
[userInServerSideTest],
104+
105+
[userInServerSideTest, userInBetaABTest],
99106
);
100107

101108
useEffect(

dotcom-rendering/src/experiments/lib/beta-ab-tests.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { isUndefined } from '@guardian/libs';
12
import { isServer } from '../../lib/isServer';
23

34
export interface BetaABTestAPI {
4-
isUserInTest: (testId: string, variantId: string) => boolean;
5+
getParticipations: () => ABParticipations;
6+
isUserInTest: (testId: string) => boolean;
7+
isUserInTestGroup: (testId: string, groupId: string) => boolean;
58
trackABTests: (
69
ophanRecord: OphanRecordFunction,
710
errorReporter: ErrorReporter,
@@ -52,8 +55,16 @@ export class BetaABTests implements BetaABTestAPI {
5255
}
5356
}
5457

55-
isUserInTest(testId: string, variantId: string): boolean {
56-
return this.participations[testId] === variantId;
58+
getParticipations(): ABParticipations {
59+
return this.participations;
60+
}
61+
62+
isUserInTest(testId: string): boolean {
63+
return !isUndefined(this.participations[testId]);
64+
}
65+
66+
isUserInTestGroup(testId: string, groupId: string): boolean {
67+
return this.participations[testId] === groupId;
5768
}
5869

5970
trackABTests(

0 commit comments

Comments
 (0)