Skip to content

Commit 48ce3ec

Browse files
authored
fix: support screen events on AJS on Segment Destination (#896)
1 parent aa56556 commit 48ce3ec

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.changeset/shy-socks-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
Added support for `screen` events for Segment destination

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,38 @@ describe('Segment.io', () => {
288288
assert(body.to == null)
289289
})
290290
})
291+
292+
describe('#screen', () => {
293+
it('should enqueue section, name and properties', async () => {
294+
await analytics.screen(
295+
'section',
296+
'name',
297+
{ property: true },
298+
{ opt: true }
299+
)
300+
301+
const [url, params] = spyMock.mock.calls[0]
302+
expect(url).toMatchInlineSnapshot(`"https://api.segment.io/v1/s"`)
303+
304+
const body = JSON.parse(params.body)
305+
306+
assert(body.name === 'name')
307+
assert(body.category === 'section')
308+
assert(body.properties.property === true)
309+
assert(body.context.opt === true)
310+
assert(body.timestamp)
311+
})
312+
313+
it('sets properties when name and category are null', async () => {
314+
// @ts-ignore test a valid ajsc page call
315+
await analytics.screen(null, { foo: 'bar' })
316+
317+
const [url, params] = spyMock.mock.calls[0]
318+
expect(url).toMatchInlineSnapshot(`"https://api.segment.io/v1/s"`)
319+
320+
const body = JSON.parse(params.body)
321+
322+
assert(body.properties.foo === 'bar')
323+
})
324+
})
291325
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export async function segmentio(
149149
page: send,
150150
alias: send,
151151
group: send,
152+
screen: send,
152153
}
153154

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

0 commit comments

Comments
 (0)