Skip to content

Commit 1e26961

Browse files
authored
Fix filtering of non-consented device mode integrations (#1328)
1 parent 235ddf9 commit 1e26961

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.changeset/nine-dolphins-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-consent-tools': patch
3+
---
4+
5+
Fix filtering of non-consented integrations

packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,68 @@ describe(createWrapper, () => {
424424
updatedCDNSettings
425425
)
426426
})
427+
428+
it('should filter ALL non-consented remote plugins when multiple integrations need to be blocked', async () => {
429+
const mockCdnSettings = cdnSettingsBuilder
430+
.addActionDestinationSettings(
431+
{
432+
creationName: 'GoogleAnalytics',
433+
consentSettings: {
434+
categories: ['Analytics'],
435+
},
436+
},
437+
{
438+
creationName: 'FacebookPixel',
439+
consentSettings: {
440+
categories: ['Advertising'],
441+
},
442+
},
443+
{
444+
creationName: 'TikTokPixel',
445+
consentSettings: {
446+
categories: ['Advertising'],
447+
},
448+
},
449+
{
450+
creationName: 'PinterestTag',
451+
consentSettings: {
452+
categories: ['Advertising'],
453+
},
454+
}
455+
)
456+
.build()
457+
458+
wrapTestAnalytics({
459+
getCategories: () => ({ Analytics: true }), // Only Analytics consented, NOT Advertising
460+
})
461+
462+
await analytics.load({
463+
...DEFAULT_LOAD_SETTINGS,
464+
cdnSettings: mockCdnSettings,
465+
})
466+
467+
expect(analyticsLoadSpy).toBeCalled()
468+
const { updatedCDNSettings } = getAnalyticsLoadLastCall()
469+
470+
expect(typeof updatedCDNSettings.remotePlugins).toBe('object')
471+
472+
// Only GoogleAnalytics should be present - all Advertising integrations should be filtered
473+
assertIntegrationsContainOnly(
474+
['GoogleAnalytics'],
475+
mockCdnSettings,
476+
updatedCDNSettings
477+
)
478+
479+
const remotePluginNames = updatedCDNSettings.remotePlugins?.map(
480+
(p) => p.creationName
481+
)
482+
483+
// Explicitly verify that all Advertising integrations are blocked
484+
expect(remotePluginNames).not.toContain('FacebookPixel')
485+
expect(remotePluginNames).not.toContain('TikTokPixel')
486+
expect(remotePluginNames).not.toContain('PinterestTag')
487+
expect(remotePluginNames).toContain('GoogleAnalytics')
488+
})
427489
})
428490

429491
describe('shouldDisableSegment', () => {

packages/consent/consent-tools/src/domain/blocking-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const filterDeviceModeDestinationsForOptIn = (
101101
for (const creationName in integrations) {
102102
if (!_shouldEnableIntegrationHelper(creationName)) {
103103
logger.debug(`Disabled (opt-in): ${creationName}`)
104-
cdnSettingsCopy.remotePlugins = remotePlugins?.filter(
104+
cdnSettingsCopy.remotePlugins = cdnSettingsCopy.remotePlugins?.filter(
105105
(p) => p.creationName !== creationName
106106
)
107107
// remove disabled classic destinations and locally-installed action destinations

0 commit comments

Comments
 (0)