-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update attribution plugin to apply utm params to the `session_st…
…art` event (#619) Co-authored-by: Marvin Liu <[email protected]> Co-authored-by: Kevin Pagtakhan <[email protected]>
- Loading branch information
1 parent
0d9605a
commit bf45ca6
Showing
15 changed files
with
826 additions
and
229 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
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
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
13 changes: 13 additions & 0 deletions
13
packages/analytics-client-common/src/attribution/campaign-helper.ts
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,13 @@ | ||
import { Event, IdentifyOperation, IdentifyUserProperties } from '@amplitude/analytics-types'; | ||
import { BASE_CAMPAIGN } from './constants'; | ||
|
||
export const isCampaignEvent = (event: Event) => { | ||
if (event.user_properties) { | ||
const properties = event.user_properties as IdentifyUserProperties; | ||
const $set = properties[IdentifyOperation.SET] || {}; | ||
const $unset = properties[IdentifyOperation.UNSET] || {}; | ||
const userProperties = [...Object.keys($set), ...Object.keys($unset)]; | ||
return Object.keys(BASE_CAMPAIGN).every((value) => userProperties.includes(value)); | ||
} | ||
return false; | ||
}; |
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
38 changes: 38 additions & 0 deletions
38
packages/analytics-client-common/test/attribution/campaign-helper.test.ts
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,38 @@ | ||
import { Identify } from '@amplitude/analytics-core'; | ||
import { isCampaignEvent } from '../../src/attribution/campaign-helper'; | ||
import { BASE_CAMPAIGN } from '../../src/attribution/constants'; | ||
|
||
describe('isCampaignEvent', () => { | ||
test('should return false with undefined user props', () => { | ||
expect( | ||
isCampaignEvent({ | ||
event_type: 'event_type', | ||
}), | ||
).toBe(false); | ||
}); | ||
|
||
test('should return false with empty user props', () => { | ||
expect( | ||
isCampaignEvent({ | ||
event_type: 'event_type', | ||
user_properties: {}, | ||
}), | ||
).toBe(false); | ||
}); | ||
|
||
test('should return true', () => { | ||
const identifyEvent = Object.entries(BASE_CAMPAIGN).reduce((identify, [key, value]) => { | ||
if (value) { | ||
return identify.set(key, value); | ||
} | ||
return identify.unset(key); | ||
}, new Identify()); | ||
|
||
expect( | ||
isCampaignEvent({ | ||
event_type: 'event_type', | ||
user_properties: identifyEvent.getUserProperties(), | ||
}), | ||
).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.