Skip to content

Commit

Permalink
fix: support screen events on AJS on Segment Destination (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscb authored Jul 14, 2023
1 parent aa56556 commit 48ce3ec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-socks-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': patch
---

Added support for `screen` events for Segment destination
34 changes: 34 additions & 0 deletions packages/browser/src/plugins/segmentio/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,38 @@ describe('Segment.io', () => {
assert(body.to == null)
})
})

describe('#screen', () => {
it('should enqueue section, name and properties', async () => {
await analytics.screen(
'section',
'name',
{ property: true },
{ opt: true }
)

const [url, params] = spyMock.mock.calls[0]
expect(url).toMatchInlineSnapshot(`"https://api.segment.io/v1/s"`)

const body = JSON.parse(params.body)

assert(body.name === 'name')
assert(body.category === 'section')
assert(body.properties.property === true)
assert(body.context.opt === true)
assert(body.timestamp)
})

it('sets properties when name and category are null', async () => {
// @ts-ignore test a valid ajsc page call
await analytics.screen(null, { foo: 'bar' })

const [url, params] = spyMock.mock.calls[0]
expect(url).toMatchInlineSnapshot(`"https://api.segment.io/v1/s"`)

const body = JSON.parse(params.body)

assert(body.properties.foo === 'bar')
})
})
})
1 change: 1 addition & 0 deletions packages/browser/src/plugins/segmentio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export async function segmentio(
page: send,
alias: send,
group: send,
screen: send,
}

// Buffer may already have items if they were previously stored in localStorage.
Expand Down

0 comments on commit 48ce3ec

Please sign in to comment.