File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
packages/browser/src/plugins/segmentio Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @segment/analytics-next ' : patch
3+ ---
4+
5+ Added support for ` screen ` events for Segment destination
Original file line number Diff line number Diff 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} )
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments