-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1848 from SUI-Components/ga4-campaign-data
feat(segment-wrapper): map GA4 campaign data
- Loading branch information
Showing
6 changed files
with
2,884 additions
and
437 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/sui-segment-wrapper/src/middlewares/source/campaignContext.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {getConfig} from '../../config.js' | ||
import {getCampaignDetails} from '../../repositories/googleRepository.js' | ||
|
||
export const campaignContext = ({payload, next}) => { | ||
const googleAnalyticsMeasurementId = getConfig('googleAnalyticsMeasurementId') | ||
|
||
if (googleAnalyticsMeasurementId) { | ||
const campaignDetails = getCampaignDetails({needsTransformation: false}) | ||
|
||
payload.obj.context = { | ||
...payload.obj.context, | ||
...campaignDetails | ||
} | ||
} | ||
|
||
next(payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {expect} from 'chai' | ||
import sinon from 'sinon' | ||
|
||
import {setConfig} from '../src/config.js' | ||
import {getCampaignDetails} from '../src/repositories/googleRepository.js' | ||
import suiAnalytics from '../src/index.js' | ||
import {stubActualQueryString} from './stubs.js' | ||
import {simulateUserAcceptConsents} from './tcf.js' | ||
|
||
export const assertCampaignDetails = async ({queryString, expectation}) => { | ||
const queryStringStub = stubActualQueryString(queryString) | ||
const spy = sinon.stub() | ||
|
||
setConfig('googleAnalyticsMeasurementId', 123) | ||
await simulateUserAcceptConsents() | ||
await suiAnalytics.track( | ||
'fakeEvent', | ||
{}, | ||
{ | ||
integrations: {fakeIntegrationKey: 'fakeIntegrationValue'} | ||
}, | ||
spy | ||
) | ||
|
||
const {context} = spy.firstCall.firstArg.obj | ||
const {campaign: campaignContext} = context | ||
const campaignDetails = getCampaignDetails() | ||
const campaignDetailsWithOriginalMedium = getCampaignDetails({ | ||
needsTransformation: false | ||
}) | ||
|
||
expect(campaignDetails).to.deep.equal(expectation) | ||
expect(campaignContext).to.deep.equal(campaignDetailsWithOriginalMedium.campaign) | ||
|
||
queryStringStub.restore() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters