Skip to content

Commit 94fe4e4

Browse files
authored
Add AB test for L2A button in Apps Article (#14343)
* WIP set up l2a ab test * Add bridget mock for nativeAbTestingClient * Update bridget * Set up l2a_article_button_test for ListenToArticle * Tidy up
1 parent e6783cf commit 94fe4e4

File tree

5 files changed

+78
-33
lines changed

5 files changed

+78
-33
lines changed

dotcom-rendering/.storybook/mocks/bridgetApi.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ export const getListenToArticleClient: BridgetApi<
102102
isAvailable: async () => true,
103103
isPlaying: async () => false,
104104
});
105+
106+
export const getNativeABTestingClient: BridgetApi<
107+
'getNativeABTestingClient'
108+
> = () => ({
109+
getParticipations: async () =>
110+
new Map(Object.entries({ 'test-id': 'variant' })),
111+
});
112+
105113
export const ensure_all_exports_are_present = {
106114
getUserClient,
107115
getAcquisitionsClient,
@@ -119,6 +127,7 @@ export const ensure_all_exports_are_present = {
119127
getInteractionClient,
120128
getInteractivesClient,
121129
getListenToArticleClient,
130+
getNativeABTestingClient,
122131
} satisfies {
123132
[Method in keyof BridgeModule]: BridgetApi<Method>;
124133
};

dotcom-rendering/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@emotion/server": "11.11.0",
2929
"@guardian/ab-core": "8.0.0",
3030
"@guardian/braze-components": "22.2.0",
31-
"@guardian/bridget": "8.6.0",
31+
"@guardian/bridget": "8.7.0",
3232
"@guardian/browserslist-config": "6.1.0",
3333
"@guardian/cdk": "61.4.0",
3434
"@guardian/commercial-core": "27.1.0",

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { log } from '@guardian/libs';
22
import { useEffect, useState } from 'react';
3-
import { getListenToArticleClient } from '../lib/bridgetApi';
3+
import {
4+
getListenToArticleClient,
5+
getNativeABTestingClient,
6+
} from '../lib/bridgetApi';
47
import { useIsBridgetCompatible } from '../lib/useIsBridgetCompatible';
58
import { ListenToArticleButton } from './ListenToArticleButton';
69

@@ -30,23 +33,43 @@ export const ListenToArticle = ({ articleId }: Props) => {
3033
number | undefined
3134
>(undefined);
3235

33-
const isBridgetCompatible = useIsBridgetCompatible('8.6.0');
36+
const isBridgetCompatible = useIsBridgetCompatible('8.7.0');
3437
useEffect(() => {
3538
if (isBridgetCompatible) {
3639
Promise.all([
40+
// AB TESTING native
41+
getNativeABTestingClient().getParticipations(),
3742
getListenToArticleClient().isAvailable(articleId),
3843
getListenToArticleClient().isPlaying(articleId),
3944
getListenToArticleClient().getAudioDurationSeconds(articleId),
4045
])
41-
.then(([isAvailable, isPlaying, durationSeconds]) => {
42-
setAudioDurationSeconds(
43-
typeof durationSeconds === 'number' &&
44-
durationSeconds > 0
45-
? durationSeconds
46-
: undefined,
47-
);
48-
setShowButton(isAvailable && !isPlaying);
49-
})
46+
.then(
47+
([
48+
abParticipations,
49+
isAvailable,
50+
isPlaying,
51+
durationSeconds,
52+
]) => {
53+
// AB TESTING native start
54+
const variant = abParticipations.get(
55+
'l2a_article_button_test',
56+
);
57+
if (variant === 'no-button') {
58+
setShowButton(false);
59+
} else if (variant === 'with-duration') {
60+
setAudioDurationSeconds(
61+
typeof durationSeconds === 'number' &&
62+
durationSeconds > 0
63+
? durationSeconds
64+
: undefined,
65+
);
66+
setShowButton(isAvailable && !isPlaying);
67+
} else if (variant === 'without-duration') {
68+
setShowButton(isAvailable && !isPlaying);
69+
}
70+
// AB TESTING native ends
71+
},
72+
)
5073
.catch((error) => {
5174
console.error(
5275
'Error fetching article audio status: ',

dotcom-rendering/src/lib/bridgetApi.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as AbTesting from '@guardian/bridget/AbTesting';
12
import * as Acquisitions from '@guardian/bridget/Acquisitions';
23
import * as Analytics from '@guardian/bridget/Analytics';
34
import * as Commercial from '@guardian/bridget/Commercial';
@@ -204,3 +205,15 @@ export const getListenToArticleClient = (): ListenToArticle.Client<void> => {
204205
}
205206
return listenToArticleClient;
206207
};
208+
209+
let nativeAbTestingClient: AbTesting.Client<void> | undefined = undefined;
210+
export const getNativeABTestingClient = (): AbTesting.Client<void> => {
211+
if (!nativeAbTestingClient) {
212+
nativeAbTestingClient = createAppClient<AbTesting.Client<void>>(
213+
AbTesting.Client,
214+
'buffered',
215+
'compact',
216+
);
217+
}
218+
return nativeAbTestingClient;
219+
};

pnpm-lock.yaml

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)