Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const ReaderRevenueDev = ({ shouldHideReaderRevenue }: Props) => {
useEffect(() => {
// Used internally only, so only import each function on demand
const loadAndRun =
<K extends keyof ReaderRevenueDevUtils>(key: K) =>
<K extends keyof Omit<ReaderRevenueDevUtils, 'bannerToShow'>>(
key: K,
) =>
(asExistingSupporter: boolean) =>
import(
/* webpackChunkName: "readerRevenueDevUtils" */ '../lib/readerRevenueDevUtils'
Expand All @@ -36,6 +38,7 @@ export const ReaderRevenueDev = ({ shouldHideReaderRevenue }: Props) => {
showMeTheBanner: loadAndRun('showMeTheBanner'),
showNextVariant: loadAndRun('showNextVariant'),
showPreviousVariant: loadAndRun('showPreviousVariant'),
bannerToShow: undefined,
};
}
}, [shouldHideReaderRevenue]);
Expand Down
26 changes: 16 additions & 10 deletions dotcom-rendering/src/components/StickyBottomBanner.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
BrazeMessagesInterface,
} from '@guardian/braze-components/logic';
import type { CountryCode } from '@guardian/libs';
import { cmp, isString, isUndefined, storage } from '@guardian/libs';
import { cmp, isString, isUndefined, log, storage } from '@guardian/libs';
import type { ModuleData } from '@guardian/support-dotcom-components/dist/dotcom/types';
import type { BannerProps } from '@guardian/support-dotcom-components/dist/shared/types';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -72,6 +72,8 @@ const buildCmpBannerConfig = (): CandidateConfig<void> => ({
result ? { show: true, meta: undefined } : { show: false },
),
show: () => {
log('supporterRevenue', `Showing CMP UI`);
window.guardian.readerRevenue.bannerToShow = 'cmpUi';
// New CMP is not a react component and is shown outside of react's world
// so render nothing if it will show
return null;
Expand Down Expand Up @@ -160,9 +162,11 @@ const buildRRBannerConfigWith = ({
ophanPageViewId,
pageId,
}),
show:
({ name, props }: ModuleData<BannerProps>) =>
() => <BannerComponent name={name} props={props} />,
show: ({ name, props }: ModuleData<BannerProps>) => {
log('supporterRevenue', `Showing banner: ${name}`);
window.guardian.readerRevenue.bannerToShow = name;
return () => <BannerComponent name={name} props={props} />;
},
},
timeoutMillis: DEFAULT_BANNER_TIMEOUT_MILLIS,
};
Expand Down Expand Up @@ -193,9 +197,11 @@ const buildBrazeBanner = (
tags,
shouldHideReaderRevenue,
),
show: (meta: any) => () => (
<BrazeBanner meta={meta} idApiUrl={idApiUrl} />
),
show: (meta: any) => () => {
log('supporterRevenue', `Showing banner: braze-banner`);
window.guardian.readerRevenue.bannerToShow = 'braze-banner';
return <BrazeBanner meta={meta} idApiUrl={idApiUrl} />;
},
},
timeoutMillis: DEFAULT_BANNER_TIMEOUT_MILLIS,
});
Expand Down Expand Up @@ -304,9 +310,9 @@ export const StickyBottomBanner = ({
};

pickMessage(bannerConfig, renderingTarget)
.then((PickedBanner: () => MaybeFC) =>
setSelectedBanner(PickedBanner),
)
.then((PickedBanner: () => MaybeFC) => {
setSelectedBanner(PickedBanner);
})
.catch((e) =>
console.error(
`StickyBottomBanner pickMessage - error: ${String(e)}`,
Expand Down
18 changes: 17 additions & 1 deletion dotcom-rendering/src/lib/messagePicker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isUndefined, startPerformanceMeasure } from '@guardian/libs';
import { isUndefined, log, startPerformanceMeasure } from '@guardian/libs';
import { getOphan } from '../client/ophan/ophan';
import type { RenderingTarget } from '../types/renderingTarget';

Expand Down Expand Up @@ -164,6 +164,22 @@ export const pickMessage = (
.then((winner) => {
clearAllTimeouts(candidateConfigsWithTimeout);

log(
'supporterRevenue',
`pickMessage for ${name}: ${JSON.stringify(winner)}}`,
);
document.dispatchEvent(
new CustomEvent<{
type: string;
winner: string | null;
}>('supporterRevenue:messagePicker', {
detail: {
type: name,
winner: winner?.candidate.id ?? null,
},
}),
);

if (winner === null) {
resolve(defaultShow);
} else {
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/lib/readerRevenueDevUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export interface ReaderRevenueDevUtils {
showMeTheBanner: ReaderRevenueDevUtil;
showNextVariant: ReaderRevenueDevUtil;
showPreviousVariant: ReaderRevenueDevUtil;
bannerToShow?: string;
}

const getForcedVariant = (type: 'epic' | 'banner'): string | null => {
Expand Down