Skip to content

Commit

Permalink
Merge pull request #12219 from bbc/nasaa-amp-experiment-stop-experiment
Browse files Browse the repository at this point in the history
[NASAA-272] - Stop Google Discover/Top Stories Experiment
  • Loading branch information
karinathomasbbc authored Dec 16, 2024
2 parents cc97d1c + 24f9258 commit 407d290
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 175 deletions.
59 changes: 3 additions & 56 deletions src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,15 @@ import Disclaimer from '../../components/Disclaimer';
import SecondaryColumn from './SecondaryColumn';
import styles from './ArticlePage.styles';
import { ComponentToRenderProps, TimeStampProps } from './types';
import AmpExperiment from '../../components/AmpExperiment';
import {
experimentName,
experimentTopStoriesConfig,
getExperimentAnalyticsConfig,
getExperimentTopStories,
ExperimentTopStories,
} from './experimentTopStories/helpers';

const ArticlePage = ({ pageData }: { pageData: Article }) => {
const { isApp, pageType, service, isAmp, env } = useContext(RequestContext);
const { isApp, pageType, service } = useContext(RequestContext);

const {
articleAuthor,
isTrustProjectParticipant,
showRelatedTopics,
brandName,
atiAnalyticsProducerId,
} = useContext(ServiceContext);

const { enabled: preloadLeadImageToggle } = useToggle('preloadLeadImage');
Expand Down Expand Up @@ -151,25 +142,13 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
jumpToVariation && hasJumpToBlockForExperiment,
);

const topStoriesContent = pageData?.secondaryColumn?.topStories;
const { shouldEnableExperimentTopStories, transformedBlocks } =
getExperimentTopStories({
blocks,
topStoriesContent,
isAmp,
service,
});

const showRelatedContent = blocks.some(
block => block.type === 'relatedContent',
);

const atiData = {
...atiAnalytics,
...(isCPS && { pageTitle: `${atiAnalytics.pageTitle} - ${brandName}` }),
...(shouldEnableExperimentTopStories && {
ampExperimentName: `${experimentName}`,
}),
};

const componentsToRender = {
Expand Down Expand Up @@ -215,28 +194,6 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
<Disclaimer {...props} increasePaddingOnDesktop={false} />
),
podcastPromo: () => (podcastPromoEnabled ? <InlinePodcastPromo /> : null),
experimentTopStoriesQuarter: () =>
topStoriesContent ? (
<ExperimentTopStories
topStoriesContent={topStoriesContent}
variantName="Quarter"
/>
) : null,
experimentTopStoriesHalf: () =>
topStoriesContent ? (
<ExperimentTopStories
topStoriesContent={topStoriesContent}
variantName="Half"
/>
) : null,
experimentTopStoriesThreeQuarters: () =>
topStoriesContent ? (
<ExperimentTopStories
topStoriesContent={topStoriesContent}
variantName="ThreeQuarters"
/>
) : null,

jumpTo: (props: ComponentToRenderProps & JumpToProps) =>
jumpToVariation === 'on' ? (
<JumpTo {...props} showRelatedContentLink={showRelatedContent} />
Expand All @@ -250,8 +207,8 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
};

const articleBlocks = startsWithHeading
? transformedBlocks
: [visuallyHiddenBlock, ...transformedBlocks];
? blocks
: [visuallyHiddenBlock, ...blocks];

const promoImageBlocks =
pageData?.promo?.images?.defaultPromoImage?.blocks ?? [];
Expand All @@ -273,16 +230,6 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {

return (
<div css={styles.pageWrapper}>
{shouldEnableExperimentTopStories && (
<AmpExperiment
experimentConfig={experimentTopStoriesConfig}
analyticsConfig={getExperimentAnalyticsConfig({
env,
service,
atiAnalyticsProducerId,
})}
/>
)}
<ATIAnalytics atiData={atiData} />
<ChartbeatAnalytics
sectionName={pageData?.relatedContent?.section?.name}
Expand Down
119 changes: 0 additions & 119 deletions src/app/pages/ArticlePage/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { RequestContextProvider } from '#contexts/RequestContext';
import { ToggleContextProvider } from '#contexts/ToggleContext';
import {
articleDataNews,
articleDataNewsLongLength,
articleDataNewsWithEmbeds,
articleDataPersian,
articleDataPidgin,
Expand Down Expand Up @@ -40,7 +39,6 @@ import { ServiceContextProvider } from '../../contexts/ServiceContext';
import ArticlePage from './ArticlePage';
import ThemeProvider from '../../components/ThemeProvider';
import ATIAnalytics from '../../components/ATIAnalytics';
import { topStoriesList } from './PagePromoSections/TopStoriesSection/fixture/index';

jest.mock('../../components/ThemeProvider');

Expand Down Expand Up @@ -884,121 +882,4 @@ describe('Article Page', () => {
);
});
});

describe('when rendering an AMP page', () => {
const renderAmpPage = ({
service,
id,
isShortArticle,
}: {
service: Services;
id: string | null;
isShortArticle?: boolean;
}) => {
const pageData = isShortArticle
? articleDataNews
: articleDataNewsLongLength;

const pageDataWithSecondaryColumn = {
...pageData,
secondaryColumn: {
topStories: topStoriesList,
features: [],
},
};

return render(
<Context isAmp service={service} id={id}>
<ArticlePage pageData={pageDataWithSecondaryColumn} />
</Context>,
{
isAmp: true,
service,
id,
},
);
};

const validNewsAsset = 'c6v11qzyv8po';
const validSportAsset = 'cpgw0xjmpd3o';

it.each`
service | id
${'news'} | ${validNewsAsset}
${'sport'} | ${validSportAsset}
`(
'should render page with experiment-top-stories blocks on $service assets that are long enough',
({ service, id }) => {
const { queryByTestId } = renderAmpPage({
service,
id,
});

expect(
queryByTestId('experiment-top-stories-Quarter'),
).toBeInTheDocument();
expect(
queryByTestId('experiment-top-stories-Half'),
).toBeInTheDocument();
expect(
queryByTestId('experiment-top-stories-ThreeQuarters'),
).toBeInTheDocument();
},
);

it.each`
service | id | isShortArticle | testDescription
${'pidgin'} | ${validNewsAsset} | ${false} | ${`services which are not 'news' or 'sport'`}
${'news'} | ${validNewsAsset} | ${true} | ${`'news' assets that are too short`}
${'sport'} | ${validSportAsset} | ${true} | ${`'sport' assets that are too short`}
`(
'should render page without experiment-top-stories blocks on $testDescription',
({ service, id, isShortArticle }) => {
const { queryByTestId } = renderAmpPage({
service,
id,
isShortArticle,
});

expect(
queryByTestId('experiment-top-stories-Quarter'),
).not.toBeInTheDocument();
expect(
queryByTestId('experiment-top-stories-Half'),
).not.toBeInTheDocument();
expect(
queryByTestId('experiment-top-stories-ThreeQuarters'),
).not.toBeInTheDocument();
},
);

it('should add ampExperimentName to ATIAnalytics on valid services', async () => {
(ATIAnalytics as jest.Mock).mockImplementation(() => <div />);
const service = 'news';
const id = validNewsAsset;

renderAmpPage({ service, id });

expect(ATIAnalytics).toHaveBeenLastCalledWith(
{
atiData: {
categoryName: 'Royal+Wedding+2018~Duchess+of+Sussex',
contentType: 'article',
contentId: 'urn:bbc:optimo:c0000000001o',
language: 'en-gb',
ldpThingIds:
'2351f2b2-ce36-4f44-996d-c3c4f7f90eaa~803eaeb9-c0c3-4f1b-9a66-90efac3df2dc',
ldpThingLabels: 'Royal+Wedding+2018~Duchess+of+Sussex',
nationsProducer: null,
pageIdentifier: 'news.articles.c0000000001o.page',
pageTitle: 'Article Headline for SEO',
timePublished: '2018-01-01T12:01:00.000Z',
timeUpdated: '2018-01-01T14:00:00.000Z',
ampExperimentName: 'topStoriesExperiment',
},
},
{},
);
});
});
});

0 comments on commit 407d290

Please sign in to comment.