Skip to content
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

WSTEAM1-1312 Run an Optimizely AA Test #12017

Merged
merged 11 commits into from
Oct 1, 2024
3 changes: 3 additions & 0 deletions src/app/legacy/components/ScrollablePromo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { GridItemMediumNoMargin } from '#components/Grid';
import useViewTracker from '#hooks/useViewTracker';
import useClickTrackerHandler from '#hooks/useClickTrackerHandler';
import idSanitiser from '#lib/utilities/idSanitiser';
import { OptimizelyContext } from '@optimizely/react-sdk';
import { ServiceContext } from '../../../contexts/ServiceContext';
import Promo from './Promo';
import PromoList from './PromoList';
Expand Down Expand Up @@ -59,10 +60,12 @@ const LabelComponent = styled.strong`

const ScrollablePromo = ({ blocks, blockGroupIndex = null }) => {
const { script, service, dir, translations } = useContext(ServiceContext);
const { optimizely } = useContext(OptimizelyContext);

const eventTrackingData = {
componentName: `edoj${blockGroupIndex}`,
format: 'CHD=edoj',
optimizely,
};

const viewRef = useViewTracker(eventTrackingData);
Expand Down
6 changes: 6 additions & 0 deletions src/app/legacy/components/ScrollablePromo/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('ScrollablePromo', () => {
expect(viewTrackerSpy).toHaveBeenCalledWith({
componentName: 'edoj1',
format: 'CHD=edoj',
optimizely: null,
});
});

Expand All @@ -94,10 +95,12 @@ describe('ScrollablePromo', () => {
expect(viewTrackerSpy).toHaveBeenCalledWith({
componentName: 'edoj1',
format: 'CHD=edoj',
optimizely: null,
});
expect(viewTrackerSpy).toHaveBeenCalledWith({
componentName: 'edoj2',
format: 'CHD=edoj',
optimizely: null,
});
});

Expand All @@ -110,6 +113,7 @@ describe('ScrollablePromo', () => {
expect(clickTrackerSpy).toHaveBeenCalledWith({
componentName: 'edoj1',
format: 'CHD=edoj',
optimizely: null,
});
});

Expand All @@ -126,10 +130,12 @@ describe('ScrollablePromo', () => {
expect(clickTrackerSpy).toHaveBeenCalledWith({
componentName: 'edoj1',
format: 'CHD=edoj',
optimizely: null,
});
expect(clickTrackerSpy).toHaveBeenCalledWith({
componentName: 'edoj2',
format: 'CHD=edoj',
optimizely: null,
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/config/optimizely/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
flagId: 'ws_test_flag',
flagId: 'scrollable_promo',
viewClickAttributeId: 'wsoj',
variationMappings: {
on: 'on',
Expand Down
20 changes: 18 additions & 2 deletions src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import CpsRecommendations from '#containers/CpsRecommendations';
import InlinePodcastPromo from '#containers/PodcastPromo/Inline';
import { Article, OptimoBylineBlock } from '#app/models/types/optimo';

import useOptimizelyVariation from '#app/hooks/useOptimizelyVariation';
import OptimizelyArticleCompleteTracking from '#app/legacy/containers/OptimizelyArticleCompleteTracking';
import OptimizelyPageViewTracking from '#app/legacy/containers/OptimizelyPageViewTracking';
import useOptimizelyScrollDepth from '#app/hooks/useOptimizelyScrollDepth';
import ImageWithCaption from '../../components/ImageWithCaption';
import AdContainer from '../../components/Ad';
import EmbedImages from '../../components/Embeds/EmbedImages';
Expand Down Expand Up @@ -133,6 +137,10 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
...(isCPS && { pageTitle: `${atiAnalytics.pageTitle} - ${brandName}` }),
};

const scrollablePromoVariation = useOptimizelyVariation(
'scrollable_promo',
) as unknown as string;
emilysaffron marked this conversation as resolved.
Show resolved Hide resolved

const componentsToRender = {
visuallyHiddenHeadline,
headline: headings,
Expand Down Expand Up @@ -166,7 +174,12 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
embedImages: EmbedImages,
embedUploader: Uploader,
group: gist,
links: (props: ComponentToRenderProps) => <ScrollablePromo {...props} />,
links: (props: ComponentToRenderProps) =>
scrollablePromoVariation === 'variation_1_aa' ? (
<ScrollablePromo {...props} />
) : (
<ScrollablePromo {...props} />
),
karinathomasbbc marked this conversation as resolved.
Show resolved Hide resolved
mpu: (props: ComponentToRenderProps) =>
allowAdvertising ? <AdContainer {...props} slotType="mpu" /> : null,
wsoj: (props: ComponentToRenderProps) => (
Expand Down Expand Up @@ -197,7 +210,6 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
);

const promoImageRawBlock = filterForBlockType(promoImageBlocks, 'rawImage');

const promoImageAltText =
promoImageAltTextBlock?.model?.blocks?.[0]?.model?.blocks?.[0]?.model?.text;

Expand All @@ -207,6 +219,8 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
showRelatedTopics && topics.length > 0 && !isTransliterated,
);

useOptimizelyScrollDepth();

return (
<div css={styles.pageWrapper}>
<ATIAnalytics atiData={atiData} />
Expand Down Expand Up @@ -282,6 +296,8 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
mobileDivider={showTopics}
/>
)}
<OptimizelyArticleCompleteTracking />
<OptimizelyPageViewTracking />
</div>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/app/pages/ArticlePage/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ jest.mock('#app/legacy/containers/OptimizelyArticleCompleteTracking');
jest.mock('#app/legacy/containers/OptimizelyPageViewTracking');
jest.mock('#app/hooks/useOptimizelyScrollDepth');

jest.mock('#app/hooks/useOptimizelyVariation', () => ({
__esModule: true,
default: jest.fn(),
}));

const input = {
bbcOrigin: 'https://www.test.bbc.co.uk',
id: 'c0000000000o',
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/ArticlePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import withOptimizelyProvider from '#app/legacy/containers/PageHandlers/withOpti
import ArticlePage from './ArticlePage';
import applyBasicPageHandlers from '../utils/applyBasicPageHandlers';

const ArticleWithOptimizely = withOptimizelyProvider(ArticlePage);
const OptimizelyArticle = withOptimizelyProvider(ArticlePage);

export default applyBasicPageHandlers(ArticleWithOptimizely);
export default applyBasicPageHandlers(OptimizelyArticle);
14 changes: 0 additions & 14 deletions src/app/routes/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ import {
import { suppressPropWarnings } from '../legacy/psammead/psammead-test-helpers/src';
import * as fetchDataFromBFF from './utils/fetchDataFromBFF';

jest.mock('@optimizely/react-sdk', () => {
return {
setLogger: jest.fn(),
OptimizelyExperiment: jest.fn(),
createInstance: jest.fn(),
useDecision: jest.fn(),
OptimizelyProvider: ({ children }) => children,
};
});

jest.mock('#app/legacy/containers/OptimizelyArticleCompleteTracking');
jest.mock('#app/legacy/containers/OptimizelyPageViewTracking');
jest.mock('#app/hooks/useOptimizelyScrollDepth');

global.performance.getEntriesByName = jest.fn(() => []);

// mock pages/index.js to return a non async page component
Expand Down
Loading