Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(packages/sui-segment-wrapper): fix stc mapping #1856

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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