Skip to content

Commit caf818b

Browse files
removing console logs
adding additional unit tests
1 parent e6371b2 commit caf818b

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

dotcom-rendering/src/components/EnhanceAffiliateLinks.importable.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,14 @@ export const EnhanceAffiliateLinks = () => {
5959
const allLinksOnPage = [...document.querySelectorAll('a')];
6060

6161
const urlParams = new URLSearchParams(window.location.search);
62-
console.log('urlParams:', urlParams.toString());
6362

6463
const referrerURLParams = new URLSearchParams(
6564
document.referrer.split('?')[1] ?? '',
6665
);
67-
console.log('referrerURLParams:', referrerURLParams.toString());
6866

6967
const utmParamsFromArticleURL = getUtmString(urlParams, utmKeys);
70-
console.log('utmString:', utmParamsFromArticleURL);
7168

7269
const utmParamsFromReferrer = getUtmString(referrerURLParams, utmKeys);
73-
console.log('utmFromReferrer:', utmParamsFromReferrer);
7470

7571
const utmParamsString =
7672
utmParamsFromArticleURL && utmParamsFromArticleURL.trim() !== ''

dotcom-rendering/src/components/EnhanceAffiliateLinks.test.tsx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ describe('EnhanceAffiliateLinks', () => {
8282
);
8383
});
8484

85-
it('should include UTM parameters in xcust if present', () => {
86-
// replace window.location safely
85+
it('should use article URL UTM parameters when present', () => {
8786
Object.defineProperty(window, 'location', {
8887
value: new URL(
8988
'https://example.test/this?utm_source=growth&utm_medium=epicuk&utm_campaign=q3_test&utm_content=filter_general',
@@ -100,4 +99,54 @@ describe('EnhanceAffiliateLinks', () => {
10099
'utm_source%7Cgrowth%7Cutm_medium%7Cepicuk%7Cutm_campaign%7Cq3_test%7Cutm_content%7Cfilter_general',
101100
);
102101
});
102+
103+
it('should use UTM parameters from the referrer if the article URL has none', () => {
104+
Object.defineProperty(window, 'location', {
105+
value: new URL('https://example.test/page'),
106+
configurable: true,
107+
});
108+
109+
Object.defineProperty(document, 'referrer', {
110+
value: 'https://foo.bar/some?utm_source=testsource&utm_medium=somemedium&utm_campaign=refcamp',
111+
configurable: true,
112+
});
113+
114+
document.body.innerHTML = `
115+
<a href="https://go.skimresources.com/?id=12345">Skimlink</a>
116+
`;
117+
118+
render(<EnhanceAffiliateLinks />);
119+
120+
const link = document.querySelector('a');
121+
122+
expect(link?.href).toContain(
123+
'utm_source%7Ctestsource%7Cutm_medium%7Csomemedium%7Cutm_campaign%7Crefcamp',
124+
);
125+
});
126+
127+
it('should use UTM parameters from the article URL over the referrer if both exist', () => {
128+
Object.defineProperty(window, 'location', {
129+
value: new URL(
130+
'https://example.test/page?utm_source=pagegrow&utm_medium=somemedium',
131+
),
132+
configurable: true,
133+
});
134+
135+
Object.defineProperty(document, 'referrer', {
136+
value: 'https://foo.bar?utm_source=refgrow&utm_medium=refmed',
137+
configurable: true,
138+
});
139+
140+
document.body.innerHTML = `
141+
<a href="https://go.skimresources.com/?id=12345">Skimlink</a>
142+
`;
143+
144+
render(<EnhanceAffiliateLinks />);
145+
146+
const link = document.querySelector('a');
147+
expect(link?.href).toContain(
148+
'utm_source%7Cpagegrow%7Cutm_medium%7Csomemedium',
149+
);
150+
expect(link?.href).not.toContain('refgrow');
151+
});
103152
});

0 commit comments

Comments
 (0)