Bug fix: referral_source should not become duplicated based on different case

Fixes https://github.com/TryGhost/Product/issues/3928
This commit is contained in:
Princi Vershwal 2023-10-11 16:39:51 +05:30 committed by GitHub
parent 909c8b53a8
commit 3e8efcca90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

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

View File

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