-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MAIN] [STRATCONN] added consent for google campaign manager (#2021)
* added consent for google campaign manager * added validation in GCM * change consent default to advertiserId * Added unit test cases * reset config changes * Increased size-limit * Added unit test case
- Loading branch information
1 parent
3f821a6
commit 95d36fe
Showing
4 changed files
with
282 additions
and
2 deletions.
There are no files selected for viewing
185 changes: 185 additions & 0 deletions
185
...ges/browser-destinations/destinations/google-campaign-manager/src/__tests__/index.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,185 @@ | ||
import { Subscription } from '@segment/browser-destination-runtime/types' | ||
import googleCampaignManager, { destination } from '../index' | ||
import { Analytics, Context } from '@segment/analytics-next' | ||
|
||
const subscriptions: Subscription[] = [ | ||
{ | ||
partnerAction: 'salesActivity', | ||
name: 'Sales Activity', | ||
enabled: true, | ||
subscribe: 'type = "track"', | ||
mapping: {} | ||
} | ||
] | ||
|
||
describe('Google Tag for Campaign Manager', () => { | ||
const defaultSettings = { | ||
advertiserId: 'test123', | ||
allowAdPersonalizationSignals: false, | ||
conversionLinker: false | ||
} | ||
beforeEach(async () => { | ||
jest.restoreAllMocks() | ||
|
||
const [googleCampaignManagerPlugin] = await googleCampaignManager({ | ||
...defaultSettings, | ||
subscriptions | ||
}) | ||
jest.spyOn(destination, 'initialize') | ||
|
||
await googleCampaignManagerPlugin.load(Context.system(), {} as Analytics) | ||
}) | ||
|
||
it('should not update consent if enable_consent mode is denied', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: false | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([expect.not.objectContaining(Object.assign({}, ['consent', 'default', {}]))]) | ||
) | ||
}) | ||
|
||
it('should update consent if analytics storage is granted', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
defaultAnalyticsStorageConsentState: 'granted' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { analytics_storage: 'granted' }])) | ||
]) | ||
) | ||
}) | ||
|
||
it('should update consent if analytics storage is denied', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
defaultAnalyticsStorageConsentState: 'denied' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { analytics_storage: 'denied' }])) | ||
]) | ||
) | ||
}) | ||
it('should update consent if Ad storage is granted', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
defaultAdsStorageConsentState: 'granted' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { ad_storage: 'granted' }])) | ||
]) | ||
) | ||
}) | ||
it('should update consent if Ad storage is denied', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
defaultAdsStorageConsentState: 'denied' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { ad_storage: 'denied' }])) | ||
]) | ||
) | ||
}) | ||
it('should update consent if Ad user data is granted', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
adUserDataConsentState: 'granted' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { ad_user_data: 'granted' }])) | ||
]) | ||
) | ||
}) | ||
it('should update consent if Ad user data is denied', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
adUserDataConsentState: 'denied' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { ad_user_data: 'denied' }])) | ||
]) | ||
) | ||
}) | ||
it('should update consent if Ad personalization is granted', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
adPersonalizationConsentState: 'granted' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { ad_personalization: 'granted' }])) | ||
]) | ||
) | ||
}) | ||
it('should update consent if Ad personalization is denied', async () => { | ||
const settings = { | ||
...defaultSettings, | ||
enableConsentMode: true, | ||
adPersonalizationConsentState: 'denied' | ||
} | ||
|
||
const [event] = await googleCampaignManager({ ...settings, subscriptions }) | ||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
|
||
expect(window.dataLayer).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining(Object.assign({}, ['consent', 'default', { ad_personalization: 'denied' }])) | ||
]) | ||
) | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
packages/browser-destinations/destinations/google-campaign-manager/src/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ | |
"size-limit": [ | ||
{ | ||
"path": "dist/web/*/*.js", | ||
"limit": "151 KB" | ||
"limit": "152 KB" | ||
} | ||
] | ||
} |