Skip to content

Commit

Permalink
Merge pull request #1856 from SUI-Components/fix-stc-mapping
Browse files Browse the repository at this point in the history
fix(packages/sui-segment-wrapper): fix stc mapping
  • Loading branch information
kikoruiz authored Oct 24, 2024
2 parents ad05bbf + 57462bd commit 025abee
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FIELDS = {
const STC = {
QUERY: 'stc',
SPLIT_SYMBOL: '-',
NAME_SPLIT_SYMBOL: ':'
CAMPAIGN_SPLIT_SYMBOL: ':'
}

const STC_MEDIUM_TRANSFORMATIONS = {
Expand All @@ -25,6 +25,8 @@ const STC_MEDIUM_TRANSFORMATIONS = {
cs: 'cross-sites'
}

const STC_INVALID_CONTENT = 'na'

const cachedData = {
[FIELDS.clientId]: null,
[FIELDS.sessionId]: null
Expand Down Expand Up @@ -77,17 +79,18 @@ 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: {
medium: (needsTransformation && STC_MEDIUM_TRANSFORMATIONS[medium]) || medium,
...(typeof name !== 'undefined' && {id}),
name: name ?? id,
source,
term,
...(typeof content !== 'undefined' && {content})
...(needsContent && {content}),
...(typeof term !== 'undefined' && {term})
}
}
}
Expand Down
92 changes: 88 additions & 4 deletions packages/sui-segment-wrapper/test/segmentWrapperSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,21 @@ 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: {
campaign: {
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: {
Expand All @@ -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'
}
}
})
Expand Down

0 comments on commit 025abee

Please sign in to comment.