From 77448ade6736c169d1087ce9251c50498599e4cd Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Thu, 8 Feb 2024 10:47:49 -0700 Subject: [PATCH 1/3] Check filters by creation name instead of current --- .../browser/src/plugins/schema-filter/__tests__/index.test.ts | 4 ++-- packages/browser/src/plugins/schema-filter/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts b/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts index abc84559d..5e3e66622 100644 --- a/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts +++ b/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts @@ -35,7 +35,7 @@ const settings: LegacySettings = { { // note that Fullstory name contains 'Actions' name: 'Fullstory (Actions)', - creationName: 'Fullstory (Actions)', + creationName: 'Fullstory', libraryName: 'fullstoryDestination', url: 'https://cdn.segment.com/next-integrations/actions/fullstory/35ea1d304f85f3306f48.js', settings: { @@ -472,7 +472,7 @@ describe('schema filter', () => { expect(updateUserProfile.track).toHaveBeenCalled() }) - it('covers different names between remote plugins and integrations', async () => { + it('works when current name differs from creation name', async () => { const filterXt = schemaFilter( { hi: { diff --git a/packages/browser/src/plugins/schema-filter/index.ts b/packages/browser/src/plugins/schema-filter/index.ts index 7c181502e..a43e4dac1 100644 --- a/packages/browser/src/plugins/schema-filter/index.ts +++ b/packages/browser/src/plugins/schema-filter/index.ts @@ -24,7 +24,7 @@ function disabledActionDestinations( const disabledRemotePlugins: string[] = [] ;(settings.remotePlugins ?? []).forEach((p: RemotePlugin) => { disabledIntegrations.forEach((int) => { - if (p.name.includes(int) || int.includes(p.name)) { + if (p.creationName == int) { disabledRemotePlugins.push(p.name) } }) From 413f97c4ed217a4ba059bc28681044be1ee0c7cf Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Thu, 8 Feb 2024 10:55:40 -0700 Subject: [PATCH 2/3] changeset --- .changeset/spicy-fireants-reflect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/spicy-fireants-reflect.md diff --git a/.changeset/spicy-fireants-reflect.md b/.changeset/spicy-fireants-reflect.md new file mode 100644 index 000000000..1b28de67b --- /dev/null +++ b/.changeset/spicy-fireants-reflect.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-next': patch +--- + +Fix schema-filter bug From 0d4e6a7fcc711a459e801729c47500bd57dd3eca Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Mon, 12 Feb 2024 10:41:48 -0700 Subject: [PATCH 3/3] add test --- .../schema-filter/__tests__/index.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts b/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts index 5e3e66622..3e8292a28 100644 --- a/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts +++ b/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts @@ -10,6 +10,8 @@ const settings: LegacySettings = { 'Braze Web Mode (Actions)': {}, // note that Fullstory's name here doesn't contain 'Actions' Fullstory: {}, + 'Google Analytics': {}, + 'Google Analytics 4 Web': {}, 'Segment.io': {}, }, remotePlugins: [ @@ -49,6 +51,19 @@ const settings: LegacySettings = { ], }, }, + { + name: 'Google Analytics 4 Web', + creationName: 'Google Analytics 4 Web', + libraryName: 'google-analytics-4-webDestination', + url: 'https://cdn.segment.com/next-integrations/actions/google-analytics-4-web/bfab87631cbcb7d70964.js', + settings: { + subscriptions: [ + { + partnerAction: 'Custom Event', + }, + ], + }, + }, ], } @@ -92,6 +107,11 @@ const fullstory: Plugin = { name: 'Fullstory (Actions) trackEvent', } +const ga4: Plugin = { + ...trackEvent, + name: 'Google Analytics 4 Web Custom Event', +} + describe('schema filter', () => { let options: SegmentioSettings let filterXt: Plugin @@ -113,6 +133,7 @@ describe('schema filter', () => { jest.spyOn(updateUserProfile, 'track') jest.spyOn(amplitude, 'track') jest.spyOn(fullstory, 'track') + jest.spyOn(ga4, 'track') }) describe('plugins and destinations', () => { @@ -516,5 +537,25 @@ describe('schema filter', () => { expect(updateUserProfile.track).toHaveBeenCalled() expect(fullstory.track).toHaveBeenCalled() }) + + it('doesnt block destinations with similar names', async () => { + const filterXt = schemaFilter( + { + hi: { + enabled: true, + integrations: { + 'Google Analytics': false, + }, + }, + }, + settings + ) + + await ajs.register(segment, ga4, filterXt) + + await ajs.track('hi') + + expect(ga4.track).toHaveBeenCalled() + }) }) })