From 57462bd97720993ffd36f1da05f2d7b4bbfdbcc2 Mon Sep 17 00:00:00 2001 From: Kiko Ruiz Date: Wed, 23 Oct 2024 16:36:21 +0200 Subject: [PATCH] fix(packages/sui-segment-wrapper): fix stc mapping --- .../src/repositories/googleRepository.js | 13 ++- .../test/segmentWrapperSpec.js | 92 ++++++++++++++++++- 2 files changed, 96 insertions(+), 9 deletions(-) diff --git a/packages/sui-segment-wrapper/src/repositories/googleRepository.js b/packages/sui-segment-wrapper/src/repositories/googleRepository.js index 8f2603624..0c699ea39 100644 --- a/packages/sui-segment-wrapper/src/repositories/googleRepository.js +++ b/packages/sui-segment-wrapper/src/repositories/googleRepository.js @@ -9,7 +9,7 @@ const FIELDS = { const STC = { QUERY: 'stc', SPLIT_SYMBOL: '-', - NAME_SPLIT_SYMBOL: ':' + CAMPAIGN_SPLIT_SYMBOL: ':' } const STC_MEDIUM_TRANSFORMATIONS = { @@ -25,6 +25,8 @@ const STC_MEDIUM_TRANSFORMATIONS = { cs: 'cross-sites' } +const STC_INVALID_CONTENT = 'na' + const cachedData = { [FIELDS.clientId]: null, [FIELDS.sessionId]: null @@ -77,8 +79,9 @@ export const getCampaignDetails = ({needsTransformation = true} = {}) => { if (!searchParams.has(STC.QUERY)) return null const stc = searchParams.get(STC.QUERY) - const [medium, source, originalName, term, content] = stc.split(STC.SPLIT_SYMBOL) - const [id, name] = originalName.split(STC.NAME_SPLIT_SYMBOL) + const [medium, source, campaign, content, term] = stc.split(STC.SPLIT_SYMBOL) + const [id, name] = campaign.split(STC.CAMPAIGN_SPLIT_SYMBOL) + const needsContent = typeof content !== 'undefined' && content !== STC_INVALID_CONTENT return { campaign: { @@ -86,8 +89,8 @@ export const getCampaignDetails = ({needsTransformation = true} = {}) => { ...(typeof name !== 'undefined' && {id}), name: name ?? id, source, - term, - ...(typeof content !== 'undefined' && {content}) + ...(needsContent && {content}), + ...(typeof term !== 'undefined' && {term}) } } } diff --git a/packages/sui-segment-wrapper/test/segmentWrapperSpec.js b/packages/sui-segment-wrapper/test/segmentWrapperSpec.js index 6749a2c0d..e3dd00276 100644 --- a/packages/sui-segment-wrapper/test/segmentWrapperSpec.js +++ b/packages/sui-segment-wrapper/test/segmentWrapperSpec.js @@ -267,7 +267,7 @@ describe('Segment Wrapper', function () { }) }) - it('should send mapped campaign details', async () => { + it('should send mapped campaign details when the url query string is `?stc=em-mail-winter%20promo-honda`', async () => { await assertCampaignDetails({ queryString: '?stc=em-mail-winter%20promo-honda', expectation: { @@ -275,11 +275,13 @@ describe('Segment Wrapper', function () { medium: 'email', name: 'winter promo', source: 'mail', - term: 'honda' + content: 'honda' } } }) + }) + it('should send mapped campaign details when the url query string is `?stc=sm-google-1234%3Aspring%20sale-aprilia-logolink`', async () => { await assertCampaignDetails({ queryString: '?stc=sm-google-1234%3Aspring%20sale-aprilia-logolink', expectation: { @@ -288,8 +290,90 @@ describe('Segment Wrapper', function () { id: '1234', name: 'spring sale', source: 'google', - term: 'aprilia', - content: 'logolink' + content: 'aprilia', + term: 'logolink' + } + } + }) + }) + + it('should send mapped campaign details when the url query string is `?stc=sem-google-autumn%20sale`', async () => { + await assertCampaignDetails({ + queryString: '?stc=sem-google-autumn%20sale', + expectation: { + campaign: { + medium: 'paid-search', + name: 'autumn sale', + source: 'google' + } + } + }) + }) + + it('should send mapped campaign details when the url query string is `?stc=sem-google-autumn sale`', async () => { + await assertCampaignDetails({ + queryString: '?stc=sem-google-autumn sale', + expectation: { + campaign: { + medium: 'paid-search', + name: 'autumn sale', + source: 'google' + } + } + }) + }) + + it('should send mapped campaign details when the url query string is `?stc=sem-google-1234%3Aautumn%20sale`', async () => { + await assertCampaignDetails({ + queryString: '?stc=sem-google-1234%3Aautumn%20sale', + expectation: { + campaign: { + medium: 'paid-search', + id: '1234', + name: 'autumn sale', + source: 'google' + } + } + }) + }) + + it('should send mapped campaign details when the url query string is `?stc=sem-google-1234:autumn sale`', async () => { + await assertCampaignDetails({ + queryString: '?stc=sem-google-1234:autumn sale', + expectation: { + campaign: { + medium: 'paid-search', + id: '1234', + name: 'autumn sale', + source: 'google' + } + } + }) + }) + + it('should send mapped campaign details when the url query string is `?stc=sem-google-autumn sale-aprilia`', async () => { + await assertCampaignDetails({ + queryString: '?stc=sem-google-autumn sale-aprilia', + expectation: { + campaign: { + medium: 'paid-search', + name: 'autumn sale', + source: 'google', + content: 'aprilia' + } + } + }) + }) + + it('should send mapped campaign details when the url query string is `?stc=sem-google-autumn sale-na-logolink`', async () => { + await assertCampaignDetails({ + queryString: '?stc=sem-google-autumn sale-na-logolink', + expectation: { + campaign: { + medium: 'paid-search', + name: 'autumn sale', + source: 'google', + term: 'logolink' } } })