diff --git a/ghost/core/core/frontend/src/member-attribution/member-attribution.js b/ghost/core/core/frontend/src/member-attribution/member-attribution.js index 6cd8c16eebc..72223d661f2 100644 --- a/ghost/core/core/frontend/src/member-attribution/member-attribution.js +++ b/ghost/core/core/frontend/src/member-attribution/member-attribution.js @@ -76,6 +76,8 @@ const LIMIT = 15; let sourceParam; let utmSourceParam; let utmMediumParam; + let referrerSource; + try { // Fetch source/medium from query param const url = new URL(window.location.href); @@ -83,11 +85,23 @@ const LIMIT = 15; sourceParam = url.searchParams.get('source'); utmSourceParam = url.searchParams.get('utm_source'); utmMediumParam = url.searchParams.get('utm_medium'); + + referrerSource = refParam || sourceParam || utmSourceParam || null; + + // if referrerSource is not set, check to see if the url contains a hash like ghost.org/#/portal/signup?ref=ghost and pull the ref from the hash + if (!referrerSource && url.hash && url.hash.includes('#/portal')) { + const hashUrl = new URL(window.location.href.replace('/#/portal', '')); + refParam = hashUrl.searchParams.get('ref'); + sourceParam = hashUrl.searchParams.get('source'); + utmSourceParam = hashUrl.searchParams.get('utm_source'); + utmMediumParam = hashUrl.searchParams.get('utm_medium'); + + referrerSource = refParam || sourceParam || utmSourceParam || null; + } } catch (e) { console.error('[Member Attribution] Parsing referrer from querystring failed', e); } - const referrerSource = refParam || sourceParam || utmSourceParam || null; const referrerMedium = utmMediumParam || null; const referrerUrl = window.document.referrer || null; diff --git a/ghost/core/test/e2e-server/services/member-attribution.test.js b/ghost/core/test/e2e-server/services/member-attribution.test.js index f4e25e8fcbc..4a3e8099956 100644 --- a/ghost/core/test/e2e-server/services/member-attribution.test.js +++ b/ghost/core/test/e2e-server/services/member-attribution.test.js @@ -400,5 +400,25 @@ describe('Member Attribution Service', function () { referrerUrl: null })); }); + + it('resolves Portal signup URLs', async function () { + // NOTE: We cannot test the actual hash URL here; the attribution below is what is receieved when navigating to /#/portal/signup?ref=ghost + // TODO: We don't appear to have tests for parsing URLs for params. + const attribution = await memberAttributionService.service.getAttribution([ + { + path: '/', + time: Date.now(), + referrerSource: 'casper' + } + ]); + attribution.should.match(({ + id: null, + url: '/', + type: 'url', + referrerSource: 'casper', + referrerMedium: null, + referrerUrl: null + })); + }); }); -}); +}); \ No newline at end of file