1
+ using System ;
1
2
using global ::System . Runtime . Serialization ;
2
3
using Segment . Serialization ;
3
4
@@ -12,15 +13,16 @@ public partial class Analytics
12
13
/// </summary>
13
14
/// <param name="name">Name of the action</param>
14
15
/// <param name="properties">Properties to describe the action</param>
15
- public virtual void Track ( string name , JsonObject properties = default )
16
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
17
+ public virtual void Track ( string name , JsonObject properties = default , Func < RawEvent , RawEvent > enrichment = default )
16
18
{
17
19
if ( properties == null )
18
20
{
19
21
properties = new JsonObject ( ) ;
20
22
}
21
23
22
24
var trackEvent = new TrackEvent ( name , properties ) ;
23
- Process ( trackEvent ) ;
25
+ Process ( trackEvent , enrichment ) ;
24
26
}
25
27
26
28
/// <summary>
@@ -30,17 +32,18 @@ public virtual void Track(string name, JsonObject properties = default)
30
32
/// </summary>
31
33
/// <param name="name">Name of the action</param>
32
34
/// <param name="properties">Properties to describe the action</param>
35
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
33
36
/// <typeparam name="T">Type that implements <see cref="ISerializable"/></typeparam>
34
- public virtual void Track < T > ( string name , T properties = default ) where T : ISerializable
37
+ public virtual void Track < T > ( string name , T properties = default , Func < RawEvent , RawEvent > enrichment = default ) where T : ISerializable
35
38
{
36
39
if ( properties == null )
37
40
{
38
- Track ( name ) ;
41
+ Track ( name , enrichment : enrichment ) ;
39
42
}
40
43
else
41
44
{
42
45
string json = JsonUtility . ToJson ( properties ) ;
43
- Track ( name , JsonUtility . FromJson < JsonObject > ( json ) ) ;
46
+ Track ( name , JsonUtility . FromJson < JsonObject > ( json ) , enrichment ) ;
44
47
}
45
48
}
46
49
@@ -59,7 +62,8 @@ public virtual void Track<T>(string name, T properties = default) where T : ISer
59
62
/// </summary>
60
63
/// <param name="userId">Unique identifier which you recognize a user by in your own database</param>
61
64
/// <param name="traits">Traits about the user</param>
62
- public virtual void Identify ( string userId , JsonObject traits = default )
65
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
66
+ public virtual void Identify ( string userId , JsonObject traits = default , Func < RawEvent , RawEvent > enrichment = default )
63
67
{
64
68
if ( traits == null )
65
69
{
@@ -76,7 +80,7 @@ public virtual void Identify(string userId, JsonObject traits = default)
76
80
} ) ;
77
81
78
82
var identifyEvent = new IdentifyEvent ( userId , traits ) ;
79
- Process ( identifyEvent ) ;
83
+ Process ( identifyEvent , enrichment ) ;
80
84
}
81
85
82
86
/// <summary>
@@ -93,7 +97,8 @@ public virtual void Identify(string userId, JsonObject traits = default)
93
97
/// info.
94
98
/// </summary>
95
99
/// <param name="traits">Traits about the user</param>
96
- public virtual void Identify ( JsonObject traits )
100
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
101
+ public virtual void Identify ( JsonObject traits , Func < RawEvent , RawEvent > enrichment = default )
97
102
{
98
103
if ( traits == null )
99
104
{
@@ -109,7 +114,7 @@ public virtual void Identify(JsonObject traits)
109
114
} ) ;
110
115
111
116
var identifyEvent = new IdentifyEvent ( _userInfo . _userId , traits ) ;
112
- Process ( identifyEvent ) ;
117
+ Process ( identifyEvent , enrichment ) ;
113
118
}
114
119
115
120
/// <summary>
@@ -127,17 +132,18 @@ public virtual void Identify(JsonObject traits)
127
132
/// </summary>
128
133
/// <param name="userId">Unique identifier which you recognize a user by in your own database</param>
129
134
/// <param name="traits">Traits about the user</param>
135
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
130
136
/// <typeparam name="T">Type that implements <see cref="ISerializable"/></typeparam>
131
- public virtual void Identify < T > ( string userId , T traits = default ) where T : ISerializable
137
+ public virtual void Identify < T > ( string userId , T traits = default , Func < RawEvent , RawEvent > enrichment = default ) where T : ISerializable
132
138
{
133
139
if ( traits == null )
134
140
{
135
- Identify ( userId ) ;
141
+ Identify ( userId , enrichment : enrichment ) ;
136
142
}
137
143
else
138
144
{
139
145
string json = JsonUtility . ToJson ( traits ) ;
140
- Identify ( userId , JsonUtility . FromJson < JsonObject > ( json ) ) ;
146
+ Identify ( userId , JsonUtility . FromJson < JsonObject > ( json ) , enrichment ) ;
141
147
}
142
148
}
143
149
@@ -155,17 +161,18 @@ public virtual void Identify<T>(string userId, T traits = default) where T : ISe
155
161
/// info.
156
162
/// </summary>
157
163
/// <param name="traits">Traits about the user</param>
164
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
158
165
/// <typeparam name="T">Type that implements <see cref="ISerializable"/></typeparam>
159
- public virtual void Identify < T > ( T traits ) where T : ISerializable
166
+ public virtual void Identify < T > ( T traits , Func < RawEvent , RawEvent > enrichment = default ) where T : ISerializable
160
167
{
161
168
if ( traits == null )
162
169
{
163
- Identify ( new JsonObject ( ) ) ;
170
+ Identify ( new JsonObject ( ) , enrichment ) ;
164
171
}
165
172
else
166
173
{
167
174
string json = JsonUtility . ToJson ( traits ) ;
168
- Identify ( JsonUtility . FromJson < JsonObject > ( json ) ) ;
175
+ Identify ( JsonUtility . FromJson < JsonObject > ( json ) , enrichment ) ;
169
176
}
170
177
}
171
178
@@ -177,14 +184,15 @@ public virtual void Identify<T>(T traits) where T : ISerializable
177
184
/// <param name="title">A name for the screen</param>
178
185
/// <param name="properties">Properties to add extra information to this call</param>
179
186
/// <param name="category">A category to describe the screen</param>
180
- public virtual void Screen ( string title , JsonObject properties = default , string category = "" )
187
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
188
+ public virtual void Screen ( string title , JsonObject properties = default , string category = "" , Func < RawEvent , RawEvent > enrichment = default )
181
189
{
182
190
if ( properties == null )
183
191
{
184
192
properties = new JsonObject ( ) ;
185
193
}
186
194
var screenEvent = new ScreenEvent ( category , title , properties ) ;
187
- Process ( screenEvent ) ;
195
+ Process ( screenEvent , enrichment ) ;
188
196
}
189
197
190
198
/// <summary>
@@ -195,17 +203,18 @@ public virtual void Screen(string title, JsonObject properties = default, string
195
203
/// <param name="title">A name for the screen</param>
196
204
/// <param name="properties">Properties to add extra information to this call</param>
197
205
/// <param name="category">A category to describe the screen</param>
206
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
198
207
/// <typeparam name="T">Type that implements <see cref="ISerializable"/></typeparam>
199
- public virtual void Screen < T > ( string title , T properties = default , string category = "" ) where T : ISerializable
208
+ public virtual void Screen < T > ( string title , T properties = default , string category = "" , Func < RawEvent , RawEvent > enrichment = default ) where T : ISerializable
200
209
{
201
210
if ( properties == null )
202
211
{
203
- Screen ( title , category : category ) ;
212
+ Screen ( title , category : category , enrichment : enrichment ) ;
204
213
}
205
214
else
206
215
{
207
216
string json = JsonUtility . ToJson ( properties ) ;
208
- Screen ( title , JsonUtility . FromJson < JsonObject > ( json ) , category ) ;
217
+ Screen ( title , JsonUtility . FromJson < JsonObject > ( json ) , category , enrichment ) ;
209
218
}
210
219
}
211
220
@@ -218,14 +227,15 @@ public virtual void Screen<T>(string title, T properties = default, string categ
218
227
/// <param name="title">A name for the page</param>
219
228
/// <param name="properties">Properties to add extra information to this call</param>
220
229
/// <param name="category">A category to describe the page</param>
221
- public virtual void Page ( string title , JsonObject properties = default , string category = "" )
230
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
231
+ public virtual void Page ( string title , JsonObject properties = default , string category = "" , Func < RawEvent , RawEvent > enrichment = default )
222
232
{
223
233
if ( properties == null )
224
234
{
225
235
properties = new JsonObject ( ) ;
226
236
}
227
237
var pageEvent = new PageEvent ( category , title , properties ) ;
228
- Process ( pageEvent ) ;
238
+ Process ( pageEvent , enrichment ) ;
229
239
}
230
240
231
241
/// <summary>
@@ -236,17 +246,18 @@ public virtual void Page(string title, JsonObject properties = default, string c
236
246
/// <param name="title">A name for the page</param>
237
247
/// <param name="properties">Properties to add extra information to this call</param>
238
248
/// <param name="category">A category to describe the page</param>
249
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
239
250
/// <typeparam name="T">Type that implements <see cref="ISerializable"/></typeparam>
240
- public virtual void Page < T > ( string title , T properties = default , string category = "" ) where T : ISerializable
251
+ public virtual void Page < T > ( string title , T properties = default , string category = "" , Func < RawEvent , RawEvent > enrichment = default ) where T : ISerializable
241
252
{
242
253
if ( properties == null )
243
254
{
244
- Page ( title , category : category ) ;
255
+ Page ( title , category : category , enrichment : enrichment ) ;
245
256
}
246
257
else
247
258
{
248
259
string json = JsonUtility . ToJson ( properties ) ;
249
- Page ( title , JsonUtility . FromJson < JsonObject > ( json ) , category ) ;
260
+ Page ( title , JsonUtility . FromJson < JsonObject > ( json ) , category , enrichment ) ;
250
261
}
251
262
}
252
263
@@ -259,14 +270,15 @@ public virtual void Page<T>(string title, T properties = default, string categor
259
270
/// </summary>
260
271
/// <param name="groupId">Unique identifier which you recognize a group by in your own database</param>
261
272
/// <param name="traits">Traits about the group</param>
262
- public virtual void Group ( string groupId , JsonObject traits = default )
273
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
274
+ public virtual void Group ( string groupId , JsonObject traits = default , Func < RawEvent , RawEvent > enrichment = default )
263
275
{
264
276
if ( traits == null )
265
277
{
266
278
traits = new JsonObject ( ) ;
267
279
}
268
280
var groupEvent = new GroupEvent ( groupId , traits ) ;
269
- Process ( groupEvent ) ;
281
+ Process ( groupEvent , enrichment ) ;
270
282
}
271
283
272
284
/// <summary>
@@ -278,17 +290,18 @@ public virtual void Group(string groupId, JsonObject traits = default)
278
290
/// </summary>
279
291
/// <param name="groupId">Unique identifier which you recognize a group by in your own database</param>
280
292
/// <param name="traits">Traits about the group</param>
293
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
281
294
/// <typeparam name="T">Type that implements <see cref="ISerializable"/></typeparam>
282
- public virtual void Group < T > ( string groupId , T traits = default ) where T : ISerializable
295
+ public virtual void Group < T > ( string groupId , T traits = default , Func < RawEvent , RawEvent > enrichment = default ) where T : ISerializable
283
296
{
284
297
if ( traits == null )
285
298
{
286
- Group ( groupId ) ;
299
+ Group ( groupId , enrichment : enrichment ) ;
287
300
}
288
301
else
289
302
{
290
303
string json = JsonUtility . ToJson ( traits ) ;
291
- Group ( groupId , JsonUtility . FromJson < JsonObject > ( json ) ) ;
304
+ Group ( groupId , JsonUtility . FromJson < JsonObject > ( json ) , enrichment ) ;
292
305
}
293
306
}
294
307
@@ -301,7 +314,8 @@ public virtual void Group<T>(string groupId, T traits = default) where T : ISeri
301
314
/// <param name="newId">The new ID you want to alias the existing ID to. The existing ID will be either
302
315
/// the previousId if you have called identify, or the anonymous ID.
303
316
/// </param>
304
- public virtual void Alias ( string newId )
317
+ /// <param name="enrichment">a closure that enables enrichment on the generated event</param>
318
+ public virtual void Alias ( string newId , Func < RawEvent , RawEvent > enrichment = default )
305
319
{
306
320
var aliasEvent = new AliasEvent ( newId , _userInfo . _userId ?? _userInfo . _anonymousId ) ;
307
321
@@ -312,7 +326,7 @@ public virtual void Alias(string newId)
312
326
await Store . Dispatch < UserInfo . SetUserIdAction , UserInfo > ( new UserInfo . SetUserIdAction ( newId ) ) ;
313
327
} ) ;
314
328
315
- Process ( aliasEvent ) ;
329
+ Process ( aliasEvent , enrichment ) ;
316
330
}
317
331
}
318
332
}
0 commit comments