Skip to content

Commit e57960e

Browse files
Change segmentio to 'Destination' type (#1008)
Co-authored-by: Daniel Jackins <djackins@twilio.com>
1 parent b5b929e commit e57960e

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

.changeset/lucky-chicken-wink.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@segment/analytics-next': minor
3+
'@segment/analytics-node': minor
4+
---
5+
6+
Change segmentio to destination type

packages/browser/src/browser/__tests__/integration.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ const googleAnalytics: Plugin = {
7575
type: 'destination',
7676
}
7777

78+
const slowPlugin: Plugin = {
79+
...xt,
80+
name: 'Slow Plugin',
81+
type: 'destination',
82+
track: async (ctx) => {
83+
await sleep(3000)
84+
return ctx
85+
},
86+
}
87+
7888
const enrichBilling: Plugin = {
7989
...xt,
8090
name: 'Billing Enrichment',
@@ -574,6 +584,34 @@ describe('Dispatch', () => {
574584
expect(segmentSpy).toHaveBeenCalledWith(boo)
575585
})
576586

587+
it('dispatching to Segmentio not blocked by other destinations', async () => {
588+
const [ajs] = await AnalyticsBrowser.load({
589+
writeKey,
590+
plugins: [slowPlugin],
591+
})
592+
593+
const segmentio = ajs.queue.plugins.find((p) => p.name === 'Segment.io')
594+
const segmentSpy = jest.spyOn(segmentio!, 'track')
595+
596+
await Promise.race([
597+
ajs.track(
598+
'Boo!',
599+
{
600+
total: 25,
601+
userId: '👻',
602+
},
603+
{
604+
integrations: {
605+
All: true,
606+
},
607+
}
608+
),
609+
sleep(100),
610+
])
611+
612+
expect(segmentSpy).toHaveBeenCalled()
613+
})
614+
577615
it('enriches events before dispatching', async () => {
578616
const [ajs] = await AnalyticsBrowser.load({
579617
writeKey,
@@ -611,8 +649,8 @@ describe('Dispatch', () => {
611649
"plugin_time",
612650
"plugin_time",
613651
"plugin_time",
614-
"message_delivered",
615652
"plugin_time",
653+
"message_delivered",
616654
"delivered",
617655
]
618656
`)

packages/browser/src/plugins/segmentio/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function segmentio(
125125

126126
const segmentio: Plugin = {
127127
name: 'Segment.io',
128-
type: 'after',
128+
type: 'destination',
129129
version: '0.1.0',
130130
isLoaded: (): boolean => true,
131131
load: (): Promise<void> => Promise.resolve(),

packages/node/src/plugins/segmentio/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function createNodePlugin(publisher: Publisher): SegmentNodePlugin {
4141

4242
return {
4343
name: 'Segment.io',
44-
type: 'after',
44+
type: 'destination',
4545
version: '1.0.0',
4646
isLoaded: () => true,
4747
load: () => Promise.resolve(),

0 commit comments

Comments
 (0)