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 }); });