diff --git a/.changeset/lucky-chicken-wink.md b/.changeset/lucky-chicken-wink.md new file mode 100644 index 000000000..b3d23c41b --- /dev/null +++ b/.changeset/lucky-chicken-wink.md @@ -0,0 +1,6 @@ +--- +'@segment/analytics-next': minor +'@segment/analytics-node': minor +--- + +Change segmentio to destination type diff --git a/packages/browser/src/browser/__tests__/integration.test.ts b/packages/browser/src/browser/__tests__/integration.test.ts index 28f813e33..5afc6d344 100644 --- a/packages/browser/src/browser/__tests__/integration.test.ts +++ b/packages/browser/src/browser/__tests__/integration.test.ts @@ -75,6 +75,16 @@ const googleAnalytics: Plugin = { type: 'destination', } +const slowPlugin: Plugin = { + ...xt, + name: 'Slow Plugin', + type: 'destination', + track: async (ctx) => { + await sleep(3000) + return ctx + }, +} + const enrichBilling: Plugin = { ...xt, name: 'Billing Enrichment', @@ -574,6 +584,34 @@ describe('Dispatch', () => { expect(segmentSpy).toHaveBeenCalledWith(boo) }) + it('dispatching to Segmentio not blocked by other destinations', async () => { + const [ajs] = await AnalyticsBrowser.load({ + writeKey, + plugins: [slowPlugin], + }) + + const segmentio = ajs.queue.plugins.find((p) => p.name === 'Segment.io') + const segmentSpy = jest.spyOn(segmentio!, 'track') + + await Promise.race([ + ajs.track( + 'Boo!', + { + total: 25, + userId: '👻', + }, + { + integrations: { + All: true, + }, + } + ), + sleep(100), + ]) + + expect(segmentSpy).toHaveBeenCalled() + }) + it('enriches events before dispatching', async () => { const [ajs] = await AnalyticsBrowser.load({ writeKey, @@ -611,8 +649,8 @@ describe('Dispatch', () => { "plugin_time", "plugin_time", "plugin_time", - "message_delivered", "plugin_time", + "message_delivered", "delivered", ] `) diff --git a/packages/browser/src/plugins/segmentio/index.ts b/packages/browser/src/plugins/segmentio/index.ts index 38f012d74..b5b0bdd7f 100644 --- a/packages/browser/src/plugins/segmentio/index.ts +++ b/packages/browser/src/plugins/segmentio/index.ts @@ -125,7 +125,7 @@ export function segmentio( const segmentio: Plugin = { name: 'Segment.io', - type: 'after', + type: 'destination', version: '0.1.0', isLoaded: (): boolean => true, load: (): Promise => Promise.resolve(), diff --git a/packages/node/src/plugins/segmentio/index.ts b/packages/node/src/plugins/segmentio/index.ts index 56c793b02..7ffed2feb 100644 --- a/packages/node/src/plugins/segmentio/index.ts +++ b/packages/node/src/plugins/segmentio/index.ts @@ -41,7 +41,7 @@ export function createNodePlugin(publisher: Publisher): SegmentNodePlugin { return { name: 'Segment.io', - type: 'after', + type: 'destination', version: '1.0.0', isLoaded: () => true, load: () => Promise.resolve(),