Skip to content

Commit 00a1859

Browse files
authored
Use promoCodes field in support message links (#14071)
* Use promoCodes field in support message links * comment * unit tests * tidy comment * fix test names
1 parent 254f113 commit 00a1859

10 files changed

Lines changed: 141 additions & 71 deletions

File tree

dotcom-rendering/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@guardian/shimport": "1.0.2",
4444
"@guardian/source": "9.0.0",
4545
"@guardian/source-development-kitchen": "18.1.1",
46-
"@guardian/support-dotcom-components": "7.2.0",
46+
"@guardian/support-dotcom-components": "7.4.0",
4747
"@guardian/tsconfig": "0.2.0",
4848
"@playwright/test": "1.52.0",
4949
"@sentry/browser": "7.75.1",

dotcom-rendering/src/components/marketing/banners/common/BannerWrapper.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import type { ReactComponent } from '../../lib/ReactComponent';
2222
import { replaceArticleCount } from '../../lib/replaceArticleCount';
2323
import {
2424
addAbandonedBasketAndTrackingParamsToUrl,
25-
addRegionIdAndTrackingParamsToSupportUrl,
2625
addTrackingParamsToProfileUrl,
2726
createClickEventFromTracking,
2827
createInsertEventFromTracking,
2928
createViewEventFromTracking,
29+
enrichSupportUrl,
3030
isProfileUrl,
3131
} from '../../lib/tracking';
3232
import type { CloseableBannerProps } from '../utils/withCloseable';
@@ -91,6 +91,7 @@ const withBannerData =
9191
design,
9292
bannerChannel,
9393
abandonedBasket,
94+
promoCodes,
9495
} = bannerProps;
9596

9697
const [hasBeenSeen, setNode] = useIsInView({
@@ -178,12 +179,12 @@ const withBannerData =
178179
}
179180

180181
return {
181-
ctaUrl: addRegionIdAndTrackingParamsToSupportUrl(
182-
cta.baseUrl,
182+
ctaUrl: enrichSupportUrl({
183+
baseUrl: cta.baseUrl,
183184
tracking,
184-
numArticles,
185+
promoCodes: promoCodes ?? [],
185186
countryCode,
186-
),
187+
}),
187188
ctaText: cta.text,
188189
};
189190
};

dotcom-rendering/src/components/marketing/epics/ContributionsEpic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ const ContributionsEpic: ReactComponent<EpicProps> = ({
324324
addTrackingParamsToBodyLinks(
325325
paragraph,
326326
tracking,
327-
articleCounts.for52Weeks,
327+
variant.promoCodes ?? [],
328328
countryCode,
329329
),
330330
);

dotcom-rendering/src/components/marketing/epics/ctas/ContributionsEpicButtons.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { hasSetReminder } from '../../lib/reminders';
2020
import {
2121
addChoiceCardsOneTimeParams,
2222
addChoiceCardsProductParams,
23-
addRegionIdAndTrackingParamsToSupportUrl,
23+
enrichSupportUrl,
2424
isSupportUrl,
2525
} from '../../lib/tracking';
2626
import {
@@ -58,15 +58,15 @@ const PrimaryCtaButton = ({
5858
countryCode,
5959
amountsTestName,
6060
amountsVariantName,
61-
numArticles,
61+
promoCodes,
6262
submitComponentEvent,
6363
}: {
6464
cta?: Cta;
6565
tracking: Tracking;
6666
countryCode?: string;
6767
amountsTestName?: string;
6868
amountsVariantName?: string;
69-
numArticles: number;
69+
promoCodes: string[];
7070
submitComponentEvent?: (event: ComponentEvent) => void;
7171
}): JSX.Element | null => {
7272
if (!cta) {
@@ -75,14 +75,14 @@ const PrimaryCtaButton = ({
7575

7676
const buttonText = cta.text || 'Support The Guardian';
7777
const baseUrl = cta.baseUrl || 'https://support.theguardian.com/contribute';
78-
const urlWithRegionAndTracking = addRegionIdAndTrackingParamsToSupportUrl(
78+
const urlWithRegionAndTracking = enrichSupportUrl({
7979
baseUrl,
8080
tracking,
81-
numArticles,
81+
promoCodes: promoCodes ?? [],
8282
countryCode,
83-
amountsTestName,
84-
amountsVariantName,
85-
);
83+
amountsAbTestName: amountsTestName,
84+
amountsAbTestVariant: amountsVariantName,
85+
});
8686

8787
return (
8888
<div css={buttonMarginStyles}>
@@ -101,22 +101,22 @@ const PrimaryCtaButton = ({
101101
const SecondaryCtaButton = ({
102102
cta,
103103
tracking,
104-
numArticles,
105104
countryCode,
106105
submitComponentEvent,
106+
promoCodes,
107107
}: {
108108
cta: Cta;
109109
tracking: Tracking;
110110
countryCode?: string;
111-
numArticles: number;
112111
submitComponentEvent?: (event: ComponentEvent) => void;
112+
promoCodes: string[];
113113
}): JSX.Element | null => {
114-
const url = addRegionIdAndTrackingParamsToSupportUrl(
115-
cta.baseUrl,
114+
const url = enrichSupportUrl({
115+
baseUrl: cta.baseUrl,
116116
tracking,
117-
numArticles,
117+
promoCodes,
118118
countryCode,
119-
);
119+
});
120120
return (
121121
<div css={buttonMarginStyles}>
122122
<EpicButton
@@ -142,7 +142,7 @@ interface ContributionsEpicButtonsProps {
142142
threeTierChoiceCardSelectedProduct?: ChoiceCard['product'];
143143
amountsTestName?: string;
144144
amountsVariantName?: string;
145-
numArticles: number;
145+
promoCodes: string[];
146146
}
147147

148148
export const ContributionsEpicButtons = ({
@@ -156,7 +156,7 @@ export const ContributionsEpicButtons = ({
156156
threeTierChoiceCardSelectedProduct,
157157
amountsTestName,
158158
amountsVariantName,
159-
numArticles,
159+
promoCodes,
160160
}: ContributionsEpicButtonsProps): JSX.Element | null => {
161161
const [hasBeenSeen, setNode] = useIsInView({
162162
debounce: true,
@@ -220,7 +220,7 @@ export const ContributionsEpicButtons = ({
220220
<PrimaryCtaButton
221221
cta={getCta(variant.cta)}
222222
tracking={tracking}
223-
numArticles={numArticles}
223+
promoCodes={promoCodes}
224224
amountsTestName={amountsTestName}
225225
amountsVariantName={amountsVariantName}
226226
countryCode={countryCode}
@@ -233,7 +233,7 @@ export const ContributionsEpicButtons = ({
233233
cta={secondaryCta.cta}
234234
tracking={tracking}
235235
countryCode={countryCode}
236-
numArticles={numArticles}
236+
promoCodes={promoCodes}
237237
submitComponentEvent={submitComponentEvent}
238238
/>
239239
)}

dotcom-rendering/src/components/marketing/epics/ctas/ContributionsEpicCtasContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type Props = EpicProps & {
2020
export const ContributionsEpicCtasContainer: ReactComponent<Props> = ({
2121
variant,
2222
countryCode,
23-
articleCounts,
2423
tracking,
2524
submitComponentEvent,
2625
fetchEmail,
@@ -82,7 +81,7 @@ export const ContributionsEpicCtasContainer: ReactComponent<Props> = ({
8281
}
8382
amountsTestName={amountsTestName}
8483
amountsVariantName={amountsVariantName}
85-
numArticles={articleCounts.for52Weeks}
84+
promoCodes={variant.promoCodes ?? []}
8685
/>
8786
{isReminderActive && showReminderFields && (
8887
<ContributionsEpicReminder

dotcom-rendering/src/components/marketing/gutters/GutterAskWrapper.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { useCallback, useEffect } from 'react';
44
import { useIsInView } from '../../../lib/useIsInView';
55
import type { ReactComponent } from '../lib/ReactComponent';
66
import {
7-
addRegionIdAndTrackingParamsToSupportUrl,
87
createClickEventFromTracking,
8+
enrichSupportUrl,
99
} from '../lib/tracking';
1010
import { GutterAsk } from './GutterAsk';
1111

@@ -18,12 +18,12 @@ export const GutterAskWrapper: ReactComponent<GutterProps> = (
1818
? content.cta.baseUrl
1919
: 'https://support.theguardian.com/contribute';
2020

21-
const enrichedUrl = addRegionIdAndTrackingParamsToSupportUrl(
21+
const enrichedUrl = enrichSupportUrl({
2222
baseUrl,
23-
props.tracking,
24-
undefined,
25-
props.countryCode,
26-
);
23+
tracking: props.tracking,
24+
promoCodes: props.promoCodes ?? [],
25+
countryCode: props.countryCode,
26+
});
2727

2828
const onCtaClick = (componentId: string) => {
2929
return (): void => {

dotcom-rendering/src/components/marketing/header/HeaderWrapper.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { useCallback, useEffect } from 'react';
1313
import { useIsInView } from '../../../lib/useIsInView';
1414
import type { ReactComponent } from '../lib/ReactComponent';
1515
import {
16-
addRegionIdAndTrackingParamsToSupportUrl,
1716
addTrackingParamsToProfileUrl,
1817
createClickEventFromTracking,
18+
enrichSupportUrl,
1919
isProfileUrl,
2020
} from '../lib/tracking';
2121

@@ -46,7 +46,7 @@ export const headerWrapper = (
4646
tracking,
4747
countryCode,
4848
submitComponentEvent,
49-
numArticles,
49+
promoCodes,
5050
}) => {
5151
const buildEnrichedCta = (cta: Cta): HeaderEnrichedCta => {
5252
if (isProfileUrl(cta.baseUrl)) {
@@ -59,12 +59,12 @@ export const headerWrapper = (
5959
};
6060
}
6161
return {
62-
ctaUrl: addRegionIdAndTrackingParamsToSupportUrl(
63-
cta.baseUrl,
62+
ctaUrl: enrichSupportUrl({
63+
baseUrl: cta.baseUrl,
6464
tracking,
65-
numArticles,
65+
promoCodes: promoCodes ?? [],
6666
countryCode,
67-
),
67+
}),
6868
ctaText: cta.text,
6969
};
7070
};

dotcom-rendering/src/components/marketing/lib/tracking.test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { addChoiceCardsParams } from './tracking';
1+
import type { Tracking } from '@guardian/support-dotcom-components/dist/shared/types';
2+
import { addChoiceCardsParams, enrichSupportUrl } from './tracking';
23

34
describe('addChoiceCardsParams', () => {
45
it('adds choice cards params to url without existing querystring', () => {
@@ -23,3 +24,60 @@ describe('addChoiceCardsParams', () => {
2324
);
2425
});
2526
});
27+
28+
describe('enrichSupportUrl', () => {
29+
const tracking: Tracking = {
30+
referrerUrl: 'https://theguardian.com',
31+
abTestName: 'test',
32+
abTestVariant: 'control',
33+
campaignCode: 'test',
34+
ophanPageId: '123',
35+
platformId: 'WEB',
36+
componentType: 'ACQUISITIONS_EPIC',
37+
};
38+
39+
it('returns the base URL if it is not a support URL', () => {
40+
const result = enrichSupportUrl({
41+
baseUrl: 'https://theguardian.com',
42+
tracking,
43+
promoCodes: [],
44+
});
45+
expect(result).toEqual('https://theguardian.com');
46+
});
47+
48+
it('adds tracking and region to a support URL without existing querystring', () => {
49+
const result = enrichSupportUrl({
50+
baseUrl: 'https://support.theguardian.com/contribute',
51+
tracking,
52+
countryCode: 'GB',
53+
promoCodes: [],
54+
});
55+
expect(result).toEqual(
56+
'https://support.theguardian.com/uk/contribute?REFPVID=123&INTCMP=test&acquisitionData=%7B%22source%22%3A%22WEB%22%2C%22componentId%22%3A%22test%22%2C%22componentType%22%3A%22ACQUISITIONS_EPIC%22%2C%22campaignCode%22%3A%22test%22%2C%22abTests%22%3A%5B%7B%22name%22%3A%22test%22%2C%22variant%22%3A%22control%22%7D%5D%2C%22referrerPageviewId%22%3A%22123%22%2C%22referrerUrl%22%3A%22https%3A%2F%2Ftheguardian.com%22%2C%22isRemote%22%3Atrue%7D',
57+
);
58+
});
59+
60+
it('adds tracking and region to a support URL with existing querystring', () => {
61+
const result = enrichSupportUrl({
62+
baseUrl: 'https://support.theguardian.com/contribute?test=test',
63+
tracking,
64+
countryCode: 'GB',
65+
promoCodes: [],
66+
});
67+
expect(result).toEqual(
68+
'https://support.theguardian.com/uk/contribute?test=test&REFPVID=123&INTCMP=test&acquisitionData=%7B%22source%22%3A%22WEB%22%2C%22componentId%22%3A%22test%22%2C%22componentType%22%3A%22ACQUISITIONS_EPIC%22%2C%22campaignCode%22%3A%22test%22%2C%22abTests%22%3A%5B%7B%22name%22%3A%22test%22%2C%22variant%22%3A%22control%22%7D%5D%2C%22referrerPageviewId%22%3A%22123%22%2C%22referrerUrl%22%3A%22https%3A%2F%2Ftheguardian.com%22%2C%22isRemote%22%3Atrue%7D',
69+
);
70+
});
71+
72+
it('adds tracking, region and promo codes to a support URL', () => {
73+
const result = enrichSupportUrl({
74+
baseUrl: 'https://support.theguardian.com/contribute',
75+
tracking,
76+
countryCode: 'GB',
77+
promoCodes: ['PROMO1', 'PROMO2'],
78+
});
79+
expect(result).toEqual(
80+
'https://support.theguardian.com/uk/contribute?REFPVID=123&INTCMP=test&acquisitionData=%7B%22source%22%3A%22WEB%22%2C%22componentId%22%3A%22test%22%2C%22componentType%22%3A%22ACQUISITIONS_EPIC%22%2C%22campaignCode%22%3A%22test%22%2C%22abTests%22%3A%5B%7B%22name%22%3A%22test%22%2C%22variant%22%3A%22control%22%7D%5D%2C%22referrerPageviewId%22%3A%22123%22%2C%22referrerUrl%22%3A%22https%3A%2F%2Ftheguardian.com%22%2C%22isRemote%22%3Atrue%7D&promoCode=PROMO1&promoCode=PROMO2',
81+
);
82+
});
83+
});

0 commit comments

Comments
 (0)