Skip to content

Commit

Permalink
Change segmentio to 'Destination' type (#1008)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Jackins <djackins@twilio.com>
  • Loading branch information
danieljackins and danieljackins committed Jan 10, 2024
1 parent b5b929e commit e57960e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/lucky-chicken-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@segment/analytics-next': minor
'@segment/analytics-node': minor
---

Change segmentio to destination type
40 changes: 39 additions & 1 deletion packages/browser/src/browser/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -611,8 +649,8 @@ describe('Dispatch', () => {
"plugin_time",
"plugin_time",
"plugin_time",
"message_delivered",
"plugin_time",
"message_delivered",
"delivered",
]
`)
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/plugins/segmentio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => Promise.resolve(),
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/plugins/segmentio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e57960e

Please sign in to comment.