File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
signals/browser-signals/src/core/signals Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,4 @@ export type { AnalyticsSnippet } from './browser/standalone-interface'
1616export type { MiddlewareFunction } from './plugins/middleware'
1717export { getGlobalAnalytics } from './lib/global-analytics-helper'
1818export { UniversalStorage , Store , StorageObject } from './core/storage'
19+ export { segmentio } from './plugins/segmentio'
Original file line number Diff line number Diff line change 1+ import { SignalsClient } from '../client'
2+
3+ import { createSuccess } from '../../../../../../browser/src/test-helpers/factories'
4+ import unfetch from 'unfetch'
5+ jest . mock ( 'unfetch' )
6+ jest
7+ . mocked ( unfetch )
8+ . mockImplementation ( ( ) => createSuccess ( { integrations : { } } ) )
9+
10+ describe ( SignalsClient , ( ) => {
11+ let client : SignalsClient
12+
13+ beforeEach ( ( ) => {
14+ client = new SignalsClient ( 'Test' )
15+ } )
16+
17+ it ( 'return a ctx from track call' , ( ) => {
18+ expect ( client ) . toBeTruthy ( )
19+ return expect ( client . send ( 'Test' , 'Test' ) ) . resolves . toMatchObject ( {
20+ event : {
21+ anonymousId : expect . any ( String ) ,
22+ context : expect . any ( Object ) ,
23+ event : 'Segment Signal Generated' ,
24+ integrations : { } ,
25+ messageId : expect . any ( String ) ,
26+ properties : {
27+ data : 'Test' ,
28+ index : expect . any ( Number ) ,
29+ type : 'Test' ,
30+ } ,
31+ timestamp : expect . any ( Date ) ,
32+ type : 'track' ,
33+ } ,
34+ } )
35+ } )
36+ } )
Original file line number Diff line number Diff line change 1+ import { Analytics , segmentio } from '@segment/analytics-next'
2+
3+ export class SignalsClient {
4+ private index = 0
5+ private analytics : Analytics
6+
7+ constructor ( writeKey : any ) {
8+ this . analytics = new Analytics ( { writeKey } )
9+ void this . analytics . register (
10+ segmentio ( this . analytics , {
11+ apiHost : 'https://signals.segment.io/v1' ,
12+ apiKey : writeKey ,
13+ deliveryStrategy : {
14+ strategy : 'batching' ,
15+ config : {
16+ size : 100 ,
17+ timeout : 30 * 1000 ,
18+ } ,
19+ } ,
20+ } )
21+ )
22+ }
23+
24+ public send ( type : any , data : any ) : Promise < any > {
25+ return this . analytics
26+ . track ( 'Segment Signal Generated' , {
27+ type,
28+ index : this . index ++ ,
29+ data,
30+ } )
31+ . then ( ( ctx ) => {
32+ return ctx
33+ } )
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments