From 3e8efcca90d75ee8c92de660aa84633c4f381045 Mon Sep 17 00:00:00 2001 From: Princi Vershwal Date: Wed, 11 Oct 2023 16:39:51 +0530 Subject: [PATCH] Bug fix: referral_source should not become duplicated based on different case Fixes https://github.com/TryGhost/Product/issues/3928 --- .../lib/ReferrerTranslator.js | 5 +++-- .../test/referrer-translator.test.js | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ghost/member-attribution/lib/ReferrerTranslator.js b/ghost/member-attribution/lib/ReferrerTranslator.js index e5a59a9514..7db27a2d2c 100644 --- a/ghost/member-attribution/lib/ReferrerTranslator.js +++ b/ghost/member-attribution/lib/ReferrerTranslator.js @@ -78,9 +78,10 @@ class ReferrerTranslator { // If referrer is from query params if (referrerSource) { const urlData = referrerUrl ? this.getDataFromUrl(referrerUrl) : null; + const knownSource = Object.values(knownReferrers).find(referrer => referrer.source.toLowerCase() === referrerSource.toLowerCase()); return { - referrerSource: referrerSource, - referrerMedium: referrerMedium || urlData?.medium || null, + referrerSource: knownSource?.source || referrerSource, + referrerMedium: knownSource?.medium || referrerMedium || urlData?.medium || null, referrerUrl: referrerUrl?.hostname ?? null }; } diff --git a/ghost/member-attribution/test/referrer-translator.test.js b/ghost/member-attribution/test/referrer-translator.test.js index 375380aaa5..19fe1e862e 100644 --- a/ghost/member-attribution/test/referrer-translator.test.js +++ b/ghost/member-attribution/test/referrer-translator.test.js @@ -157,8 +157,22 @@ describe('ReferrerTranslator', function () { referrerUrl: null } ])).eql({ - referrerSource: 'twitter', - referrerMedium: null, + referrerSource: 'Twitter', + referrerMedium: 'social', + referrerUrl: null + }); + }); + + it('returns known source for ref source if exists', async function () { + should(translator.getReferrerDetails([ + { + referrerSource: 'facebook', + referrerMedium: null, + referrerUrl: null + } + ])).eql({ + referrerSource: 'Facebook', + referrerMedium: 'social', referrerUrl: null }); });