From 825c4e6b92ac9b3c8053c927b87978575e249689 Mon Sep 17 00:00:00 2001 From: Anna Beddow Date: Tue, 7 May 2024 15:38:09 +0100 Subject: [PATCH] Add test variants to layouts --- .../src/layouts/CommentLayout.tsx | 172 +++++++++------- .../src/layouts/ImmersiveLayout.tsx | 176 ++++++++++------- .../src/layouts/InteractiveLayout.tsx | 172 +++++++++------- dotcom-rendering/src/layouts/LiveLayout.tsx | 184 ++++++++++-------- .../src/layouts/PictureLayout.tsx | 131 ++++++++----- .../src/layouts/ShowcaseLayout.tsx | 171 +++++++++------- .../src/layouts/StandardLayout.tsx | 176 ++++++++++------- 7 files changed, 692 insertions(+), 490 deletions(-) diff --git a/dotcom-rendering/src/layouts/CommentLayout.tsx b/dotcom-rendering/src/layouts/CommentLayout.tsx index a9f8ec425b4..db6f0757f2e 100644 --- a/dotcom-rendering/src/layouts/CommentLayout.tsx +++ b/dotcom-rendering/src/layouts/CommentLayout.tsx @@ -45,6 +45,7 @@ import { canRenderAds } from '../lib/canRenderAds'; import { getContributionsServiceUrl } from '../lib/contributions'; import { decideTrail } from '../lib/decideTrail'; import { parse } from '../lib/slot-machine-flags'; +import { useAB } from '../lib/useAB'; import type { NavType } from '../model/extract-nav'; import { palette as themePalette } from '../palette'; import type { DCRArticle } from '../types/frontend'; @@ -282,6 +283,25 @@ export const CommentLayout = (props: WebProps | AppsProps) => { config: { isPaidContent, host }, } = article; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + const showBodyEndSlot = isWeb && (parse(article.slotMachineFlags ?? '').showBodyEnd || @@ -799,49 +819,58 @@ export const CommentLayout = (props: WebProps | AppsProps) => { )} - {article.storyPackage && ( -
- - - -
- )} - - - - + {article.storyPackage && + (showOnwardsAllRows || showOnwardsTopRow) && ( +
+ + + +
+ )} + {(showOnwardsAllRows || showOnwardsBottomRow) && ( + + + + )} {showComments && (
{
)} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {renderAds && (
{ const isWeb = renderingTarget === 'Web'; const isApps = renderingTarget === 'Apps'; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + const showBodyEndSlot = isWeb && (parse(article.slotMachineFlags ?? '').showBodyEnd || @@ -820,51 +840,60 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
)} - {article.storyPackage && ( -
- - - -
- )} + + + + + )} - - - + {(showOnwardsAllRows || showOnwardsBottomRow) && ( + + + + )} {showComments && (
{ />
)} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {!isLabs && renderAds && (
{ editionId, } = article; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + const isApps = renderingTarget === 'Apps'; const isWeb = renderingTarget === 'Web'; @@ -733,50 +753,59 @@ export const InteractiveLayout = (props: WebProps | AppsProps) => {
)} - {article.storyPackage && ( -
- - - -
+ {article.storyPackage && + (showOnwardsAllRows || showOnwardsTopRow) && ( +
+ + + +
+ )} + {(showOnwardsAllRows || showOnwardsBottomRow) && ( + + + )} - - - - {showComments && (
{
)} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {renderAds && (
{ config: { isPaidContent, host }, } = article; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + // TODO: // 1) Read 'forceEpic' value from URL parameter and use it to force the slot to render // 2) Otherwise, ensure slot only renders if `article.config.shouldHideReaderRevenue` equals false. @@ -1212,56 +1232,59 @@ export const LiveLayout = (props: WebProps | AppsProps) => {
)} - {article.storyPackage && ( -
- - - -
+ + + + + )} + {(showOnwardsAllRows || showOnwardsBottomRow) && ( + + + )} - - - - - {showComments && (
{
)} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {renderAds && (
{ const isWeb = renderingTarget === 'Web'; const isApps = renderingTarget === 'Apps'; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + // TODO: // 1) Read 'forceEpic' value from URL parameter and use it to force the slot to render // 2) Otherwise, ensure slot only renders if `article.config.shouldHideReaderRevenue` equals false. @@ -683,30 +703,36 @@ export const PictureLayout = (props: WebProps | AppsProps) => {
)} - {article.storyPackage && ( -
- - - -
- )} + {article.storyPackage && + (showOnwardsAllRows || showOnwardsTopRow) && ( +
+ + + +
+ )} - {isWeb && ( + {isWeb && (showOnwardsAllRows || showOnwardsBottomRow) && ( { )} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {renderAds && (
{ const isWeb = renderingTarget === 'Web'; const isApps = renderingTarget === 'Apps'; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + const showBodyEndSlot = isWeb && (parse(article.slotMachineFlags ?? '').showBodyEnd || @@ -798,48 +818,58 @@ export const ShowcaseLayout = (props: WebProps | AppsProps) => {
)} - {article.storyPackage && ( -
- - - -
- )} + {article.storyPackage && + (showOnwardsAllRows || showOnwardsTopRow) && ( +
+ + + +
+ )} - - - + {(showOnwardsAllRows || showOnwardsBottomRow) && ( + + + + )} {showComments && (
{
)} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {renderAds && !isLabs && (
{ editionId, } = article; + const abTests = useAB(); + const abTestsApi = abTests?.api; + const showOnwardsAllRows = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'control', + ); + const showOnwardsTopRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-1', + ); + const showOnwardsBottomRow = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-2', + ); + const showOnwardsMostViewed = abTestsApi?.isUserInVariant( + 'OnwardJourneys', + 'variant-3', + ); + const isWeb = renderingTarget === 'Web'; const isApps = renderingTarget === 'Apps'; @@ -380,7 +400,6 @@ export const StandardLayout = (props: WebProps | AppProps) => { isWeb && (parse(article.slotMachineFlags ?? '').showBodyEnd || article.config.switches.slotBodyEnd); - // TODO: // 1) Read 'forceEpic' value from URL parameter and use it to force the slot to render // 2) Otherwise, ensure slot only renders if `article.config.shouldHideReaderRevenue` equals false. @@ -957,51 +976,59 @@ export const StandardLayout = (props: WebProps | AppProps) => {
)} - {article.storyPackage && ( -
- - - -
+ {article.storyPackage && + (showOnwardsAllRows || showOnwardsTopRow) && ( +
+ + + +
+ )} + {(showOnwardsAllRows || showOnwardsBottomRow) && ( + + + )} - - - - {showComments && (
{
)} - {!isPaidContent && ( -
- - - - - -
- )} + {!isPaidContent && + (showOnwardsAllRows || showOnwardsMostViewed) && ( +
+ + + + + +
+ )} {renderAds && !isLabs && (