Skip to content

Commit

Permalink
Update consent change event name (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Apr 22, 2024
1 parent a102cbb commit 712f592
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-waves-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-consent-tools': patch
---

Update consent change event name
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export abstract class BasePage {
getConsentChangedEvents(): SegmentEvent[] {
const reqBodies = this.getAllTrackingEvents()
const consentEvents = reqBodies.filter(
(el) => el.event === 'Segment Consent Preference'
(el) => el.event === 'Segment Consent Preference Updated'
)
return consentEvents
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ it('should send a track call after waiting for explicit consent', async () => {

const consentChangeEvents = page.getConsentChangedEvents()
expect(consentChangeEvents.length).toBe(1)
expect(consentChangeEvents[0].event).toEqual('Segment Consent Preference')
expect(consentChangeEvents[0].event).toEqual(
'Segment Consent Preference Updated'
)

await browser.waitUntil(() => page.fetchIntegrationReqs.length, {
timeout: 20000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ it('should not wait for consent before sending track call', async () => {
})
consentChangeEvents = page.getConsentChangedEvents()
expect(consentChangeEvents.length).toBe(1)
expect(consentChangeEvents[0].event).toEqual('Segment Consent Preference')
expect(consentChangeEvents[0].event).toEqual(
'Segment Consent Preference Updated'
)
await browser.execute(() => {
return window.analytics.track('sup')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ describe(createWrapper, () => {

// if OnConsentChanged callback is called with categories, it should send event
expect(analyticsTrackSpy).toBeCalledWith(
'Segment Consent Preference',
'Segment Consent Preference Updated',
undefined,
{ consent: { categoryPreferences: { C0001: true, C0002: false } } }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ describe(AnalyticsService, () => {
const mockCategories = { C0001: true, C0002: false }
analyticsService.consentChange(mockCategories)
expect(analyticsMock.track).toBeCalledWith(
'Segment Consent Preference',
'Segment Consent Preference Updated',
undefined,
{ consent: { categoryPreferences: mockCategories } }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class AnalyticsService {
* ```ts
* {
* "type": "track",
* "event": "Segment Consent Preference",
* "event": "Segment Consent Preference Updated",
* "context": {
* "consent": {
* "categoryPreferences" : {
Expand All @@ -184,7 +184,7 @@ export class AnalyticsService {
// not sure if there's a better way to handle this
return console.error(e)
}
const CONSENT_CHANGED_EVENT = 'Segment Consent Preference'
const CONSENT_CHANGED_EVENT = 'Segment Consent Preference Updated'
this.analytics.track(CONSENT_CHANGED_EVENT, undefined, {
consent: { categoryPreferences: categories },
})
Expand Down
4 changes: 2 additions & 2 deletions packages/consent/consent-tools/src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface CreateWrapperSettings {
getCategories: GetCategoriesFunction

/**
* Function to register a listener for consent changes to programatically send a "Segment Consent Preference" event to Segment when consent preferences change.
* Function to register a listener for consent changes to programatically send a "Segment Consent Preference Updated" event to Segment when consent preferences change.
*
* #### Note: The callback requires the categories to be in the shape of { "C0001": true, "C0002": false }, so some normalization may be needed.
* @example
Expand All @@ -77,7 +77,7 @@ export interface CreateWrapperSettings {
* /* event payload
* {
* "type": "track",
* "event": "Segment Consent Preference",
* "event": "Segment Consent Preference Updated",
* "context": {
* "consent": {
* "version": 2,
Expand Down

0 comments on commit 712f592

Please sign in to comment.