@blueconic/blueconic-react-native 3.2.4 → 4.0.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.
@@ -9,7 +9,7 @@ import BlueConicClient
9
9
  @objc(BlueConicClientModule)
10
10
  class BlueConicClientModule: RCTEventEmitter {
11
11
  private static var platformName: String = "React Native"
12
- private static var platformVersion: String = "3.2.0"
12
+ private static var platformVersion: String = "4.0.0"
13
13
  private static var moduleInstance: BlueConicClientModule?
14
14
  private static var hasListeners: Bool?
15
15
 
@@ -32,6 +32,30 @@ class BlueConicClientModule: RCTEventEmitter {
32
32
  return false
33
33
  }
34
34
 
35
+ @objc func initialize(_ properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
36
+ let blueConicConfiguration = BlueConicConfiguration.Builder()
37
+ .setHostName(properties["bc_hostname"] as! String)
38
+ .setDebugMode(properties["bc_debug"] as! Bool)
39
+ .setShared(false)
40
+ .build()
41
+
42
+ if let overrideAppId = properties["override_app_id"] as? String {
43
+ blueConicConfiguration.appID = overrideAppId
44
+ }
45
+
46
+ if let username = properties["simulator_username"] as? String, let sessionId = properties["simulator_session_id"] as? String {
47
+ blueConicConfiguration.simulatorUsername = username
48
+ blueConicConfiguration.simulatorMobileSessionId = sessionId
49
+ }
50
+
51
+ self.getBlueConicClientInstance().initialize(blueConicConfiguration, callback: { result in
52
+ if result.success {
53
+ callback([true, nil])
54
+ } else if let error = result.error {
55
+ callback([false, error.nsError.localizedDescription])
56
+ }
57
+ })
58
+ }
35
59
 
36
60
  // MARK: GETTERS
37
61
  /**
@@ -39,10 +63,18 @@ class BlueConicClientModule: RCTEventEmitter {
39
63
  - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
40
64
  Native Modules to pass values back to the JavaScript.
41
65
  */
42
- @objc func getProfileId(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
66
+ @objc func getProfileIdAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
43
67
  resolve([self.getBlueConicClientInstance().getProfileId() ?? ""])
44
68
  }
45
69
 
70
+ /**
71
+ Gets the ID of the BlueConic profile. The value is passed to the provided callback function as a String.
72
+ - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
73
+ Native Modules to pass values back to the JavaScript.
74
+ */
75
+ @objc func getProfileIdWithCallback(_ callback: RCTResponseSenderBlock) -> Void {
76
+ callback([self.getBlueConicClientInstance().getProfileId() ?? ""])
77
+ }
46
78
 
47
79
  /**
48
80
  Gets the values of the specified profile property. The values are passed to the provided callback function
@@ -51,7 +83,7 @@ class BlueConicClientModule: RCTEventEmitter {
51
83
  - parameter callback: The callback function to handle the obtained values. Callbacks are necessary in
52
84
  Native Modules to pass values back to the JavaScript.
53
85
  */
54
- @objc func getProfileValue(_ property: String, withResolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
86
+ @objc func getProfileValueAsync(_ property: String, withResolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
55
87
  resolve([self.getBlueConicClientInstance().getProfileValue(property)])
56
88
  }
57
89
 
@@ -63,20 +95,10 @@ class BlueConicClientModule: RCTEventEmitter {
63
95
  - parameter callback: The callback function to handle the obtained values. Callbacks are necessary in
64
96
  Native Modules to pass values back to the JavaScript.
65
97
  */
66
- @objc func getProfileValues(_ property: String, withResolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
98
+ @objc func getProfileValuesAsync(_ property: String, withResolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
67
99
  resolve(self.getBlueConicClientInstance().getProfileValues(property))
68
100
  }
69
101
 
70
-
71
- /**
72
- Gets the ID of the BlueConic profile. The value is passed to the provided callback function as a String.
73
- - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
74
- Native Modules to pass values back to the JavaScript.
75
- */
76
- @objc func getProfileIdWithCallback(_ callback: RCTResponseSenderBlock) -> Void {
77
- callback([self.getBlueConicClientInstance().getProfileId() ?? ""])
78
- }
79
-
80
102
  /**
81
103
  Gets the values of the specified profile property. The values are passed to the provided callback function
82
104
  as separate Strings.
@@ -99,13 +121,30 @@ class BlueConicClientModule: RCTEventEmitter {
99
121
  @objc func getProfileValuesWithCallback(_ property: String, withCallback callback: RCTResponseSenderBlock) -> Void {
100
122
  callback(self.getBlueConicClientInstance().getProfileValues(property))
101
123
  }
102
-
124
+
125
+ /**
126
+ Retrieves all the profile properties and their values.
127
+ - parameter callback: The promise to handle the obtained value. Promises are necessary in Native Modules
128
+ */
129
+ @objc func getAllProfilePropertiesAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
130
+ var result = [[String: String]]()
131
+ let allProperties = self.getBlueConicClientInstance().getAllProfileProperties()
132
+ for (key, value) in allProperties {
133
+ let item = [
134
+ "id": key,
135
+ "value": value.joined(separator: ", ")
136
+ ]
137
+ result.append(item)
138
+ }
139
+ resolve(result)
140
+ }
141
+
103
142
  /**
104
143
  Gets the privacy legislation of the BlueConic profile. The value is passed to the provided callback function as a String.
105
144
  - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
106
145
  Native Modules to pass values back to the JavaScript.
107
146
  */
108
- @objc func getPrivacyLegislation(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
147
+ @objc func getPrivacyLegislationAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
109
148
  resolve([self.getBlueConicClientInstance().getPrivacyLegislation() ?? ""])
110
149
  }
111
150
 
@@ -123,7 +162,7 @@ class BlueConicClientModule: RCTEventEmitter {
123
162
  - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
124
163
  Native Modules to pass values back to the JavaScript.
125
164
  */
126
- @objc func getConsentedObjectives(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
165
+ @objc func getConsentedObjectivesAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
127
166
  resolve(self.getBlueConicClientInstance().getConsentedObjectives())
128
167
  }
129
168
 
@@ -141,7 +180,7 @@ class BlueConicClientModule: RCTEventEmitter {
141
180
  - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
142
181
  Native Modules to pass values back to the JavaScript.
143
182
  */
144
- @objc func getRefusedObjectives(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
183
+ @objc func getRefusedObjectivesAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
145
184
  resolve(self.getBlueConicClientInstance().getRefusedObjectives())
146
185
  }
147
186
 
@@ -160,7 +199,7 @@ class BlueConicClientModule: RCTEventEmitter {
160
199
  - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
161
200
  Native Modules to pass values back to the JavaScript.
162
201
  */
163
- @objc func getSegments(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
202
+ @objc func getSegmentsAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
164
203
  resolve(self.getFormattedSegments())
165
204
  }
166
205
 
@@ -274,14 +313,18 @@ class BlueConicClientModule: RCTEventEmitter {
274
313
  @objc func createEvent(_ eventName: String, withProperties properties: [String: String]) -> Void {
275
314
  self.getBlueConicClientInstance().createEvent(eventName, properties: properties)
276
315
  }
277
- @objc func createEventSync(_ eventName: String, withProperties properties: [String: String], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
278
- self.getBlueConicClientInstance().createEvent(eventName, properties: properties, completion: {
316
+ @objc func createEventAsync(_ eventName: String, withProperties properties: [String: String], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
317
+ self.getBlueConicClientInstance().createEvent(eventName, properties: properties, callback: { result in
279
318
  resolve([])
280
319
  })
281
320
  }
282
- @objc func createEventSyncWithCallback(_ eventName: String, withProperties properties: [String: String], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
283
- self.getBlueConicClientInstance().createEvent(eventName, properties: properties, completion: {
284
- callback([])
321
+ @objc func createEventWithCallback(_ eventName: String, withProperties properties: [String: String], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
322
+ self.getBlueConicClientInstance().createEvent(eventName, properties: properties, callback: { result in
323
+ if result.success {
324
+ callback([true, nil])
325
+ } else if let error = result.error {
326
+ callback([false, error.nsError.localizedDescription])
327
+ }
285
328
  })
286
329
  }
287
330
 
@@ -291,15 +334,19 @@ class BlueConicClientModule: RCTEventEmitter {
291
334
  @objc func updateProfile() -> Void {
292
335
  self.getBlueConicClientInstance().updateProfile()
293
336
  }
294
- @objc func updateProfileSync(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
295
- self.getBlueConicClientInstance().updateProfile(completion: {
337
+ @objc func updateProfileAsync(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
338
+ self.getBlueConicClientInstance().updateProfile { result in
296
339
  resolve([])
297
- })
340
+ }
298
341
  }
299
- @objc func updateProfileSyncWithCallback(_ callback: @escaping RCTResponseSenderBlock) -> Void {
300
- self.getBlueConicClientInstance().updateProfile(completion: {
301
- callback([])
302
- })
342
+ @objc func updateProfileWithCallback(_ callback: @escaping RCTResponseSenderBlock) -> Void {
343
+ self.getBlueConicClientInstance().updateProfile { result in
344
+ if result.success {
345
+ callback([true, nil])
346
+ } else if let error = result.error {
347
+ callback([false, error.nsError.localizedDescription])
348
+ }
349
+ }
303
350
  }
304
351
 
305
352
  /**
@@ -326,7 +373,7 @@ class BlueConicClientModule: RCTEventEmitter {
326
373
  - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in
327
374
  Native Modules to pass values back to the JavaScript.
328
375
  */
329
- @objc func isEnabled(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
376
+ @objc func isEnabledAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
330
377
  resolve([self.getBlueConicClientInstance().isEnabled()])
331
378
  }
332
379
 
@@ -346,7 +393,7 @@ class BlueConicClientModule: RCTEventEmitter {
346
393
  - parameter callback: The callback function to handle the obtained values. Callbacks are necessary in
347
394
  Native Modules to pass values back to the JavaScript.
348
395
  */
349
- @objc func hasSegment(_ segmentId: String, withResolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
396
+ @objc func hasSegmentAsync(_ segmentId: String, withResolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
350
397
  resolve([self.getBlueConicClientInstance().hasSegment(segmentId)])
351
398
  }
352
399
  /**
@@ -367,86 +414,225 @@ class BlueConicClientModule: RCTEventEmitter {
367
414
  on every screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialoges)
368
415
  for the screen.
369
416
  - parameter screenName: The name of the screen.
417
+ - parameter properties: The properties for the event.
370
418
  */
371
- @objc func registerPageView(_ screenName: String) -> Void {
372
- self.getBlueConicClientInstance().createEvent("PAGEVIEW", properties: ["screenName": screenName])
419
+ @objc func createPageViewEvent(_ screenName: String, withProperties properties: [String: Any]) -> Void {
420
+ self.getBlueConicClientInstance().createPageViewEvent(screenName: screenName, properties: properties, callback: nil)
373
421
  }
374
- @objc func registerPageViewSync(_ screenName: String, withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
375
- self.getBlueConicClientInstance().createEvent("PAGEVIEW", properties: ["screenName": screenName], completion: {
422
+ @objc func createPageViewEventAsync(_ screenName: String, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
423
+ self.getBlueConicClientInstance().createPageViewEvent(screenName: screenName, properties: properties, callback: { result in
376
424
  resolve([])
377
425
  })
378
426
  }
379
- @objc func registerPageViewSyncWithCallback(_ screenName: String, withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
380
- self.getBlueConicClientInstance().createEvent("PAGEVIEW", properties: ["screenName": screenName], completion: {
381
- callback([])
427
+ @objc func createPageViewEventWithCallback(_ screenName: String, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
428
+ self.getBlueConicClientInstance().createPageViewEvent(screenName: screenName, properties: properties, callback: { result in
429
+ if result.success {
430
+ callback([true, nil])
431
+ } else if let error = result.error {
432
+ callback([false, error.nsError.localizedDescription])
433
+ }
434
+ })
435
+ }
436
+
437
+ /**
438
+ Calls the createEvent method of the BlueConicClient to register a VIEW event.
439
+ - parameter interactionId: The interaction id.
440
+ - parameter properties: The properties for the event.
441
+ */
442
+ @objc func createViewEvent(_ interactionId: String, withProperties properties: [String: Any]) -> Void {
443
+ self.getBlueConicClientInstance().createViewEvent(interactionId: interactionId, properties: properties, callback: nil)
444
+ }
445
+ @objc func createViewEventAsync(_ interactionId: String, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
446
+ self.getBlueConicClientInstance().createViewEvent(interactionId: interactionId, properties: properties, callback: { result in
447
+ resolve([])
448
+ })
449
+ }
450
+ @objc func createViewEventWithCallback(_ interactionId: String, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
451
+ self.getBlueConicClientInstance().createViewEvent(interactionId: interactionId, properties: properties, callback: { result in
452
+ if result.success {
453
+ callback([true, nil])
454
+ } else if let error = result.error {
455
+ callback([false, error.nsError.localizedDescription])
456
+ }
457
+ })
458
+ }
459
+
460
+ /**
461
+ Calls the createEvent method of the BlueConicClient to register a CONVERSION event.
462
+ - parameter interactionId: The interaction id.
463
+ - parameter properties: The properties for the event.
464
+ */
465
+ @objc func createConversionEvent(_ interactionId: String, withProperties properties: [String: Any]) -> Void {
466
+ self.getBlueConicClientInstance().createConversionEvent(interactionId: interactionId, properties: properties, callback: nil)
467
+ }
468
+ @objc func createConversionEventAsync(_ interactionId: String, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
469
+ self.getBlueConicClientInstance().createConversionEvent(interactionId: interactionId, properties: properties, callback: { result in
470
+ resolve([])
471
+ })
472
+ }
473
+ @objc func createConversionEventWithCallback(_ interactionId: String, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
474
+ self.getBlueConicClientInstance().createConversionEvent(interactionId: interactionId, properties: properties, callback: { result in
475
+ if result.success {
476
+ callback([true, nil])
477
+ } else if let error = result.error {
478
+ callback([false, error.nsError.localizedDescription])
479
+ }
480
+ })
481
+ }
482
+
483
+ /**
484
+ Calls the createEvent method of the BlueConicClient to register a CLICK event.
485
+ - parameter interactionId: The interaction id.
486
+ - parameter properties: The properties for the event.
487
+ */
488
+ @objc func createClickEvent(_ interactionId: String, withProperties properties: [String: Any]) -> Void {
489
+ self.getBlueConicClientInstance().createClickEvent(interactionId: interactionId, properties: properties, callback: nil)
490
+ }
491
+ @objc func createClickEventAsync(_ interactionId: String, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
492
+ self.getBlueConicClientInstance().createClickEvent(interactionId: interactionId, properties: properties, callback: { result in
493
+ resolve([])
494
+ })
495
+ }
496
+ @objc func createClickEventWithCallback(_ interactionId: String, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
497
+ self.getBlueConicClientInstance().createClickEvent(interactionId: interactionId, properties: properties, callback: { result in
498
+ if result.success {
499
+ callback([true, nil])
500
+ } else if let error = result.error {
501
+ callback([false, error.nsError.localizedDescription])
502
+ }
382
503
  })
383
504
  }
384
505
 
385
506
  /**
386
507
  Calls the createTimelineEvent method of the BlueConicClient.
387
508
  */
388
- @objc func registerTimelineEvent(_ eventType: String, withDate eventDate: Date, withProperties properties: [String: Any]) -> Void {
509
+ @objc func createTimelineEvent(_ eventType: String, withDate eventDate: Date, withProperties properties: [String: Any]) -> Void {
389
510
  self.getBlueConicClientInstance().createTimelineEvent(eventType, eventDate: eventDate, properties: properties)
390
511
  }
391
- @objc func registerTimelineEventSync(_ eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
392
- self.getBlueConicClientInstance().createTimelineEvent(eventType, eventDate: eventDate, properties: properties, completion: {
512
+ @objc func createTimelineEventAsync(_ eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
513
+ self.getBlueConicClientInstance().createTimelineEvent(eventType, eventDate: eventDate, properties: properties, callback: { result in
393
514
  resolve([])
394
515
  })
395
516
  }
396
- @objc func registerTimelineEventSyncWithCallback(_ eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
397
- self.getBlueConicClientInstance().createTimelineEvent(eventType, eventDate: eventDate, properties: properties, completion: {
398
- callback([])
517
+ @objc func createTimelineEventWithCallback(_ eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
518
+ self.getBlueConicClientInstance().createTimelineEvent(eventType, eventDate: eventDate, properties: properties, callback: { result in
519
+ if result.success {
520
+ callback([true, nil])
521
+ } else if let error = result.error {
522
+ callback([false, error.nsError.localizedDescription])
523
+ }
399
524
  })
400
525
  }
401
526
 
402
527
  /**
403
528
  Calls the createTimelineEventById method of the BlueConicClient.
404
529
  */
405
- @objc func registerTimelineEventById(_ eventId: String, withType eventType: String, withDate eventDate: Date, withProperties properties: [String: Any]) -> Void {
530
+ @objc func createTimelineEventById(_ eventId: String, withType eventType: String, withDate eventDate: Date, withProperties properties: [String: Any]) -> Void {
406
531
  self.getBlueConicClientInstance().createTimelineEventById(eventId, eventType: eventType, eventDate: eventDate, properties: properties)
407
532
  }
408
- @objc func registerTimelineEventByIdSync(_ eventId: String, withType eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
409
- self.getBlueConicClientInstance().createTimelineEventById(eventId, eventType: eventType, eventDate: eventDate, properties: properties, completion: {
533
+ @objc func createTimelineEventByIdAsync(_ eventId: String, withType eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withResolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
534
+ self.getBlueConicClientInstance().createTimelineEventById(eventId, eventType: eventType, eventDate: eventDate, properties: properties, callback: { result in
410
535
  resolve([])
411
536
  })
412
537
  }
413
- @objc func registerTimelineEventByIdSyncWithCallback(_ eventId: String, withType eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
414
- self.getBlueConicClientInstance().createTimelineEventById(eventId, eventType: eventType, eventDate: eventDate, properties: properties, completion: {
415
- callback([])
538
+ @objc func createTimelineEventByIdWithCallback(_ eventId: String, withType eventType: String, withDate eventDate: Date, withProperties properties: [String: Any], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
539
+ self.getBlueConicClientInstance().createTimelineEventById(eventId, eventType: eventType, eventDate: eventDate, properties: properties, callback: { result in
540
+ if result.success {
541
+ callback([true, nil])
542
+ } else if let error = result.error {
543
+ callback([false, error.nsError.localizedDescription])
544
+ }
416
545
  })
417
546
  }
418
547
 
548
+ @objc func subscribe(_ eventName: String, withOnlyOnce onlyOnce: Bool, withIdentifier identifier: String) -> Void {
549
+ let eventHandler: EventHandler
550
+
551
+ switch eventName {
552
+ case "propertiesDialogueEvent":
553
+ eventHandler = PropertiesDialogueHandler(eventName: eventName)
554
+ default:
555
+ eventHandler = DefaultEventHandler()
556
+ }
557
+
558
+ self.getBlueConicClientInstance().getEventManager().subscribe(
559
+ BlueConicEventManager.EventName.propertiesDialogue,
560
+ callbackObject: eventHandler,
561
+ onlyOnce: onlyOnce,
562
+ identifier: identifier
563
+ )
564
+ }
565
+
566
+ @objc func unsubscribe(_ identifier: String) -> Void {
567
+ self.getBlueConicClientInstance().getEventManager().unsubscribe(identifier: identifier)
568
+ }
569
+
419
570
  /**
420
571
  Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
421
572
  - parameter selector: The selector to identify the clicked component.
422
573
  */
423
- @objc func registerClickEvent(_ selector: String) -> Void {
424
- getBlueConicEventManager().publish(ClickEvent(selector: selector))
574
+ @objc func publishClickEvent(_ selector: String, withValues values: [String]) -> Void {
575
+ self.getBlueConicClientInstance().getEventManager().publishClickEvent(selector: selector)
425
576
  }
426
577
 
427
578
  /**
428
- Creates a ClickEvent with the given selector and context, and publishes the event to BlueConic using the EventManager.
579
+ Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
429
580
  - parameter selector: The selector to identify the clicked component.
430
- - parameter values: The values to pass to BlueConic as the context of the event.
431
581
  */
432
- @objc func registerClickEventWithContext(_ selector: String, withValues values: [String]) -> Void {
433
- getBlueConicEventManager().publish(ClickEvent(selector: selector, context: values))
582
+ @objc func publishClickEventWithCallback(_ selector: String, withValues values: [String], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
583
+ self.getBlueConicClientInstance().getEventManager().publishClickEvent(selector: selector, callback: { result in
584
+ if result.success {
585
+ callback([true, nil])
586
+ } else if let error = result.error {
587
+ callback([false, error.nsError.localizedDescription])
588
+ }
589
+ })
434
590
  }
591
+
435
592
  /**
436
593
  Creates a Form Submit Event for the given selector and publishes the event to BlueConic using the EventManager.
437
594
  - parameter selector: The selector to identify the clicked component.
438
595
  */
439
- @objc func registerFormSubmitEvent(_ selector: String) -> Void {
440
- getBlueConicEventManager().publish(FormSubmitEvent(selector: selector))
596
+ @objc func publishFormSubmitEvent(_ selector: String, withValues values: [String]) -> Void {
597
+ self.getBlueConicClientInstance().getEventManager().publishFormSubmitEvent(selector: selector)
441
598
  }
442
599
 
443
600
  /**
444
- Creates a Form Submit Event with the given selector and context, and publishes the event to BlueConic using the EventManager.
601
+ Creates a Form Submit Event for the given selector and publishes the event to BlueConic using the EventManager.
445
602
  - parameter selector: The selector to identify the clicked component.
446
- - parameter values: The values to pass to BlueConic as the context of the event.
447
603
  */
448
- @objc func registerFormSubmitEventWithContext(_ selector: String, withValues values: [String]) -> Void {
449
- getBlueConicEventManager().publish(FormSubmitEvent(selector: selector, context: values))
604
+ @objc func publishFormSubmitEventWithCallback(_ selector: String, withValues values: [String], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
605
+ self.getBlueConicClientInstance().getEventManager().publishFormSubmitEvent(selector: selector, callback: { result in
606
+ if result.success {
607
+ callback([true, nil])
608
+ } else if let error = result.error {
609
+ callback([false, error.nsError.localizedDescription])
610
+ }
611
+ })
612
+ }
613
+
614
+ /**
615
+ Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
616
+ - parameter selector: The selector to identify the component with updated values.
617
+ - parameter value: The value to be passed on to BlueConic.
618
+ */
619
+ @objc func publishUpdateContentEvent(_ selector: String, withValue value: String) -> Void {
620
+ self.getBlueConicClientInstance().getEventManager().publishUpdateContentEvent(selector: selector, content: value)
621
+ }
622
+
623
+ /**
624
+ Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
625
+ - parameter selector: The selector to identify the component with updated values.
626
+ - parameter value: The value to be passed on to BlueConic.
627
+ */
628
+ @objc func publishUpdateContentEventWithCallback(_ selector: String, withValue value: String, withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
629
+ self.getBlueConicClientInstance().getEventManager().publishUpdateContentEvent(selector: selector, content: value, callback: { result in
630
+ if result.success {
631
+ callback([true, nil])
632
+ } else if let error = result.error {
633
+ callback([false, error.nsError.localizedDescription])
634
+ }
635
+ })
450
636
  }
451
637
 
452
638
  /**
@@ -454,16 +640,23 @@ class BlueConicClientModule: RCTEventEmitter {
454
640
  - parameter selector: The selector to identify the component with updated values.
455
641
  - parameter value: The value to be passed on to BlueConic.
456
642
  */
457
- @objc func registerUpdateContentEvent(_ selector: String, withValue value: String) -> Void {
458
- getBlueConicEventManager().publish(UpdateContentEvent(selector: selector, content: value))
643
+ @objc func publishUpdateValuesEvent(_ selector: String, withValue value: String) -> Void {
644
+ self.getBlueConicClientInstance().getEventManager().publishUpdateValuesEvent(selector: selector, values: [value])
459
645
  }
646
+
460
647
  /**
461
648
  Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
462
649
  - parameter selector: The selector to identify the component with updated values.
463
650
  - parameter value: The value to be passed on to BlueConic.
464
651
  */
465
- @objc func registerUpdateValuesEvent(_ selector: String, withValue value: String) -> Void {
466
- getBlueConicEventManager().publish(UpdateValuesEvent(selector: selector, values: [value]))
652
+ @objc func publishUpdateValuesEventWithCallback(_ selector: String, withValue value: String, withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
653
+ self.getBlueConicClientInstance().getEventManager().publishUpdateValuesEvent(selector: selector, values: [value], callback: { result in
654
+ if result.success {
655
+ callback([true, nil])
656
+ } else if let error = result.error {
657
+ callback([false, error.nsError.localizedDescription])
658
+ }
659
+ })
467
660
  }
468
661
 
469
662
  /**
@@ -471,10 +664,24 @@ class BlueConicClientModule: RCTEventEmitter {
471
664
  - parameter name: The name to identify the event.
472
665
  - parameter values: The values to pass to BlueConic as context of the event.
473
666
  */
474
- @objc func registerAdvancedEvent(_ name: String, withValues values: [String]) -> Void {
475
- getBlueConicEventManager().publish(AdvancedEvent(eventName: name, context: values))
667
+ @objc func publishAdvancedEvent(_ name: String, withValues values: [String]) -> Void {
668
+ self.getBlueConicClientInstance().getEventManager().publishAdvancedEvent(eventName: name, context: values)
476
669
  }
477
670
 
671
+ /**
672
+ Creates an AdvancedEvent with the given name and values, and publishes the event using the EventManager.
673
+ - parameter name: The name to identify the event.
674
+ - parameter values: The values to pass to BlueConic as context of the event.
675
+ */
676
+ @objc func publishAdvancedEventWithCallback(_ name: String, withValues values: [String], withCallback callback: @escaping RCTResponseSenderBlock) -> Void {
677
+ self.getBlueConicClientInstance().getEventManager().publishAdvancedEvent(eventName: name, context: values, callback: { result in
678
+ if result.success {
679
+ callback([true, nil])
680
+ } else if let error = result.error {
681
+ callback([false, error.nsError.localizedDescription])
682
+ }
683
+ })
684
+ }
478
685
 
479
686
  /**
480
687
  Empty method. This method exists purely because we expose a method named destroyPlugins in the Android
@@ -486,14 +693,33 @@ class BlueConicClientModule: RCTEventEmitter {
486
693
  }
487
694
 
488
695
  /**
489
- Sends an event to the BlueConic server, indicating that a certain interaction was viewed, clicked, or converted for.
490
- - parameter eventType: The event type to register for the interaction. Possible events are "VIEW", "CLICK" or "CONVERSION".
491
- - parameter interactionId: The unique identifier of the interaction.
696
+ Resets the BlueConic profile id. This will generate a new profile id for the current user.
492
697
  */
493
- @objc func registerDialogueEvent(_ eventType: String, withInteractionId interactionId: String) -> Void {
494
- self.getBlueConicClientInstance().createEvent(eventType, properties: ["interactionId": interactionId])
698
+ @objc func clearProfileId(_ callback: @escaping RCTResponseSenderBlock) -> Void {
699
+ self.getBlueConicClientInstance().clearProfileId { result in
700
+ if result.success {
701
+ callback([true, nil])
702
+ } else if let error = result.error {
703
+ callback([false, error.nsError.localizedDescription])
704
+ }
705
+ }
495
706
  }
496
707
 
708
+ /**
709
+ Returns the current screen name.
710
+ - parameter promise: The promise to handle the obtained value. Promises are necessary in Native Modules
711
+ */
712
+ @objc func getScreenNameAsync(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) -> Void {
713
+ resolve([self.getBlueConicClientInstance().getScreenName() ?? ""])
714
+ }
715
+
716
+ /**
717
+ Returns the current screen name.
718
+ - parameter callback: The callback function to handle the obtained value. Callbacks are necessary in Native Modules
719
+ */
720
+ @objc func getScreenNameWithCallback(_ callback: RCTResponseSenderBlock) -> Void {
721
+ callback([self.getBlueConicClientInstance().getScreenName() ?? ""])
722
+ }
497
723
 
498
724
  /**
499
725
  Returns the current BlueConicClient instance
@@ -502,16 +728,10 @@ class BlueConicClientModule: RCTEventEmitter {
502
728
  private func getBlueConicClientInstance() -> BlueConic {
503
729
  let instance = BlueConic.getInstance()
504
730
  BlueConic.setPlatformInformation(platformName: BlueConicClientModule.platformName, platformVersion: BlueConicClientModule.platformVersion)
731
+ let viewController = RCTPresentedViewController()
732
+ instance.setContext(viewController)
505
733
  return instance
506
734
  }
507
-
508
- /**
509
- Returns the current BlueConicEventManager instance
510
- - returns: The BlueConicEventManager instance
511
- */
512
- private func getBlueConicEventManager() -> BlueConicEventManager {
513
- return BlueConicEventFactory.getInstance()
514
- }
515
735
 
516
736
  /**
517
737
  Return the segments in a list of dictionaries.
@@ -561,7 +781,7 @@ class BlueConicClientModule: RCTEventEmitter {
561
781
  - returns: An array of event names that may be published to the JavaScript.
562
782
  */
563
783
  override func supportedEvents() -> [String]! {
564
- return ["onBlueConicPluginLoad", "onBlueConicPluginDestroyed"]
784
+ return ["onBlueConicPluginLoad", "onBlueConicPluginDestroyed", "propertiesDialogueEvent"]
565
785
  }
566
786
 
567
787
  /**
@@ -578,3 +798,27 @@ class BlueConicClientModule: RCTEventEmitter {
578
798
  BlueConicClientModule.hasListeners = false
579
799
  }
580
800
  }
801
+
802
+ class DefaultEventHandler: EventHandler {
803
+ func handleEvent(_ event: Event) {
804
+ // Default implementation does nothing
805
+ }
806
+ }
807
+
808
+ class PropertiesDialogueHandler: EventHandler {
809
+ private let eventName: String
810
+
811
+ init(eventName: String) {
812
+ self.eventName = eventName
813
+ }
814
+
815
+ func handleEvent(_ event: BlueConicClient.Event) {
816
+ let propertiesDialogueEvent = event as! PropertiesDialogueEvent
817
+
818
+ var properties = [String: Any]()
819
+ properties["variantId"] = propertiesDialogueEvent.variantId
820
+ properties["position"] = propertiesDialogueEvent.position
821
+ properties["data"] = propertiesDialogueEvent.data
822
+ BlueConicClientModule.publishDialogueEvent(properties, eventName: self.eventName)
823
+ }
824
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueconic/blueconic-react-native",
3
- "version": "3.2.4",
3
+ "version": "4.0.1",
4
4
  "description": "The BlueConicClient Framework provides the basis for communicating with BlueConic.",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -26,8 +26,8 @@
26
26
  "author": "BlueConic (info@blueconic.com)",
27
27
  "license": "SEE LICENSE IN LICENSE",
28
28
  "nativeDependencies": {
29
- "android": "5.2.6",
30
- "ios": "3.3.0"
29
+ "android": "6.0.1",
30
+ "ios": "4.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react-native": "<1.0.0"