Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-dolphins-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-consent-tools': patch
---

Fix filtering of non-consented integrations
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,68 @@ describe(createWrapper, () => {
updatedCDNSettings
)
})

it('should filter ALL non-consented remote plugins when multiple integrations need to be blocked', async () => {
const mockCdnSettings = cdnSettingsBuilder
.addActionDestinationSettings(
{
creationName: 'GoogleAnalytics',
consentSettings: {
categories: ['Analytics'],
},
},
{
creationName: 'FacebookPixel',
consentSettings: {
categories: ['Advertising'],
},
},
{
creationName: 'TikTokPixel',
consentSettings: {
categories: ['Advertising'],
},
},
{
creationName: 'PinterestTag',
consentSettings: {
categories: ['Advertising'],
},
}
)
.build()

wrapTestAnalytics({
getCategories: () => ({ Analytics: true }), // Only Analytics consented, NOT Advertising
})

await analytics.load({
...DEFAULT_LOAD_SETTINGS,
cdnSettings: mockCdnSettings,
})

expect(analyticsLoadSpy).toBeCalled()
const { updatedCDNSettings } = getAnalyticsLoadLastCall()

expect(typeof updatedCDNSettings.remotePlugins).toBe('object')

// Only GoogleAnalytics should be present - all Advertising integrations should be filtered
assertIntegrationsContainOnly(
['GoogleAnalytics'],
mockCdnSettings,
updatedCDNSettings
)

const remotePluginNames = updatedCDNSettings.remotePlugins?.map(
(p) => p.creationName
)

// Explicitly verify that all Advertising integrations are blocked
expect(remotePluginNames).not.toContain('FacebookPixel')
expect(remotePluginNames).not.toContain('TikTokPixel')
expect(remotePluginNames).not.toContain('PinterestTag')
expect(remotePluginNames).toContain('GoogleAnalytics')
})
})

describe('shouldDisableSegment', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const filterDeviceModeDestinationsForOptIn = (
for (const creationName in integrations) {
if (!_shouldEnableIntegrationHelper(creationName)) {
logger.debug(`Disabled (opt-in): ${creationName}`)
cdnSettingsCopy.remotePlugins = remotePlugins?.filter(
cdnSettingsCopy.remotePlugins = cdnSettingsCopy.remotePlugins?.filter(
(p) => p.creationName !== creationName
)
// remove disabled classic destinations and locally-installed action destinations
Expand Down