@snowplow/react-native-tracker 1.0.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  //
2
2
  // RNSnowplowTracker.m
3
3
  //
4
- // Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
4
+ // Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
5
5
  //
6
6
  // This program is licensed to you under the Apache License Version 2.0,
7
7
  // and you may not use this file except in compliance with the Apache License
@@ -14,17 +14,16 @@
14
14
  // express or implied. See the Apache License Version 2.0 for the specific
15
15
  // language governing permissions and limitations there under.
16
16
  //
17
- // Copyright: Copyright (c) 2021 Snowplow Analytics Ltd
17
+ // Copyright: Copyright (c) 2022 Snowplow Analytics Ltd
18
18
  // License: Apache License Version 2.0
19
19
  //
20
20
 
21
21
  #import "RNSnowplowTracker.h"
22
22
  #import "RNConfigUtils.h"
23
23
  #import "RNUtilities.h"
24
+ #import "NSDictionary+RNSP_TypeMethods.h"
24
25
 
25
26
  #import <SnowplowTracker/SPSnowplow.h>
26
- #import <SnowplowTracker/NSDictionary+SP_TypeMethods.h>
27
- #import <SnowplowTracker/SPUtilities.h>
28
27
  #import <SnowplowTracker/SPNetworkConfiguration.h>
29
28
  #import <SnowplowTracker/SPNetworkConnection.h>
30
29
  #import <SnowplowTracker/SPTrackerConfiguration.h>
@@ -44,6 +43,8 @@
44
43
  #import <SnowplowTracker/SPStructured.h>
45
44
  #import <SnowplowTracker/SPEcommerceItem.h>
46
45
  #import <SnowplowTracker/SPEcommerce.h>
46
+ #import <SnowplowTracker/SPDeepLinkReceived.h>
47
+ #import <SnowplowTracker/SPMessageNotification.h>
47
48
 
48
49
 
49
50
  @implementation RNSnowplowTracker
@@ -59,7 +60,7 @@ RCT_EXPORT_METHOD(createTracker:
59
60
  NSDictionary *networkConfig =[argmap objectForKey:@"networkConfig"];
60
61
 
61
62
  // NetworkConfiguration
62
- NSString *method = [networkConfig sp_stringForKey:@"method" defaultValue:nil];
63
+ NSString *method = [networkConfig rnsp_stringForKey:@"method" defaultValue:nil];
63
64
  SPHttpMethod httpMethod = [@"get" isEqualToString:method] ? SPHttpMethodGet : SPHttpMethodPost;
64
65
  SPNetworkConfiguration *networkConfiguration = [[SPNetworkConfiguration alloc] initWithEndpoint:networkConfig[@"endpoint"] method:httpMethod];
65
66
 
@@ -167,19 +168,19 @@ RCT_EXPORT_METHOD(trackStructuredEvent:
167
168
  NSDictionary *argmap = [details objectForKey:@"eventData"];
168
169
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
169
170
 
170
- NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
171
- NSString *action = [argmap sp_stringForKey:@"action" defaultValue:nil];
171
+ NSString *category = [argmap rnsp_stringForKey:@"category" defaultValue:nil];
172
+ NSString *action = [argmap rnsp_stringForKey:@"action" defaultValue:nil];
172
173
  SPStructured *event = [[SPStructured alloc] initWithCategory:category
173
174
  action:action];
174
- NSString *label = [argmap sp_stringForKey:@"label" defaultValue:nil];
175
+ NSString *label = [argmap rnsp_stringForKey:@"label" defaultValue:nil];
175
176
  if (label) {
176
177
  event.label = label;
177
178
  }
178
- NSString *property = [argmap sp_stringForKey:@"property" defaultValue:nil];
179
+ NSString *property = [argmap rnsp_stringForKey:@"property" defaultValue:nil];
179
180
  if (property) {
180
181
  event.property = property;
181
182
  }
182
- NSNumber *value = [argmap sp_numberForKey:@"value" defaultValue:nil];
183
+ NSNumber *value = [argmap rnsp_numberForKey:@"value" defaultValue:nil];
183
184
  if (label) {
184
185
  event.value = value;
185
186
  }
@@ -204,8 +205,8 @@ RCT_EXPORT_METHOD(trackScreenViewEvent:
204
205
  NSDictionary *argmap = [details objectForKey:@"eventData"];
205
206
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
206
207
 
207
- NSString *screenName = [argmap sp_stringForKey:@"name" defaultValue:nil];
208
- NSString *screenId = [argmap sp_stringForKey:@"id" defaultValue:nil];
208
+ NSString *screenName = [argmap rnsp_stringForKey:@"name" defaultValue:nil];
209
+ NSString *screenId = [argmap rnsp_stringForKey:@"id" defaultValue:nil];
209
210
  NSUUID *screenUuid = [[NSUUID alloc] initWithUUIDString:screenId];
210
211
  if (screenId != nil && screenUuid == nil) {
211
212
  NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
@@ -214,23 +215,23 @@ RCT_EXPORT_METHOD(trackScreenViewEvent:
214
215
  SPScreenView *event = [[SPScreenView alloc] initWithName:screenName
215
216
  screenId:screenUuid];
216
217
 
217
- NSString *type = [argmap sp_stringForKey:@"type" defaultValue:nil];
218
+ NSString *type = [argmap rnsp_stringForKey:@"type" defaultValue:nil];
218
219
  if (type) {
219
220
  event.type = type;
220
221
  }
221
- NSString *previousName = [argmap sp_stringForKey:@"previousName" defaultValue:nil];
222
+ NSString *previousName = [argmap rnsp_stringForKey:@"previousName" defaultValue:nil];
222
223
  if (previousName) {
223
224
  event.previousName = previousName;
224
225
  }
225
- NSString *previousId = [argmap sp_stringForKey:@"previousId" defaultValue:nil];
226
+ NSString *previousId = [argmap rnsp_stringForKey:@"previousId" defaultValue:nil];
226
227
  if (previousId) {
227
228
  event.previousId = previousId;
228
229
  }
229
- NSString *previousType = [argmap sp_stringForKey:@"previousType" defaultValue:nil];
230
+ NSString *previousType = [argmap rnsp_stringForKey:@"previousType" defaultValue:nil];
230
231
  if (previousType) {
231
232
  event.previousType = previousType;
232
233
  }
233
- NSString *transitionType = [argmap sp_stringForKey:@"transitionType" defaultValue:nil];
234
+ NSString *transitionType = [argmap rnsp_stringForKey:@"transitionType" defaultValue:nil];
234
235
  if (transitionType) {
235
236
  event.transitionType = transitionType;
236
237
  }
@@ -255,14 +256,14 @@ RCT_EXPORT_METHOD(trackPageViewEvent:
255
256
  NSDictionary *argmap = [details objectForKey:@"eventData"];
256
257
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
257
258
 
258
- NSString *pageUrl = [argmap sp_stringForKey:@"pageUrl" defaultValue:nil];
259
+ NSString *pageUrl = [argmap rnsp_stringForKey:@"pageUrl" defaultValue:nil];
259
260
  SPPageView *event = [[SPPageView alloc] initWithPageUrl:pageUrl];
260
261
 
261
- NSString *pageTitle = [argmap sp_stringForKey:@"pageTitle" defaultValue:nil];
262
+ NSString *pageTitle = [argmap rnsp_stringForKey:@"pageTitle" defaultValue:nil];
262
263
  if (pageTitle) {
263
264
  event.pageTitle = pageTitle;
264
265
  }
265
- NSString *referrer = [argmap sp_stringForKey:@"referrer" defaultValue:nil];
266
+ NSString *referrer = [argmap rnsp_stringForKey:@"referrer" defaultValue:nil];
266
267
  if (referrer) {
267
268
  event.referrer = referrer;
268
269
  }
@@ -287,13 +288,13 @@ RCT_EXPORT_METHOD(trackTimingEvent:
287
288
  NSDictionary *argmap = [details objectForKey:@"eventData"];
288
289
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
289
290
 
290
- NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
291
- NSString *variable = [argmap sp_stringForKey:@"variable" defaultValue:nil];
292
- NSNumber *timing = [argmap sp_numberForKey:@"timing" defaultValue:nil];
291
+ NSString *category = [argmap rnsp_stringForKey:@"category" defaultValue:nil];
292
+ NSString *variable = [argmap rnsp_stringForKey:@"variable" defaultValue:nil];
293
+ NSNumber *timing = [argmap rnsp_numberForKey:@"timing" defaultValue:nil];
293
294
  SPTiming *event = [[SPTiming alloc] initWithCategory:category
294
295
  variable:variable
295
296
  timing:timing];
296
- NSString *label = [argmap sp_stringForKey:@"label" defaultValue:nil];
297
+ NSString *label = [argmap rnsp_stringForKey:@"label" defaultValue:nil];
297
298
  if (label) {
298
299
  event.label = label;
299
300
  }
@@ -318,18 +319,18 @@ RCT_EXPORT_METHOD(trackConsentGrantedEvent:
318
319
  NSDictionary *argmap = [details objectForKey:@"eventData"];
319
320
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
320
321
 
321
- NSString *expiry = [argmap sp_stringForKey:@"expiry" defaultValue:nil];
322
- NSString *documentId = [argmap sp_stringForKey:@"documentId" defaultValue:nil];
323
- NSString *version = [argmap sp_stringForKey:@"version" defaultValue:nil];
322
+ NSString *expiry = [argmap rnsp_stringForKey:@"expiry" defaultValue:nil];
323
+ NSString *documentId = [argmap rnsp_stringForKey:@"documentId" defaultValue:nil];
324
+ NSString *version = [argmap rnsp_stringForKey:@"version" defaultValue:nil];
324
325
  SPConsentGranted *event = [[SPConsentGranted alloc] initWithExpiry:expiry
325
326
  documentId:documentId
326
327
  version:version];
327
328
 
328
- NSString *name = [argmap sp_stringForKey:@"name" defaultValue:nil];
329
+ NSString *name = [argmap rnsp_stringForKey:@"name" defaultValue:nil];
329
330
  if (name) {
330
331
  event.name = name;
331
332
  }
332
- NSString *documentDescription = [argmap sp_stringForKey:@"documentDescription" defaultValue:nil];
333
+ NSString *documentDescription = [argmap rnsp_stringForKey:@"documentDescription" defaultValue:nil];
333
334
  if (documentDescription) {
334
335
  event.documentDescription = documentDescription;
335
336
  }
@@ -356,17 +357,17 @@ RCT_EXPORT_METHOD(trackConsentWithdrawnEvent:
356
357
 
357
358
  SPConsentWithdrawn *event = [SPConsentWithdrawn new];
358
359
 
359
- BOOL all = [argmap sp_boolForKey:@"all" defaultValue:nil];
360
+ BOOL all = [argmap rnsp_boolForKey:@"all" defaultValue:nil];
360
361
  event.all = all;
361
- NSString *documentId = [argmap sp_stringForKey:@"documentId" defaultValue:nil];
362
+ NSString *documentId = [argmap rnsp_stringForKey:@"documentId" defaultValue:nil];
362
363
  event.documentId = documentId;
363
- NSString *version = [argmap sp_stringForKey:@"version" defaultValue:nil];
364
+ NSString *version = [argmap rnsp_stringForKey:@"version" defaultValue:nil];
364
365
  event.version = version;
365
- NSString *name = [argmap sp_stringForKey:@"name" defaultValue:nil];
366
+ NSString *name = [argmap rnsp_stringForKey:@"name" defaultValue:nil];
366
367
  if (name) {
367
368
  event.name = name;
368
369
  }
369
- NSString *documentDescription = [argmap sp_stringForKey:@"documentDescription" defaultValue:nil];
370
+ NSString *documentDescription = [argmap rnsp_stringForKey:@"documentDescription" defaultValue:nil];
370
371
  if (documentDescription) {
371
372
  event.documentDescription = documentDescription;
372
373
  }
@@ -391,28 +392,28 @@ RCT_EXPORT_METHOD(trackEcommerceTransactionEvent:
391
392
  NSDictionary *argmap = [details objectForKey:@"eventData"];
392
393
  NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
393
394
 
394
- NSString *orderId = [argmap sp_stringForKey:@"orderId" defaultValue:nil];
395
- NSNumber *totalValue = [argmap sp_numberForKey:@"totalValue" defaultValue:nil];
395
+ NSString *orderId = [argmap rnsp_stringForKey:@"orderId" defaultValue:nil];
396
+ NSNumber *totalValue = [argmap rnsp_numberForKey:@"totalValue" defaultValue:nil];
396
397
  NSArray *items = [argmap objectForKey:@"items"];
397
398
 
398
399
  NSMutableArray *transItems = [NSMutableArray new];
399
400
  for (NSDictionary* item in items) {
400
- NSString *sku = [item sp_stringForKey:@"sku" defaultValue:nil];
401
- NSNumber *price = [item sp_numberForKey:@"price" defaultValue:nil];
402
- NSNumber *quantity = [item sp_numberForKey:@"quantity" defaultValue:nil];
401
+ NSString *sku = [item rnsp_stringForKey:@"sku" defaultValue:nil];
402
+ NSNumber *price = [item rnsp_numberForKey:@"price" defaultValue:nil];
403
+ NSNumber *quantity = [item rnsp_numberForKey:@"quantity" defaultValue:nil];
403
404
  SPEcommerceItem *ecomItem = [[SPEcommerceItem alloc] initWithSku:sku
404
405
  price:price
405
406
  quantity:quantity];
406
407
 
407
- NSString *name = [argmap sp_stringForKey:@"name" defaultValue:nil];
408
+ NSString *name = [argmap rnsp_stringForKey:@"name" defaultValue:nil];
408
409
  if (name) {
409
410
  ecomItem.name = name;
410
411
  }
411
- NSString *category = [argmap sp_stringForKey:@"category" defaultValue:nil];
412
+ NSString *category = [argmap rnsp_stringForKey:@"category" defaultValue:nil];
412
413
  if (category) {
413
414
  ecomItem.category = category;
414
415
  }
415
- NSString *currency = [argmap sp_stringForKey:@"currency" defaultValue:nil];
416
+ NSString *currency = [argmap rnsp_stringForKey:@"currency" defaultValue:nil];
416
417
  if (currency) {
417
418
  ecomItem.currency = currency;
418
419
  }
@@ -433,6 +434,148 @@ RCT_EXPORT_METHOD(trackEcommerceTransactionEvent:
433
434
  }
434
435
  }
435
436
 
437
+ RCT_EXPORT_METHOD(trackDeepLinkReceivedEvent:
438
+ (NSDictionary *)details
439
+ resolver:(RCTPromiseResolveBlock)resolve
440
+ rejecter:(RCTPromiseRejectBlock)reject) {
441
+ NSString *namespace = [details objectForKey:@"tracker"];
442
+ id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
443
+
444
+ if (trackerController != nil) {
445
+ NSDictionary *argmap = [details objectForKey:@"eventData"];
446
+ NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
447
+
448
+ NSString *url = [argmap rnsp_stringForKey:@"url" defaultValue:nil];
449
+ SPDeepLinkReceived *event = [[SPDeepLinkReceived alloc] initWithUrl:url];
450
+
451
+ NSString *referrer = [argmap rnsp_stringForKey:@"referrer" defaultValue:nil];
452
+ if (referrer) {
453
+ event.referrer = referrer;
454
+ }
455
+
456
+ [event contexts:[RNUtilities mkSDJArray:contexts]];
457
+ [trackerController track:event];
458
+ resolve(@YES);
459
+ } else {
460
+ NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
461
+ reject(@"ERROR", @"tracker with given namespace not found", error);
462
+ }
463
+ }
464
+
465
+ RCT_EXPORT_METHOD(trackMessageNotificationEvent:
466
+ (NSDictionary *)details
467
+ resolver:(RCTPromiseResolveBlock)resolve
468
+ rejecter:(RCTPromiseRejectBlock)reject) {
469
+ NSString *namespace = [details objectForKey:@"tracker"];
470
+ id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
471
+
472
+ if (trackerController != nil) {
473
+ NSDictionary *argmap = [details objectForKey:@"eventData"];
474
+ NSArray<NSDictionary *> *contexts = [details objectForKey:@"contexts"];
475
+
476
+ NSString *title = [argmap rnsp_stringForKey:@"title" defaultValue:nil];
477
+ NSString *body = [argmap rnsp_stringForKey:@"body" defaultValue:nil];
478
+ NSString *triggerStr = [argmap rnsp_stringForKey:@"trigger" defaultValue:nil];
479
+ SPMessageNotificationTrigger trigger;
480
+ if ([triggerStr isEqualToString:@"push"]) {
481
+ trigger = SPMessageNotificationTriggerPush;
482
+ } else if ([triggerStr isEqualToString:@"location"]) {
483
+ trigger = SPMessageNotificationTriggerLocation;
484
+ } else if ([triggerStr isEqualToString:@"calendar"]) {
485
+ trigger = SPMessageNotificationTriggerCalendar;
486
+ } else if ([triggerStr isEqualToString:@"timeInterval"]) {
487
+ trigger = SPMessageNotificationTriggerTimeInterval;
488
+ } else {
489
+ trigger = SPMessageNotificationTriggerOther;
490
+ }
491
+ SPMessageNotification *event = [[SPMessageNotification alloc] initWithTitle: title
492
+ body: body
493
+ trigger: trigger];
494
+
495
+ NSString *action = [argmap rnsp_stringForKey:@"action" defaultValue:nil];
496
+ if (action) {
497
+ event.action = action;
498
+ }
499
+ NSArray *attachmentsMap = [argmap objectForKey:@"attachments"];
500
+ if (attachmentsMap) {
501
+ NSMutableArray *attachments = [NSMutableArray new];
502
+ for (NSDictionary* attachmentMap in attachmentsMap) {
503
+ NSString *identifier = [attachmentMap rnsp_stringForKey:@"identifier" defaultValue:nil];
504
+ NSString *type = [attachmentMap rnsp_stringForKey:@"type" defaultValue:nil];
505
+ NSString *url = [attachmentMap rnsp_stringForKey:@"url" defaultValue:nil];
506
+ SPMessageNotificationAttachment *attachment = [[SPMessageNotificationAttachment alloc] initWithIdentifier:identifier
507
+ type:type
508
+ url:url];
509
+ [attachments addObject:attachment];
510
+ }
511
+ event.attachments = attachments;
512
+ }
513
+ NSArray<NSString *> *bodyLocArgs = [argmap objectForKey:@"bodyLocArgs"];
514
+ if (bodyLocArgs) {
515
+ event.bodyLocArgs = bodyLocArgs;
516
+ }
517
+ NSString *bodyLocKey = [argmap rnsp_stringForKey:@"bodyLocKey" defaultValue:nil];
518
+ if (bodyLocKey) {
519
+ event.bodyLocKey = bodyLocKey;
520
+ }
521
+ NSString *category = [argmap rnsp_stringForKey:@"category" defaultValue:nil];
522
+ if (category) {
523
+ event.category = category;
524
+ }
525
+ NSNumber *contentAvailable = [argmap rnsp_numberForKey:@"contentAvailable" defaultValue:nil];
526
+ if (contentAvailable != nil) {
527
+ event.contentAvailable = contentAvailable;
528
+ }
529
+ NSString *group = [argmap rnsp_stringForKey:@"group" defaultValue:nil];
530
+ if (group) {
531
+ event.group = group;
532
+ }
533
+ NSString *icon = [argmap rnsp_stringForKey:@"icon" defaultValue:nil];
534
+ if (icon) {
535
+ event.icon = icon;
536
+ }
537
+ NSNumber *notificationCount = [argmap rnsp_numberForKey:@"notificationCount" defaultValue:nil];
538
+ if (notificationCount) {
539
+ event.notificationCount = notificationCount;
540
+ }
541
+ NSString *notificationTimestamp = [argmap rnsp_stringForKey:@"notificationTimestamp" defaultValue:nil];
542
+ if (notificationTimestamp) {
543
+ event.notificationTimestamp = notificationTimestamp;
544
+ }
545
+ NSString *sound = [argmap rnsp_stringForKey:@"sound" defaultValue:nil];
546
+ if (sound) {
547
+ event.sound = sound;
548
+ }
549
+ NSString *subtitle = [argmap rnsp_stringForKey:@"subtitle" defaultValue:nil];
550
+ if (subtitle) {
551
+ event.subtitle = subtitle;
552
+ }
553
+ NSString *tag = [argmap rnsp_stringForKey:@"tag" defaultValue:nil];
554
+ if (tag) {
555
+ event.tag = tag;
556
+ }
557
+ NSString *threadIdentifier = [argmap rnsp_stringForKey:@"threadIdentifier" defaultValue:nil];
558
+ if (threadIdentifier) {
559
+ event.threadIdentifier = threadIdentifier;
560
+ }
561
+ NSArray<NSString *> *titleLocArgs = [argmap objectForKey:@"titleLocArgs"];
562
+ if (titleLocArgs) {
563
+ event.titleLocArgs = titleLocArgs;
564
+ }
565
+ NSString *titleLocKey = [argmap rnsp_stringForKey:@"titleLocKey" defaultValue:nil];
566
+ if (titleLocKey) {
567
+ event.titleLocKey = titleLocKey;
568
+ }
569
+
570
+ [event contexts:[RNUtilities mkSDJArray:contexts]];
571
+ [trackerController track:event];
572
+ resolve(@YES);
573
+ } else {
574
+ NSError* error = [NSError errorWithDomain:@"SnowplowTracker" code:200 userInfo:nil];
575
+ reject(@"ERROR", @"tracker with given namespace not found", error);
576
+ }
577
+ }
578
+
436
579
  RCT_EXPORT_METHOD(removeGlobalContexts:
437
580
  (NSDictionary *)details
438
581
  resolver:(RCTPromiseResolveBlock)resolve
@@ -481,7 +624,7 @@ RCT_EXPORT_METHOD(setUserId:
481
624
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
482
625
 
483
626
  if (trackerController != nil) {
484
- NSString *newUid = [details sp_stringForKey:@"userId" defaultValue:nil];
627
+ NSString *newUid = [details rnsp_stringForKey:@"userId" defaultValue:nil];
485
628
  [trackerController.subject setUserId:newUid];
486
629
  resolve(@YES);
487
630
  } else {
@@ -498,7 +641,7 @@ RCT_EXPORT_METHOD(setNetworkUserId:
498
641
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
499
642
 
500
643
  if (trackerController != nil) {
501
- NSString *newNuid = [details sp_stringForKey:@"networkUserId" defaultValue:nil];
644
+ NSString *newNuid = [details rnsp_stringForKey:@"networkUserId" defaultValue:nil];
502
645
  [trackerController.subject setNetworkUserId:newNuid];
503
646
  resolve(@YES);
504
647
  } else {
@@ -515,7 +658,7 @@ RCT_EXPORT_METHOD(setDomainUserId:
515
658
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
516
659
 
517
660
  if (trackerController != nil) {
518
- NSString *newDuid = [details sp_stringForKey:@"domainUserId" defaultValue:nil];
661
+ NSString *newDuid = [details rnsp_stringForKey:@"domainUserId" defaultValue:nil];
519
662
  [trackerController.subject setDomainUserId:newDuid];
520
663
  resolve(@YES);
521
664
  } else {
@@ -532,7 +675,7 @@ RCT_EXPORT_METHOD(setIpAddress:
532
675
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
533
676
 
534
677
  if (trackerController != nil) {
535
- NSString *newIp = [details sp_stringForKey:@"ipAddress" defaultValue:nil];
678
+ NSString *newIp = [details rnsp_stringForKey:@"ipAddress" defaultValue:nil];
536
679
  [trackerController.subject setIpAddress:newIp];
537
680
  resolve(@YES);
538
681
  } else {
@@ -549,7 +692,7 @@ RCT_EXPORT_METHOD(setUseragent:
549
692
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
550
693
 
551
694
  if (trackerController != nil) {
552
- NSString *newUagent = [details sp_stringForKey:@"useragent" defaultValue:nil];
695
+ NSString *newUagent = [details rnsp_stringForKey:@"useragent" defaultValue:nil];
553
696
  [trackerController.subject setUseragent:newUagent];
554
697
  resolve(@YES);
555
698
  } else {
@@ -566,7 +709,7 @@ RCT_EXPORT_METHOD(setTimezone:
566
709
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
567
710
 
568
711
  if (trackerController != nil) {
569
- NSString *newTz = [details sp_stringForKey:@"timezone" defaultValue:nil];
712
+ NSString *newTz = [details rnsp_stringForKey:@"timezone" defaultValue:nil];
570
713
  [trackerController.subject setTimezone:newTz];
571
714
  resolve(@YES);
572
715
  } else {
@@ -583,7 +726,7 @@ RCT_EXPORT_METHOD(setLanguage:
583
726
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
584
727
 
585
728
  if (trackerController != nil) {
586
- NSString *newLang = [details sp_stringForKey:@"language" defaultValue:nil];
729
+ NSString *newLang = [details rnsp_stringForKey:@"language" defaultValue:nil];
587
730
  [trackerController.subject setLanguage:newLang];
588
731
  resolve(@YES);
589
732
  } else {
@@ -648,7 +791,7 @@ RCT_EXPORT_METHOD(setColorDepth:
648
791
  id<SPTrackerController> trackerController = [SPSnowplow trackerByNamespace:namespace];
649
792
 
650
793
  if (trackerController != nil) {
651
- NSNumber *newColorD = [details sp_numberForKey:@"colorDepth" defaultValue:nil];
794
+ NSNumber *newColorD = [details rnsp_numberForKey:@"colorDepth" defaultValue:nil];
652
795
  [trackerController.subject setColorDepth:newColorD];
653
796
  resolve(@YES);
654
797
  } else {
@@ -0,0 +1,33 @@
1
+ //
2
+ // NSDictionary+RNSP_TypeMethods.h
3
+ //
4
+ // Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
5
+ //
6
+ // This program is licensed to you under the Apache License Version 2.0,
7
+ // and you may not use this file except in compliance with the Apache License
8
+ // Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
9
+ // http://www.apache.org/licenses/LICENSE-2.0.
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the Apache License Version 2.0 is distributed on
13
+ // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ // express or implied. See the Apache License Version 2.0 for the specific
15
+ // language governing permissions and limitations there under.
16
+ //
17
+ // Copyright: Copyright (c) 2022 Snowplow Analytics Ltd
18
+ // License: Apache License Version 2.0
19
+ //
20
+
21
+ #import <Foundation/Foundation.h>
22
+
23
+ NS_ASSUME_NONNULL_BEGIN
24
+
25
+ @interface NSDictionary (RNSP_TypeMethods)
26
+
27
+ - (nullable NSString *)rnsp_stringForKey:(NSString *)key defaultValue:(nullable NSString *)defaultValue;
28
+ - (nullable NSNumber *)rnsp_numberForKey:(NSString *)key defaultValue:(nullable NSNumber *)defaultValue;
29
+ - (BOOL)rnsp_boolForKey:(NSString *)key defaultValue:(BOOL)defaultValue;
30
+
31
+ @end
32
+
33
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,40 @@
1
+ //
2
+ // NSDictionary+RNSP_TypeMethods.m
3
+ //
4
+ // Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
5
+ //
6
+ // This program is licensed to you under the Apache License Version 2.0,
7
+ // and you may not use this file except in compliance with the Apache License
8
+ // Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
9
+ // http://www.apache.org/licenses/LICENSE-2.0.
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the Apache License Version 2.0 is distributed on
13
+ // an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14
+ // express or implied. See the Apache License Version 2.0 for the specific
15
+ // language governing permissions and limitations there under.
16
+ //
17
+ // Copyright: Copyright (c) 2022 Snowplow Analytics Ltd
18
+ // License: Apache License Version 2.0
19
+ //
20
+
21
+ #import "NSDictionary+RNSP_TypeMethods.h"
22
+
23
+ @implementation NSDictionary (RNSP_TypeMethods)
24
+
25
+ - (nullable NSString *)rnsp_stringForKey:(NSString *)key defaultValue:(nullable NSString *)defaultValue {
26
+ NSObject *obj = [self objectForKey:key];
27
+ return [obj isKindOfClass:NSString.class] ? (NSString *)obj : defaultValue;
28
+ }
29
+
30
+ - (nullable NSNumber *)rnsp_numberForKey:(NSString *)key defaultValue:(nullable NSNumber *)defaultValue {
31
+ NSObject *obj = [self objectForKey:key];
32
+ return [obj isKindOfClass:NSNumber.class] ? (NSNumber *)obj : defaultValue;
33
+ }
34
+
35
+ - (BOOL)rnsp_boolForKey:(NSString *)key defaultValue:(BOOL)defaultValue {
36
+ NSNumber *num = [self rnsp_numberForKey:key defaultValue:nil];
37
+ return num ? num.boolValue : defaultValue;
38
+ }
39
+
40
+ @end
@@ -1,7 +1,7 @@
1
1
  //
2
2
  // RNConfigUtils.h
3
3
  //
4
- // Copyright (c) 2021 Snowplow Analytics Ltd. All rights reserved.
4
+ // Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
5
5
  //
6
6
  // This program is licensed to you under the Apache License Version 2.0,
7
7
  // and you may not use this file except in compliance with the Apache License
@@ -14,7 +14,7 @@
14
14
  // express or implied. See the Apache License Version 2.0 for the specific
15
15
  // language governing permissions and limitations there under.
16
16
  //
17
- // Copyright: Copyright (c) 2021 Snowplow Analytics Ltd
17
+ // Copyright: Copyright (c) 2022 Snowplow Analytics Ltd
18
18
  // License: Apache License Version 2.0
19
19
  //
20
20