Skip to content

Commit

Permalink
Merge pull request #12172 from bbc/WSTEAMA-1444-remove-election-banne…
Browse files Browse the repository at this point in the history
…r-optimizely-references

WSTEAMA-1444 - Remove election banner Optimizely references
  • Loading branch information
louisearchibald authored Nov 14, 2024
2 parents 0a3c774 + 189aa47 commit c3b2ad8
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 57 deletions.
17 changes: 0 additions & 17 deletions src/app/components/ATIAnalytics/atiUrl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const buildATIPageTrackPath = ({
categoryName,
campaigns,
nationsProducer,
experimentVariant,
}: ATIPageTrackingProps) => {
const href = getHref(platform);
const referrer = getReferrer(platform, origin, previousPath);
Expand Down Expand Up @@ -215,22 +214,6 @@ export const buildATIPageTrackPath = ({
value: getATIMarketingString(href, campaignType),
wrap: false,
},
...(experimentVariant
? [
{
key: 'mv_test',
description: 'Article page banner experiment',
value: `Election Banner Experiment`,
wrap: false,
},
{
key: 'mv_creation',
description: 'Article page banner variant',
value: `${experimentVariant}`,
wrap: false,
},
]
: []),
...getRSSMarketingString(href, campaignType),
...(onOnionTld()
? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const buildPageATIParams = ({
producerId,
timePublished,
timeUpdated,
experimentVariant,
} = atiData;

return {
Expand All @@ -50,7 +49,6 @@ export const buildPageATIParams = ({
statsDestination,
timePublished,
timeUpdated,
...(experimentVariant && { experimentVariant }),
};
};

Expand Down
2 changes: 0 additions & 2 deletions src/app/components/ATIAnalytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface ATIData {
producerName?: string | null;
timePublished?: string | null;
timeUpdated?: string | null;
experimentVariant?: string | null;
}

export interface PageData {
Expand Down Expand Up @@ -132,7 +131,6 @@ export interface ATIPageTrackingProps {
categoryName?: string | null;
campaigns?: { campaignId?: string; campaignName?: string }[] | null;
nationsProducer?: string | null;
experimentVariant?: string | null;
}

export interface ATIProps {
Expand Down
4 changes: 1 addition & 3 deletions src/app/hooks/useOptimizelyMvtVariation/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useContext } from 'react';
import { OptimizelyContext } from '@optimizely/react-sdk';
import { RequestContext } from '#contexts/RequestContext';
import useToggle from '#hooks/useToggle';
import activateExperiment from './activateExperiment';

const useOptimizelyMvtVariation = id => {
const { optimizely } = useContext(OptimizelyContext);
const { mvtExperiments } = useContext(RequestContext);
const { enabled: electionBannerEnabled } = useToggle('electionBanner');

if (!mvtExperiments || mvtExperiments.length === 0 || id === null) {
return null;
Expand All @@ -17,7 +15,7 @@ const useOptimizelyMvtVariation = id => {
({ experimentName }) => experimentName === id,
);

if (!experiment || !electionBannerEnabled) return null;
if (!experiment) return null;

const isEnabled = experiment.enabled;
const variation = isEnabled && experiment.variation;
Expand Down
7 changes: 1 addition & 6 deletions src/app/hooks/useOptimizelyMvtVariation/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { renderHook } from '#app/components/react-testing-library-with-providers';
import { RequestContextProvider } from '#contexts/RequestContext';
import { ToggleContextProvider } from '#contexts/ToggleContext';
import useOptimizelyMvtVariation from '.';
import * as activateExperiment from './activateExperiment';

Expand All @@ -23,11 +22,7 @@ describe('useOptimizelyMvtVariation custom hook', () => {
pathname: 'bar',
};
const wrapper = ({ children }) => (
<RequestContextProvider {...props}>
<ToggleContextProvider toggles={{ electionBanner: { enabled: true } }}>
{children}
</ToggleContextProvider>
</RequestContextProvider>
<RequestContextProvider {...props}>{children}</RequestContextProvider>
);
return renderHook(() => useOptimizelyMvtVariation(flagId), {
wrapper,
Expand Down
2 changes: 1 addition & 1 deletion src/app/hooks/useOptimizelyVariation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useState, useEffect } from 'react';
import { useDecision } from '@optimizely/react-sdk';

const isClientSide = false;
const isClientSide = true;

// ALTHOUGH THIS FUNCTION BREAKS REACT RULES BY USING CONDITIONAL HOOKS,
// WE CAN SAFELY DO SO SINCE isClientSide IS A CONSTANT AND THEREFORE GUARANTEES THAT
Expand Down
17 changes: 1 addition & 16 deletions src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/** @jsx jsx */
/** @jsxFrag React.Fragment */
import React, { useContext } from 'react';
import { useContext } from 'react';
import { jsx, useTheme } from '@emotion/react';
import useToggle from '#hooks/useToggle';
import useOptimizelyMvtVariation from '#hooks/useOptimizelyMvtVariation';
import { singleTextBlock } from '#app/models/blocks';
import ArticleMetadata from '#containers/ArticleMetadata';
import { RequestContext } from '#contexts/RequestContext';
Expand Down Expand Up @@ -40,8 +38,6 @@ import CpsRecommendations from '#containers/CpsRecommendations';
import InlinePodcastPromo from '#containers/PodcastPromo/Inline';
import { Article, OptimoBylineBlock } from '#app/models/types/optimo';
import ScrollablePromo from '#components/ScrollablePromo';
import OptimizelyArticleCompleteTracking from '#app/legacy/containers/OptimizelyArticleCompleteTracking';
import OptimizelyPageViewTracking from '#app/legacy/containers/OptimizelyPageViewTracking';
import JumpTo from '#app/components/JumpTo';
import ElectionBanner from './ElectionBanner';

Expand Down Expand Up @@ -91,10 +87,6 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
palette: { GREY_2, WHITE },
} = useTheme();

const experimentVariant = useOptimizelyMvtVariation(
'newswb_01_ap_banner_election',
);

const allowAdvertising = pageData?.metadata?.allowAdvertising ?? false;
const adcampaign = pageData?.metadata?.adCampaignKeyword;
const isTransliterated =
Expand Down Expand Up @@ -145,7 +137,6 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
const atiData = {
...atiAnalytics,
...(isCPS && { pageTitle: `${atiAnalytics.pageTitle} - ${brandName}` }),
...(experimentVariant && { experimentVariant }),
};

const topStoriesContent = pageData?.secondaryColumn?.topStories;
Expand Down Expand Up @@ -315,12 +306,6 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
mobileDivider={showTopics}
/>
)}
{experimentVariant && (
<>
<OptimizelyArticleCompleteTracking />
<OptimizelyPageViewTracking />
</>
)}
</div>
);
};
Expand Down
4 changes: 0 additions & 4 deletions src/app/pages/ArticlePage/ElectionBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import AmpIframe from '#app/components/AmpIframe';
import useToggle from '#app/hooks/useToggle';
import { Tag } from '#app/components/Metadata/types';
import { ServiceContext } from '#app/contexts/ServiceContext';
import useOptimizelyMvtVariation from '#app/hooks/useOptimizelyMvtVariation';
import { getEnvConfig } from '#app/lib/utilities/getEnvConfig';
import { MetadataTaggings } from '#app/models/types/metadata';
import { Services } from '#app/models/types/global';
Expand Down Expand Up @@ -36,8 +35,6 @@ export default function ElectionBanner({ aboutTags, taggings }: Props) {
const { enabled: electionBannerEnabled }: { enabled: boolean | null } =
useToggle('electionBanner');

const variation = useOptimizelyMvtVariation('newswb_01_ap_banner_election');

if (isLite) return null;

const {
Expand All @@ -60,7 +57,6 @@ export default function ElectionBanner({ aboutTags, taggings }: Props) {
!isEditoriallySensitive && validAboutTag && electionBannerEnabled;

if (!showBanner) return null;
if (variation === 'off') return null;

const {
SIMORGH_APP_ENV,
Expand Down
5 changes: 1 addition & 4 deletions src/app/pages/ArticlePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import withOptimizelyProvider from '#app/legacy/containers/PageHandlers/withOptimizelyProvider';
import ArticlePage from './ArticlePage';
import applyBasicPageHandlers from '../utils/applyBasicPageHandlers';

const OptimizelyArticle = withOptimizelyProvider(ArticlePage);

export default applyBasicPageHandlers(OptimizelyArticle);
export default applyBasicPageHandlers(ArticlePage);
4 changes: 2 additions & 2 deletions src/server/utilities/mvtHeader/enabledExperimentsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Add enabled experiments objects inside this array in this format:
*/
const enabledExperimentList = [
{
name: 'newswb_01_ap_banner_election',
services: ['mundo', 'portuguese'],
name: 'test_2',
services: ['pidgin'],
pageTypes: ['article'],
},
];
Expand Down

0 comments on commit c3b2ad8

Please sign in to comment.