@@ -15,7 +15,7 @@ use chrono::prelude::*;
15
15
16
16
// constants and reserved keywords
17
17
const NAME : & str = "RudderStack Rust SDK" ;
18
- const VERSION : & str = "1.1.3 " ;
18
+ const VERSION : & str = "1.1.4 " ;
19
19
static RESERVED_KEYS : [ & str ; 1 ] = [ "library" ] ;
20
20
const CHANNEL : & str = "server" ;
21
21
@@ -237,8 +237,8 @@ pub fn parse_alias(msg:&Alias)-> Ruddermessage{
237
237
238
238
// modify batch payload to rudder format
239
239
pub fn parse_batch ( msg : & Batch ) -> Ruddermessage {
240
- let mut modified_context = get_default_context ( ) ;
241
- merge ( & mut modified_context , msg. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ) ;
240
+ let default_context = get_default_context ( ) ;
241
+ let batch_context = msg. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
242
242
243
243
let original_timestamp;
244
244
let sent_at = Utc :: now ( ) ;
@@ -253,6 +253,11 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
253
253
for i in & msg. batch {
254
254
match i {
255
255
BatchMessage :: Identify ( a_) =>{
256
+ let mut event_context: Value = a_. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
257
+ let mut final_context: Value = batch_context. clone ( ) ;
258
+ merge ( & mut final_context, event_context. clone ( ) ) ;
259
+ merge ( & mut final_context, default_context. clone ( ) ) ;
260
+
256
261
batch. push ( Rudderbatchmessage :: Identify ( Rudderidentify
257
262
{
258
263
user_id : a_. user_id . clone ( ) ,
@@ -261,12 +266,17 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
261
266
original_timestamp : original_timestamp,
262
267
sent_at : Some ( sent_at) ,
263
268
integrations : a_. integrations . clone ( ) ,
264
- context : Some ( modified_context . clone ( ) ) ,
269
+ context : Some ( final_context ) ,
265
270
r#type : String :: from ( "identify" ) ,
266
271
channel : CHANNEL . to_string ( )
267
272
} ) ) ;
268
273
} ,
269
274
BatchMessage :: Track ( a_) =>{
275
+ let mut event_context: Value = a_. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
276
+ let mut final_context: Value = batch_context. clone ( ) ;
277
+ merge ( & mut final_context, event_context. clone ( ) ) ;
278
+ merge ( & mut final_context, default_context. clone ( ) ) ;
279
+
270
280
batch. push ( Rudderbatchmessage :: Track (
271
281
Ruddertrack {
272
282
user_id : a_. user_id . clone ( ) ,
@@ -276,13 +286,18 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
276
286
original_timestamp : original_timestamp,
277
287
sent_at : Some ( sent_at) ,
278
288
integrations : a_. integrations . clone ( ) ,
279
- context : Some ( modified_context . clone ( ) ) ,
289
+ context : Some ( final_context ) ,
280
290
r#type : String :: from ( "track" ) ,
281
291
channel : CHANNEL . to_string ( )
282
292
}
283
293
) ) ;
284
294
} ,
285
295
BatchMessage :: Page ( a_) =>{
296
+ let mut event_context: Value = a_. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
297
+ let mut final_context: Value = batch_context. clone ( ) ;
298
+ merge ( & mut final_context, event_context. clone ( ) ) ;
299
+ merge ( & mut final_context, default_context. clone ( ) ) ;
300
+
286
301
batch. push ( Rudderbatchmessage :: Page (
287
302
Rudderpage {
288
303
user_id : a_. user_id . clone ( ) ,
@@ -292,13 +307,18 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
292
307
original_timestamp : original_timestamp,
293
308
sent_at : Some ( sent_at) ,
294
309
integrations : a_. integrations . clone ( ) ,
295
- context : Some ( modified_context . clone ( ) ) ,
310
+ context : Some ( final_context ) ,
296
311
r#type : String :: from ( "page" ) ,
297
312
channel : CHANNEL . to_string ( )
298
313
}
299
314
) ) ;
300
315
} ,
301
316
BatchMessage :: Screen ( a_) =>{
317
+ let mut event_context: Value = a_. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
318
+ let mut final_context: Value = batch_context. clone ( ) ;
319
+ merge ( & mut final_context, event_context. clone ( ) ) ;
320
+ merge ( & mut final_context, default_context. clone ( ) ) ;
321
+
302
322
batch. push ( Rudderbatchmessage :: Screen (
303
323
Rudderscreen {
304
324
user_id : a_. user_id . clone ( ) ,
@@ -308,13 +328,18 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
308
328
original_timestamp : original_timestamp,
309
329
sent_at : Some ( sent_at) ,
310
330
integrations : a_. integrations . clone ( ) ,
311
- context : Some ( modified_context . clone ( ) ) ,
331
+ context : Some ( final_context ) ,
312
332
r#type : String :: from ( "screen" ) ,
313
333
channel : CHANNEL . to_string ( )
314
334
}
315
335
) ) ;
316
336
} ,
317
337
BatchMessage :: Group ( a_) =>{
338
+ let mut event_context: Value = a_. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
339
+ let mut final_context: Value = batch_context. clone ( ) ;
340
+ merge ( & mut final_context, event_context. clone ( ) ) ;
341
+ merge ( & mut final_context, default_context. clone ( ) ) ;
342
+
318
343
batch. push ( Rudderbatchmessage :: Group (
319
344
Ruddergroup {
320
345
user_id : a_. user_id . clone ( ) ,
@@ -324,13 +349,18 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
324
349
original_timestamp : original_timestamp,
325
350
sent_at : Some ( sent_at) ,
326
351
integrations : a_. integrations . clone ( ) ,
327
- context : Some ( modified_context . clone ( ) ) ,
352
+ context : Some ( final_context ) ,
328
353
r#type : String :: from ( "group" ) ,
329
354
channel : CHANNEL . to_string ( )
330
355
}
331
356
) ) ;
332
357
} ,
333
358
BatchMessage :: Alias ( a_) =>{
359
+ let mut event_context: Value = a_. context . clone ( ) . unwrap_or ( json ! ( { } ) ) ;
360
+ let mut final_context: Value = batch_context. clone ( ) ;
361
+ merge ( & mut final_context, event_context. clone ( ) ) ;
362
+ merge ( & mut final_context, default_context. clone ( ) ) ;
363
+
334
364
batch. push ( Rudderbatchmessage :: Alias (
335
365
Rudderalias {
336
366
user_id : a_. user_id . clone ( ) ,
@@ -339,7 +369,7 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
339
369
original_timestamp : original_timestamp,
340
370
sent_at : Some ( sent_at) ,
341
371
integrations : a_. integrations . clone ( ) ,
342
- context : Some ( modified_context . clone ( ) ) ,
372
+ context : Some ( final_context ) ,
343
373
r#type : String :: from ( "alias" ) ,
344
374
channel : CHANNEL . to_string ( )
345
375
}
@@ -352,7 +382,7 @@ pub fn parse_batch(msg:&Batch)-> Ruddermessage{
352
382
Rudderbatch {
353
383
batch : batch,
354
384
integrations : msg. integrations . clone ( ) ,
355
- context : Some ( modified_context ) ,
385
+ context : Some ( batch_context ) ,
356
386
r#type : String :: from ( "batch" ) ,
357
387
original_timestamp : original_timestamp,
358
388
sent_at : Some ( sent_at) ,
0 commit comments