Skip to content

Commit 0653c91

Browse files
-adding ability to pull utm params out of the ref URL
-couple of renamings to make const clearer -updating comment to be more readable
1 parent abd3149 commit 0653c91

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { useBetaAB } from '../lib/useAB';
77
* - Referrer
88
* - Skimlinks account ID
99
* - AB test participations
10-
* - utm_source,
11-
* - utm_medium,
12-
* - utm_campaign,
13-
* - utm_content,
14-
* - utm_term
10+
* - UTM parameters (from page URL or referrer URL):
11+
* - utm_source
12+
* - utm_medium
13+
* - utm_campaign
14+
* - utm_content
15+
* - utm_term
1516
*
1617
* ## Why does this need to be an Island?
1718
*
@@ -38,6 +39,9 @@ export const EnhanceAffiliateLinks = () => {
3839
const allLinksOnPage = [...document.querySelectorAll('a')];
3940

4041
const urlParams = new URLSearchParams(window.location.search);
42+
const referrerURLParams = new URLSearchParams(
43+
document.referrer.split('?')[1] || '',
44+
);
4145

4246
const utmKeys = [
4347
'utm_source',
@@ -47,14 +51,32 @@ export const EnhanceAffiliateLinks = () => {
4751
'utm_term',
4852
];
4953

50-
const utmString = utmKeys
54+
const utmFromArticleURL = utmKeys
5155
.map((key) => {
5256
const value = urlParams.get(key);
5357
return value ? `${key}|${value}` : null;
5458
})
5559
.filter(Boolean)
5660
.join('|');
5761

62+
console.log('utmString:', utmFromArticleURL);
63+
64+
const utmFromReferrer = utmKeys
65+
.map((key) => {
66+
const value = referrerURLParams.get(key);
67+
return value ? `${key}|${value}` : null;
68+
})
69+
.filter(Boolean)
70+
.join('|');
71+
72+
console.log('utmFromReferrer:', utmFromReferrer);
73+
74+
const utmString = utmFromArticleURL
75+
? utmFromArticleURL
76+
: utmFromReferrer
77+
? utmFromReferrer
78+
: '';
79+
5880
for (const link of allLinksOnPage) {
5981
if (isSkimlink(link.href)) {
6082
const referrerDomain =

0 commit comments

Comments
 (0)