@@ -66,6 +66,11 @@ export class TelemetryClient {
66
66
return this . #debug
67
67
}
68
68
69
+ page ( name : string , properties : Properties = { } ) : void {
70
+ this . #log( 'page' , name , properties )
71
+ this . #push( { type : 'page' , name, properties } )
72
+ }
73
+
69
74
screen ( name : string , properties : Properties = { } ) : void {
70
75
this . #log( 'screen' , name , properties )
71
76
this . #push( { type : 'screen' , name, properties } )
@@ -76,18 +81,12 @@ export class TelemetryClient {
76
81
this . #push( { type : 'track' , event, properties } )
77
82
}
78
83
79
- alias ( userId : string , previousId ?: string ) : void {
80
- const resolvedPreviousId =
81
- previousId ?? this . #user?. userId ?? this . #anonymousId
82
- if ( resolvedPreviousId == null ) {
83
- throw new Error ( 'Cannot resolve previous id' )
84
- }
85
- this . #log( 'alias' , userId , resolvedPreviousId )
84
+ group ( groupId : string , traits : Traits = { } ) : void {
85
+ this . #log( 'group' , groupId , traits )
86
86
this . #push( {
87
- type : 'alias' ,
88
- userId,
89
- previousId : resolvedPreviousId ,
90
- anonymousId : undefined ,
87
+ type : 'group' ,
88
+ groupId,
89
+ traits,
91
90
} )
92
91
}
93
92
@@ -111,6 +110,21 @@ export class TelemetryClient {
111
110
} )
112
111
}
113
112
113
+ alias ( userId : string , previousId ?: string ) : void {
114
+ const resolvedPreviousId =
115
+ previousId ?? this . #user?. userId ?? this . #anonymousId
116
+ if ( resolvedPreviousId == null ) {
117
+ throw new Error ( 'Cannot resolve previous id' )
118
+ }
119
+ this . #log( 'alias' , userId , resolvedPreviousId )
120
+ this . #push( {
121
+ type : 'alias' ,
122
+ userId,
123
+ previousId : resolvedPreviousId ,
124
+ anonymousId : undefined ,
125
+ } )
126
+ }
127
+
114
128
get #context( ) : Context {
115
129
return {
116
130
...( this . #user?. traits == null ? { } : { traits : this . #user. traits } ) ,
@@ -164,6 +178,13 @@ export class TelemetryClient {
164
178
}
165
179
}
166
180
181
+ // https://segment.com/docs/connections/spec/screen/
182
+ interface PageSpec {
183
+ type : 'page'
184
+ name : string
185
+ properties : Properties
186
+ }
187
+
167
188
// https://segment.com/docs/connections/spec/screen/
168
189
interface ScreenSpec {
169
190
type : 'screen'
@@ -178,6 +199,13 @@ interface TrackSpec {
178
199
properties : Properties
179
200
}
180
201
202
+ // https://segment.com/docs/connections/spec/group/
203
+ interface GroupSpec {
204
+ type : 'group'
205
+ groupId : string
206
+ traits : Traits
207
+ }
208
+
181
209
// https://segment.com/docs/connections/spec/identify/
182
210
interface IdentifySpec {
183
211
type : 'identify'
@@ -218,7 +246,13 @@ interface User {
218
246
219
247
type Payload = Omit < Message , 'userId' > & CommonSpec
220
248
221
- type Message = ScreenSpec | TrackSpec | IdentifySpec | AliasSpec
249
+ type Message =
250
+ | PageSpec
251
+ | ScreenSpec
252
+ | TrackSpec
253
+ | GroupSpec
254
+ | IdentifySpec
255
+ | AliasSpec
222
256
223
257
type Traits = TelemetryRecord
224
258
0 commit comments