@blueconic/blueconic-react-native 3.2.4 → 4.0.0

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,1049 +1,1751 @@
1
-
2
1
  package com.blueconic.reactnative;
3
2
 
4
3
  import android.app.Activity;
4
+ import android.app.Application;
5
+ import android.os.Bundle;
5
6
  import android.os.Handler;
6
7
  import android.os.Looper;
8
+ import android.os.Parcelable;
7
9
  import android.util.Log;
8
-
10
+ import com.blueconic.BlueConicClient;
11
+ import com.blueconic.Segment;
9
12
  import com.blueconic.impl.BlueConicClientImpl;
10
- import com.facebook.react.bridge.ReactApplicationContext;
11
-
12
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
13
- import com.facebook.react.bridge.ReactMethod;
14
- import com.facebook.react.bridge.ReadableArray;
15
- import com.facebook.react.bridge.Callback;
16
- import com.facebook.react.bridge.Promise;
17
- import com.facebook.react.bridge.Arguments;
18
- import com.facebook.react.bridge.ReadableMap;
19
- import com.facebook.react.bridge.WritableArray;
20
- import com.facebook.react.bridge.WritableMap;
21
- import com.facebook.react.bridge.WritableNativeArray;
22
- import com.facebook.react.bridge.WritableNativeMap;
13
+ import com.blueconic.impl.configuration.BlueConicConfiguration;
14
+ import com.blueconic.plugin.events.Event;
15
+ import com.blueconic.plugin.events.EventHandler;
16
+ import com.blueconic.plugin.events.PropertiesDialogueEvent;
17
+ import com.facebook.react.bridge.*;
23
18
  import com.facebook.react.modules.core.DeviceEventManagerModule;
24
-
25
- import java.util.*;
19
+ import org.jetbrains.annotations.NotNull;
26
20
 
27
21
  import javax.annotation.Nonnull;
22
+ import java.util.*;
28
23
 
29
- import com.blueconic.BlueConicClient;
30
- import com.blueconic.BlueConicClientFactory;
31
- import com.blueconic.plugin.events.BlueConicEventFactory;
32
- import com.blueconic.plugin.events.BlueConicEventManager;
33
- import com.blueconic.plugin.events.ClickEvent;
34
- import com.blueconic.plugin.events.UpdateValuesEvent;
35
- import com.blueconic.plugin.events.FormSubmitEvent;
36
- import com.blueconic.plugin.events.UpdateContentEvent;
37
- import com.blueconic.plugin.events.AdvancedEvent;
24
+ import static com.facebook.react.bridge.Arguments.fromBundle;
25
+ import static com.facebook.react.bridge.Arguments.toList;
26
+ import static java.util.Collections.emptyList;
38
27
 
39
28
  public class BlueConicClientModule extends ReactContextBaseJavaModule {
40
- private static BlueConicClientModuleHelper helper;
41
- private ReactApplicationContext reactContext;
42
-
43
- /**
44
- * The constructor calls the constructor of the superclass and creates an instance of
45
- * the BlueConicClientModuleHelper class which is referred to by a static instance variable. This helper stores the
46
- * reactContext, making it available for use by the static publishReceivedParametersEvent method.
47
- * @param reactContext The application context.
48
- */
49
- public BlueConicClientModule(ReactApplicationContext reactContext) {
50
- super(reactContext);
51
- this.reactContext = reactContext;
52
- helper = new BlueConicClientModuleHelper(reactContext);
53
-
54
- // Delayed plugin class register due to availability of activity context
55
- new Handler(Looper.getMainLooper()).postDelayed(() -> {
56
- BlueConicClient blueConicClient = getBlueConicClientInstance();
57
- if (blueConicClient != null) {
58
- blueConicClient.registerPluginClass(BlueConicInteraction.class, "BlueConicClient.BlueConicInteraction");
59
- }
60
- }, 2000);
61
- }
62
-
63
- /**
64
- * The superclass ReactContextBaseJavaModule requires that the getName method is implemented.
65
- * The purpose of this method is to return the name of the Native Module which represents this class in JavaScript.
66
- * Hence, this method allows us to access the native module through NativeModules.BlueConic in JavaScript.
67
- * @return String representing the name of this module.
68
- */
69
- @Override
70
- public String getName() {
71
- return "BlueConicClient";
72
- }
73
-
74
-
75
- // MARK: GETTERS
76
- /**
77
- * Gets the ID of the BlueConic profile. The value is passed to the provided promiseas a String.
78
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
79
- * to pass values back to the JavaScript.
80
- */
81
- @ReactMethod
82
- public void getProfileId(@Nonnull Promise promise) {
83
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
84
- String profileId = "";
85
- if (blueConicClient != null) {
86
- profileId = blueConicClient.getProfileId();
87
- }
88
-
89
- promise.resolve(profileId);
90
- }
91
-
92
- /**
93
- * Gets the values of the specified profile property. The values are passed to the provided promise
94
- * as separate Strings.
95
- * @param property The profile property for which to get the values.
96
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
97
- * to pass values back to the JavaScript.
98
- */
99
- @ReactMethod
100
- public void getProfileValue(@Nonnull String property, @Nonnull Promise promise) {
101
- final List<String> result = new ArrayList<String>();
102
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
103
-
104
- if (blueConicClient != null) {
105
- result.add(blueConicClient.getProfileValue(property));
106
- }
107
-
108
- promise.resolve(result);
109
- }
110
-
111
- /**
112
- * Gets the values of the specified profile property. The values are passed to the provided promise
113
- * as separate Strings.
114
- * @param property The profile property for which to get the values.
115
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
116
- * to pass values back to the JavaScript.
117
- */
118
- @ReactMethod
119
- public void getProfileValues(@Nonnull String property, @Nonnull Promise promise) {
120
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
121
-
122
- if (blueConicClient != null) {
123
- Collection<String> values = blueConicClient.getProfileValues(property);
124
- promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
125
- } else {
126
- promise.resolve(Arguments.createArray());
127
- }
128
- }
129
-
130
- /**
131
- * Gets the ID of the BlueConic profile. The value is passed to the provided callback function as a String.
132
- * @param callback The Callback function to handle the obtained value. Callbacks are necessary in Native Modules
133
- * to pass values back to the JavaScript.
134
- */
135
- @ReactMethod
136
- public void getProfileIdWithCallback(@Nonnull Callback callback) {
137
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
138
- String profileId = "";
139
- if (blueConicClient != null) {
140
- profileId = blueConicClient.getProfileId();
141
- }
142
-
143
- callback.invoke(profileId);
144
- }
145
-
146
- /**
147
- * Gets the values of the specified profile property. The values are passed to the provided callback function
148
- * as separate Strings.
149
- * @param property The profile property for which to get the values.
150
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
151
- * to pass values back to the JavaScript.
152
- */
153
- @ReactMethod
154
- public void getProfileValueWithCallback(@Nonnull String property, @Nonnull Callback callback) {
155
- final List<String> result = new ArrayList<String>();
156
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
157
-
158
- if (blueConicClient != null) {
159
- result.add(blueConicClient.getProfileValue(property));
160
- }
161
-
162
- callback.invoke(result);
163
- }
164
-
165
- /**
166
- * Gets the values of the specified profile property. The values are passed to the provided callback function
167
- * as separate Strings.
168
- * @param property The profile property for which to get the values.
169
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
170
- * to pass values back to the JavaScript.
171
- */
172
- @ReactMethod
173
- public void getProfileValuesWithCallback(@Nonnull String property, @Nonnull Callback callback) {
174
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
175
-
176
- if (blueConicClient != null) {
177
- Collection<String> values = blueConicClient.getProfileValues(property);
178
- callback.invoke(values.toArray());
179
- } else {
180
- callback.invoke(new ArrayList<String>());
181
- }
182
- }
183
-
184
- /**
185
- * Gets the privacy legislation. The values are passed to the provided promise
186
- * as separate String.
187
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
188
- * to pass values back to the JavaScript.
189
- */
190
- @ReactMethod
191
- public void getPrivacyLegislation(@Nonnull Promise promise) {
192
- final List<String> result = new ArrayList<String>();
193
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
194
-
195
- if (blueConicClient != null) {
196
- result.add(blueConicClient.getPrivacyLegislation());
197
- }
198
-
199
- promise.resolve(result);
200
- }
201
-
202
- /**
203
- * Gets the privacy legislation. The values are passed to the provided callback function
204
- * as separate String.
205
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
206
- * to pass values back to the JavaScript.
207
- */
208
- @ReactMethod
209
- public void getPrivacyLegislationWithCallback(@Nonnull Callback callback) {
210
- final List<String> result = new ArrayList<String>();
211
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
212
-
213
- if (blueConicClient != null) {
214
- result.add(blueConicClient.getPrivacyLegislation());
215
- }
216
-
217
- callback.invoke(result);
218
- }
219
-
220
- /**
221
- * Gets the consented objectives. The values are passed to the provided promise
222
- * as separate Strings.
223
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
224
- * to pass values back to the JavaScript.
225
- */
226
- @ReactMethod
227
- public void getConsentedObjectives(@Nonnull Promise promise) {
228
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
229
-
230
- if (blueConicClient != null) {
231
- Collection<String> values = blueConicClient.getConsentedObjectives();
232
- promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
233
- } else {
234
- promise.resolve(Arguments.createArray());
235
- }
236
- }
237
-
238
- /**
239
- * Gets the consented objectives. The values are passed to the provided callback function
240
- * as separate Strings.
241
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
242
- * to pass values back to the JavaScript.
243
- */
244
- @ReactMethod
245
- public void getConsentedObjectivesWithCallback(@Nonnull Callback callback) {
246
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
247
-
248
- if (blueConicClient != null) {
249
- Collection<String> values = blueConicClient.getConsentedObjectives();
250
- callback.invoke(values.toArray());
251
- } else {
252
- callback.invoke(new ArrayList<String>());
253
- }
254
- }
255
-
256
- /**
257
- * Gets the refused objectives. The values are passed to the provided promise
258
- * as separate Strings.
259
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
260
- * to pass values back to the JavaScript.
261
- */
262
- @ReactMethod
263
- public void getRefusedObjectives(@Nonnull Promise promise) {
264
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
265
-
266
- if (blueConicClient != null) {
267
- Collection<String> values = blueConicClient.getRefusedObjectives();
268
- promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
269
- } else {
270
- promise.resolve(Arguments.createArray());
271
- }
272
- }
273
-
274
- /**
275
- * Gets the refused objectives. The values are passed to the provided callback function
276
- * as separate Strings.
277
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
278
- * to pass values back to the JavaScript.
279
- */
280
- @ReactMethod
281
- public void getRefusedObjectivesWithCallback(@Nonnull Callback callback) {
282
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
283
-
284
- if (blueConicClient != null) {
285
- Collection<String> values = blueConicClient.getRefusedObjectives();
286
- callback.invoke(values.toArray());
287
- } else {
288
- callback.invoke(new ArrayList<String>());
289
- }
290
- }
291
-
292
- /**
293
- * Setter for the locale to get the parameters for. By default, the default locale configured in BlueConic is used.
294
- * @param locale the locale, e.g. 'en_US'.
295
- */
296
- @ReactMethod
297
- public void setLocale(@Nonnull String locale) {
298
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
299
- if (blueConicClient != null) {
300
- blueConicClient.setLocale(locale);
301
- }
302
- }
303
-
304
- /**
305
- * Gets the segments of the profile.
306
- * To retrieve and update the Segments you have to register a pageview first.
307
- * The values are passed to the provided promise
308
- * as a list of Objects containing id and name.
309
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
310
- * to pass values back to the JavaScript.
311
- */
312
- @ReactMethod
313
- public void getSegments(@Nonnull Promise promise) {
314
- promise.resolve(getFormattedSegments());
315
- }
316
-
317
- /**
318
- * Gets the segments of the profile.
319
- * To retrieve and update the Segments you have to register a pageview first.
320
- * The values are passed to the provided promise
321
- * as a list of Objects containing id and name.
322
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
323
- * to pass values back to the JavaScript.
324
- */
325
- @ReactMethod
326
- public void getSegmentsWithCallback(@Nonnull Callback callback) {
327
- callback.invoke(getFormattedSegments());
328
- }
329
-
330
- // MARK: ADDERS
331
- /**
332
- * Adds the given values to the specified profile property.
333
- * @param property The profile property to which to add the values.
334
- * @param values A ReadableArray containing Strings that will be added to the profile property.
335
- */
336
- @ReactMethod
337
- public void addProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
338
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
339
- if (blueConicClient != null) {
340
- blueConicClient.addProfileValues(property, Arguments.toList(values));
341
- }
342
- }
343
-
344
- /**
345
- * Adds the given values to the specified profile property.
346
- * @param property The profile property to which to add the values.
347
- * @param value A ReadableArray containing Strings that will be added to the profile property.
348
- */
349
- @ReactMethod
350
- public void addProfileValue(@Nonnull String property, @Nonnull String value) {
351
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
352
- if (blueConicClient != null) {
353
- blueConicClient.addProfileValue(property, value);
354
- }
355
- }
356
-
357
- /**
358
- * Adds an objective to the consented objectives list.
359
- * @param objectiveId The id of the objective to add to consented objectives.
360
- */
361
- @ReactMethod
362
- public void addConsentedObjective(@Nonnull String objectiveId) {
363
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
364
- if (blueConicClient != null) {
365
- blueConicClient.addConsentedObjective(objectiveId);
366
- }
367
- }
368
-
369
- /**
370
- * Adds an objective to the refused objectives list.
371
- * @param objectiveId The id of the objective to add to refused objectives.
372
- */
373
- @ReactMethod
374
- public void addRefusedObjective(@Nonnull String objectiveId) {
375
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
376
- if (blueConicClient != null) {
377
- blueConicClient.addRefusedObjective(objectiveId);
378
- }
379
- }
380
-
381
- // MARK: SETTERS
382
- /**
383
- * Sets the given values for the specified profile property.
384
- * @param property The profile property for which to set the values.
385
- * @param values A ReadableArray containing Strings that will be set as the new values for the profile property.
386
- */
387
- @ReactMethod
388
- public void setProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
389
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
390
- if (blueConicClient != null) {
391
- blueConicClient.setProfileValues(property, Arguments.toList(values));
392
- }
393
- }
394
-
395
- /**
396
- * Set the given value for the specified profile property.
397
- * @param property The profile property for which to set the values.
398
- * @param value A ReadableArray containing Strings that will be set as the new values for the profile property.
399
- */
400
- @ReactMethod
401
- public void setProfileValue(@Nonnull String property, @Nonnull String value) {
402
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
403
- if (blueConicClient != null) {
404
- blueConicClient.setProfileValue(property, value);
405
- }
406
- }
407
-
408
- /**
409
- * Increments the given values to the specified profile property.
410
- * @param property The profile property to which to increment the values.
411
- * @param value A ReadableArray containing Strings that will be incremented to the profile property.
412
- */
413
- @ReactMethod
414
- public void incrementProfileValue(@Nonnull String property, @Nonnull String value) {
415
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
416
- if (blueConicClient != null) {
417
- blueConicClient.incrementProfileValue(property, value);
418
- }
419
- }
420
-
421
- /**
422
- * Set the privacy legislation.
423
- * @param privacyLegislation The privacy legislation.
424
- */
425
- @ReactMethod
426
- public void setPrivacyLegislation(@Nonnull String privacyLegislation) {
427
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
428
- if (blueConicClient != null) {
429
- blueConicClient.setPrivacyLegislation(privacyLegislation);
430
- }
431
- }
432
-
433
- /**
434
- * Sets the given objectives for consented objectives.
435
- * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
436
- */
437
- @ReactMethod
438
- public void setConsentedObjectives(@Nonnull ReadableArray objectiveIds) {
439
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
440
- if (blueConicClient != null) {
441
- blueConicClient.setConsentedObjectives(Arguments.toList(objectiveIds));
442
- }
443
- }
444
-
445
- /**
446
- * Sets the given objectives for consented objectives.
447
- * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
448
- */
449
- @ReactMethod
450
- public void setRefusedObjectives(@Nonnull ReadableArray objectiveIds) {
451
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
452
- if (blueConicClient != null) {
453
- blueConicClient.setRefusedObjectives(Arguments.toList(objectiveIds));
454
- }
455
- }
456
-
457
- /**
458
- * Set enabled.
459
- * Define to enable and disable the BlueConicClient
460
- * To prevent or re-activate tracking data
461
- * @param isEnabled to enable or disable the BlueConicClient.
462
- */
463
- @ReactMethod
464
- public void setEnabled(@Nonnull Boolean isEnabled) {
465
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
466
- if (blueConicClient != null) {
467
- blueConicClient.setEnabled(isEnabled == null ? false : isEnabled.booleanValue());
468
- }
469
-
470
- }
471
-
472
- /**
473
- * Return is BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings.
474
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
475
- * Native Modules to pass values back to the JavaScript.
476
- */
477
- @ReactMethod
478
- public void isEnabled(@Nonnull Promise promise) {
479
- final List<Boolean> result = new ArrayList<Boolean>();
480
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
481
-
482
- if (blueConicClient != null) {
483
- result.add(Boolean.valueOf(blueConicClient.isEnabled()));
484
- }
485
-
486
- promise.resolve(result);
487
- }
488
-
489
- /**
490
- * Return is BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings
491
- * @param callback: The callback function to handle the obtained value. Callbacks are necessary in
492
- * Native Modules to pass values back to the JavaScript.
493
- */
494
- @ReactMethod
495
- public void isEnabledWithCallback(@Nonnull Callback callback) {
496
- final List<Boolean> result = new ArrayList<Boolean>();
497
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
498
-
499
- if (blueConicClient != null) {
500
- result.add(Boolean.valueOf(blueConicClient.isEnabled()));
501
- }
502
-
503
- callback.invoke(result);
504
- }
505
-
506
- /**
507
- * Return whether the BlueConic profile is part of the BlueConic segment. The value is passed to the provided callback function as Boolean.
508
- * @param segmentId The id of the segment
509
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
510
- * Native Modules to pass values back to the JavaScript.
511
- */
512
- @ReactMethod
513
- public void hasSegment(@Nonnull String segmentId, @Nonnull Promise promise) {
514
- final List<Boolean> result = new ArrayList<Boolean>();
515
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
516
-
517
- if (blueConicClient != null) {
518
- result.add(Boolean.valueOf(blueConicClient.hasSegment(segmentId)));
519
- }
520
-
521
- promise.resolve(result);
522
- }
523
-
524
- /**
525
- * Return whether the BlueConic profile is part of the BlueConic segment. The value is passed to the provided callback function as Boolean.
526
- * @param segmentId The id of the segment
527
- * @param callback: The callback function to handle the obtained value. Callbacks are necessary in
528
- * Native Modules to pass values back to the JavaScript.
529
- */
530
- @ReactMethod
531
- public void hasSegmentWithCallback(@Nonnull String segmentId, @Nonnull Callback callback) {
532
- final List<Boolean> result = new ArrayList<Boolean>();
533
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
534
-
535
- if (blueConicClient != null) {
536
- result.add(Boolean.valueOf(blueConicClient.hasSegment(segmentId)));
537
- }
538
-
539
- callback.invoke(result);
540
- }
541
-
542
- // MARK: REGISTERS
543
- /**
544
- * Create Event.
545
- * @param eventName The name of the event
546
- * @param readableMap The readable map retrieved from React native
547
- */
548
- @ReactMethod
549
- public void createEvent(@Nonnull String eventName, ReadableMap readableMap) {
550
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
551
- final Map<String, Object> properties = readableMap.toHashMap();
552
-
553
- if (blueConicClient != null) {
554
- blueConicClient.createEventWithData(eventName, properties);
555
- }
556
- }
557
-
558
- /**
559
- * Create Event.
560
- * @param eventName The name of the event
561
- * @param readableMap The readable map retrieved from React native
562
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
563
- * Native Modules to pass values back to the JavaScript.
564
- */
565
- @ReactMethod
566
- public void createEventSync(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Promise promise) {
567
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
568
- final Map<String, Object> properties = readableMap.toHashMap();
569
-
570
- if (blueConicClient != null) {
571
- blueConicClient.createEventWithData(eventName, properties, new Runnable() {
572
- @Override
573
- public void run() {
574
- promise.resolve(Arguments.createArray());
575
- }
576
- });
577
- return;
578
- }
579
-
580
- promise.resolve(Arguments.createArray());
581
- }
582
-
583
- /**
584
- * Create Event.
585
- * @param eventName The name of the event
586
- * @param readableMap The readable map retrieved from React native
587
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
588
- * to pass values back to the JavaScript.
589
- */
590
- @ReactMethod
591
- public void createEventSyncWithCallback(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Callback callback) {
592
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
593
- final Map<String, Object> properties = readableMap.toHashMap();
594
-
595
- if (blueConicClient != null) {
596
- blueConicClient.createEventWithData(eventName, properties, new Runnable() {
597
- @Override
598
- public void run() {
599
- callback.invoke(Arguments.createArray());
600
- }
601
- });
602
- return;
603
- }
604
-
605
- callback.invoke(Arguments.createArray());
606
- }
607
-
608
- /**
609
- * Update sync the BlueConic Profile
610
- */
611
- @ReactMethod
612
- public void updateProfile() {
613
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
614
-
615
- if (blueConicClient != null) {
616
- blueConicClient.updateProfile();
617
- }
618
- }
619
-
620
- /**
621
- * Update sync the BlueConic Profile
622
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
623
- * Native Modules to pass values back to the JavaScript.
624
- */
625
- @ReactMethod
626
- public void updateProfileSync(@Nonnull final Promise promise) {
627
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
628
-
629
- if (blueConicClient != null) {
630
- blueConicClient.updateProfile(new Runnable() {
631
- @Override
632
- public void run() {
633
- promise.resolve(Arguments.createArray());
634
- }
635
- });
636
-
637
- return;
638
- }
639
-
640
- promise.resolve(Arguments.createArray());
641
- }
642
-
643
- /**
644
- * Update sync the BlueConic Profile
645
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
646
- * to pass values back to the JavaScript.
647
- */
648
- @ReactMethod
649
- public void updateProfileSyncWithCallback(@Nonnull final Callback callback) {
650
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
651
-
652
- if (blueConicClient != null) {
653
- blueConicClient.updateProfile(new Runnable() {
654
- @Override
655
- public void run() {
656
- callback.invoke(Arguments.createArray());
657
- }
658
- });
659
-
660
- return;
661
- }
662
-
663
- callback.invoke(Arguments.createArray());
664
- }
665
-
666
- /**
667
- * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
668
- * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
669
- * @param screenName The name of the screen.
670
- */
671
- @ReactMethod
672
- public void registerPageView(@Nonnull String screenName) {
673
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
674
- if (blueConicClient != null) {
675
- // blueConicClient instance must have an activity or application
676
- final Map<String, String> properties = new HashMap<>();
677
- properties.put("screenName", screenName);
678
- Activity activity = getCurrentActivity();
679
- if (activity == null) {
680
- activity = new Activity();
681
- }
682
-
683
- blueConicClient.createEvent("PAGEVIEW", properties, activity);
684
- } else {
685
- Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
686
- }
687
- }
688
-
689
- /**
690
- * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
691
- * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
692
- * @param screenName The name of the screen.
693
- */
694
- @ReactMethod
695
- public void registerPageViewSync(@Nonnull String screenName, @Nonnull final Promise promise) {
696
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
697
- if (blueConicClient != null) {
698
- // blueConicClient instance must have an activity or application
699
- final Map<String, String> properties = new HashMap<>();
700
- properties.put("screenName", screenName);
701
- Activity activity = getCurrentActivity();
702
- if (activity == null) {
703
- activity = new Activity();
704
- }
705
-
706
- blueConicClient.createEvent("PAGEVIEW", properties, activity, new Runnable() {
707
- @Override
708
- public void run() {
709
- promise.resolve(Arguments.createArray());
710
- }
711
- });
712
- } else {
713
- Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
714
- promise.resolve(Arguments.createArray());
715
- }
716
- }
717
-
718
- /**
719
- * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
720
- * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
721
- * @param screenName The name of the screen.
722
- */
723
- @ReactMethod
724
- public void registerPageViewSyncCallback(@Nonnull String screenName, @Nonnull final Callback callback) {
725
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
726
- if (blueConicClient != null) {
727
- // blueConicClient instance must have an activity or application
728
- final Map<String, String> properties = new HashMap<>();
729
- properties.put("screenName", screenName);
730
- Activity activity = getCurrentActivity();
731
- if (activity == null) {
732
- activity = new Activity();
733
- }
734
-
735
- blueConicClient.createEvent("PAGEVIEW", properties, activity, new Runnable() {
736
- @Override
737
- public void run() {
738
- callback.invoke(Arguments.createArray());
739
- }
740
- });
741
- } else {
742
- Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
743
- callback.invoke(Arguments.createArray());
744
- }
745
- }
746
-
747
- /**
748
- * Create Timeline Event.
749
- * @param eventType The type of event
750
- * @param eventDate The date of the event
751
- * @param readableMap The readable map retrieved from React native
752
- */
753
- @ReactMethod
754
- public void registerTimelineEvent(@Nonnull String eventType, double eventDate, ReadableMap readableMap) {
755
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
756
- final Map<String, Object> properties = readableMap.toHashMap();
757
-
758
- if (blueConicClient != null) {
759
- blueConicClient.createTimelineEvent(eventType, new Date((long) eventDate), properties, null);
760
- }
761
- }
762
-
763
- /**
764
- * Create Timeline Event.
765
- * @param eventType The type of event
766
- * @param eventDate The date of the event
767
- * @param readableMap The readable map retrieved from React native
768
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
769
- * Native Modules to pass values back to the JavaScript.
770
- */
771
- @ReactMethod
772
- public void registerTimelineEventSync(@Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Promise promise) {
773
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
774
- final Map<String, Object> properties = readableMap.toHashMap();
775
-
776
- if (blueConicClient != null) {
777
- blueConicClient.createTimelineEvent(eventType, new Date((long) eventDate), properties, new Runnable() {
778
- @Override
779
- public void run() {
780
- promise.resolve(Arguments.createArray());
781
- }
782
- });
783
- return;
784
- }
785
-
786
- promise.resolve(Arguments.createArray());
787
- }
788
-
789
- /**
790
- * Create Timeline Event.
791
- * @param eventType The type of event
792
- * @param eventDate The date of the event
793
- * @param readableMap The readable map retrieved from React native
794
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
795
- * to pass values back to the JavaScript.
796
- */
797
- @ReactMethod
798
- public void registerTimelineEventSyncWithCallback(@Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Callback callback) {
799
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
800
- final Map<String, Object> properties = readableMap.toHashMap();
801
-
802
- if (blueConicClient != null) {
803
- blueConicClient.createTimelineEvent(eventType, new Date((long) eventDate), properties, new Runnable() {
804
- @Override
805
- public void run() {
806
- callback.invoke(Arguments.createArray());
807
- }
808
- });
809
- return;
810
- }
811
-
812
- callback.invoke(Arguments.createArray());
813
- }
814
-
815
- /**
816
- * Create Timeline Event.
817
- * @param eventType The type of event
818
- * @param eventDate The date of the event
819
- * @param readableMap The readable map retrieved from React native
820
- */
821
- @ReactMethod
822
- public void registerTimelineEventById(@Nonnull String eventId, @Nonnull String eventType, double eventDate, ReadableMap readableMap) {
823
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
824
- final Map<String, Object> properties = readableMap.toHashMap();
825
-
826
- if (blueConicClient != null) {
827
- blueConicClient.createTimelineEventById(eventId, eventType, new Date((long) eventDate), properties, null);
828
- }
829
- }
830
-
831
- /**
832
- * Create Timeline Event.
833
- * @param eventType The type of event
834
- * @param eventDate The date of the event
835
- * @param readableMap The readable map retrieved from React native
836
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
837
- * Native Modules to pass values back to the JavaScript.
838
- */
839
- @ReactMethod
840
- public void registerTimelineEventByIdSync(@Nonnull String eventId, @Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Promise promise) {
841
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
842
- final Map<String, Object> properties = readableMap.toHashMap();
843
-
844
- if (blueConicClient != null) {
845
- blueConicClient.createTimelineEventById(eventId, eventType, new Date((long) eventDate), properties, new Runnable() {
846
- @Override
847
- public void run() {
848
- promise.resolve(Arguments.createArray());
849
- }
850
- });
851
- return;
852
- }
853
-
854
- promise.resolve(Arguments.createArray());
855
- }
856
-
857
- /**
858
- * Create Timeline Event.
859
- * @param eventType The type of event
860
- * @param eventDate The date of the event
861
- * @param readableMap The readable map retrieved from React native
862
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
863
- * to pass values back to the JavaScript.
864
- */
865
- @ReactMethod
866
- public void registerTimelineEventByIdSyncWithCallback(@Nonnull String eventId, @Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Callback callback) {
867
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
868
- final Map<String, Object> properties = readableMap.toHashMap();
869
-
870
- if (blueConicClient != null) {
871
- blueConicClient.createTimelineEventById(eventId, eventType, new Date((long) eventDate), properties, new Runnable() {
872
- @Override
873
- public void run() {
874
- callback.invoke(Arguments.createArray());
875
- }
876
- });
877
- return;
878
- }
879
-
880
- callback.invoke(Arguments.createArray());
881
- }
882
-
883
- /**
884
- * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
885
- * @param selector The selector to identify the clicked component.
886
- */
887
- @ReactMethod
888
- public void registerClickEvent(@Nonnull String selector) {
889
- getBlueConicEventManagerInstance().publish(new ClickEvent(selector));
890
- }
891
-
892
- /**
893
- * Creates a ClickEvent for the given selector and values, and publishes the event using the EventManager.
894
- * @param selector The selector to identify the clicked component.
895
- * @param values The values to pass to BlueConic as context of the event.
896
- */
897
- @ReactMethod
898
- public void registerClickEventWithContext(@Nonnull String selector, @Nonnull ReadableArray values) {
899
- getBlueConicEventManagerInstance().publish(new ClickEvent(selector, Arguments.toList(values)));
900
- }
901
-
902
- /**
903
- * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
904
- * @param selector The selector to identify the clicked component.
905
- */
906
- @ReactMethod
907
- public void registerFormSubmitEvent(@Nonnull String selector) {
908
- getBlueConicEventManagerInstance().publish(new FormSubmitEvent(selector));
909
- }
910
-
911
- /**
912
- * Creates a ClickEvent for the given selector and values, and publishes the event using the EventManager.
913
- * @param selector The selector to identify the clicked component.
914
- * @param values The values to pass to BlueConic as context of the event.
915
- */
916
- @ReactMethod
917
- public void registerFormSubmitEventWithContext(@Nonnull String selector, @Nonnull ReadableArray values) {
918
- getBlueConicEventManagerInstance().publish(new FormSubmitEvent(selector, Arguments.toList(values)));
919
- }
920
-
921
- /**
922
- * Creates an UpdateContentEvent for the given selector and value, and publishes the event using the EventManager.
923
- * @param selector The selector to identify the component with updated values.
924
- * @param value The value to be passed on to BlueConic.
925
- */
926
- @ReactMethod
927
- public void registerUpdateContentEvent(@Nonnull String selector, @Nonnull String value) {
928
- UpdateContentEvent event = new UpdateContentEvent(selector, value);
929
- getBlueConicEventManagerInstance().publish(event);
930
- }
931
-
932
- /**
933
- * Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
934
- * @param selector The selector to identify the component with updated values.
935
- * @param value The value to be passed on to BlueConic.
936
- */
937
- @ReactMethod
938
- public void registerUpdateValuesEvent(@Nonnull String selector, @Nonnull String value) {
939
- UpdateValuesEvent event = new UpdateValuesEvent(selector, Collections.singletonList(value));
940
- getBlueConicEventManagerInstance().publish(event);
941
- }
942
-
943
- /**
944
- * Creates an AdvancedEvent with the given name and values, and publishes the event using the EventManager.
945
- * @param name The name to identify the event.
946
- * @param values The values to pass to BlueConic as context of the event.
947
- */
948
- @ReactMethod
949
- public void registerAdvancedEvent(@Nonnull String name, @Nonnull ReadableArray values) {
950
- AdvancedEvent event = new AdvancedEvent(name, Arguments.toList(values));
951
- getBlueConicEventManagerInstance().publish(event);
952
- }
953
-
954
-
955
-
956
- /**
957
- * Destroys all active BlueConic plugins (i.e. instances of listeners and dialogues). This method must be called
958
- * in the onPause of an activity if the app targets Android API versions before API 14. It should also be called if
959
- * one switches screens in the app without calling the onPause of the previous Activity.
960
- *
961
- */
962
- @ReactMethod
963
- public void destroyPlugins() {
964
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
965
- if (blueConicClient != null) {
966
- blueConicClient.destroyPlugins();
967
- }
968
- }
969
-
970
- /**
971
- * Sends an event to the BlueConic server, indicating that a certain interaction was viewed, clicked, or converted for.
972
- * @param eventType The event type to register for the interaction. Possible events are "VIEW", "CLICK" and "CONVERSION".
973
- * @param interactionId The unique identifier of the interaction.
974
- */
975
- @ReactMethod
976
- public void registerDialogueEvent(@Nonnull String eventType, @Nonnull String interactionId) {
977
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
978
- if (blueConicClient != null) {
979
- final Map<String, String> interactionIdMap = new HashMap<>();
980
- interactionIdMap.put("interactionId", interactionId);
981
- blueConicClient.createEvent(eventType, interactionIdMap);
982
- }
983
- }
984
-
985
-
986
- /**
987
- * Returns an instance of the BlueConicClient
988
- * @return BlueConicClient
989
- */
990
- private BlueConicClient getBlueConicClientInstance() {
991
- // Retrieve current Activity from ReactContextBaseJavaModule
992
- final Activity currentActivity = getCurrentActivity();
993
- if (currentActivity != null) {
994
- // Activity found and return a BlueConicClient instance
995
- BlueConicClient instance = BlueConicClientFactory.INSTANCE.getInstance(currentActivity);
996
- //Set platform information
997
- BlueConicClientImpl implInstance = (BlueConicClientImpl) instance;
998
- implInstance.setPlatformInformation(BuildConfig.PLATFORM_NAME, BuildConfig.PLATFORM_VERSION);
999
- return instance;
1000
- }
1001
-
1002
- return null;
1003
- }
1004
-
1005
- /**
1006
- * Returns an instance of the BlueConicEventManager
1007
- * @return BlueConicClient
1008
- */
1009
- private BlueConicEventManager getBlueConicEventManagerInstance() {
1010
- return BlueConicEventFactory.INSTANCE.getInstance(getBlueConicClientInstance());
1011
- }
1012
-
1013
- private WritableArray getFormattedSegments() {
1014
- final WritableArray result = new WritableNativeArray();
1015
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
1016
-
1017
- if (blueConicClient == null) {
1018
- return result;
1019
- }
1020
- final Collection<BlueConicClient.Segment> segments = blueConicClient.getSegments();
1021
-
1022
- for (BlueConicClient.Segment segment : segments) {
1023
- final WritableMap item = new WritableNativeMap();
1024
- item.putString("id", segment.getId());
1025
- item.putString("name", segment.getName());
1026
- result.pushMap(item);
1027
- }
1028
-
1029
- return result;
1030
- }
1031
-
1032
- /**
1033
- * Static method that is called by the BlueConicInteraction when it receives the parameters of the dialogue,
1034
- * and when the dialogue is destroyed by the BlueConic SDK. An event is published to which the JavaScript of the
1035
- * app should subscribe.
1036
- * @param properties The properties of the dialogues as received from BlueConic.
1037
- * @param eventName The name of the event to be published.
1038
- */
1039
- static void publishDialogueEvent(@Nonnull Map<String, Object> properties, String eventName) {
1040
- WritableMap map = Arguments.makeNativeMap(properties);
1041
-
1042
- if (helper != null) {
1043
- helper
1044
- .getReactContext()
1045
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
1046
- .emit(eventName, map);
1047
- }
1048
- }
29
+ private static BlueConicClientModuleHelper helper;
30
+ private final ReactApplicationContext reactContext;
31
+
32
+ /**
33
+ * The constructor calls the constructor of the superclass and creates an instance of
34
+ * the BlueConicClientModuleHelper class which is referred to by a static instance variable. This helper stores the
35
+ * reactContext, making it available for use by the static publishReceivedParametersEvent method.
36
+ *
37
+ * @param reactContext The application context.
38
+ */
39
+ public BlueConicClientModule(ReactApplicationContext reactContext) {
40
+ super(reactContext);
41
+ this.reactContext = reactContext;
42
+ helper = new BlueConicClientModuleHelper(reactContext);
43
+
44
+ // Delayed plugin class register due to availability of activity context
45
+ getHandler().postDelayed(() -> {
46
+ BlueConicClient blueConicClient = getBlueConicClientInstance();
47
+ if (blueConicClient != null) {
48
+ blueConicClient.registerPluginClass(BlueConicInteraction.class, "BlueConicClient.BlueConicInteraction");
49
+ }
50
+ }, 2000);
51
+ }
52
+
53
+ /**
54
+ * The superclass ReactContextBaseJavaModule requires that the getName method is implemented.
55
+ * The purpose of this method is to return the name of the Native Module which represents this class in JavaScript.
56
+ * Hence, this method allows us to access the native module through NativeModules.BlueConic in JavaScript.
57
+ *
58
+ * @return String representing the name of this module.
59
+ */
60
+ @Override
61
+ public String getName() {
62
+ return "BlueConicClient";
63
+ }
64
+
65
+ @ReactMethod
66
+ public void initialize(@Nonnull ReadableMap readableMap, @Nonnull Callback callback) {
67
+ final Map<String, Object> properties = readableMap.toHashMap();
68
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
69
+
70
+ BlueConicConfiguration configuration = new BlueConicConfiguration.Builder()
71
+ .setHostName((String)Objects.requireNonNull(properties.get("bc_hostname")))
72
+ .setDebugMode((Boolean)Objects.requireNonNull(properties.get("bc_debug")))
73
+ .build((Application) getReactApplicationContext().getApplicationContext());
74
+
75
+ if (properties.containsKey("override_app_id") && properties.get("override_app_id") != null) {
76
+ configuration.setAppID((String) properties.get("override_app_id"));
77
+ }
78
+
79
+ if (properties.containsKey("simulator_username") && properties.get("simulator_username") != null
80
+ && properties.containsKey("simulator_session_id") && properties.get("simulator_session_id") != null) {
81
+ configuration.setSimulatorUsername((String) properties.get("simulator_username"));
82
+ configuration.setSimulatorMobileSessionId((String) properties.get("simulator_session_id"));
83
+ }
84
+
85
+ if (blueConicClient != null) {
86
+ getBlueConicClientInstance().initialize(configuration, new com.blueconic.Callback() {
87
+ @Override
88
+ public void onSuccess() {
89
+ callback.invoke(true, null);
90
+ }
91
+
92
+ @Override
93
+ public void onError(@NotNull com.blueconic.Error error) {
94
+ callback.invoke(false, error.toString());
95
+ }
96
+ });
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Enable and disable the BlueConicClient to prevent or re-activate tracking data.
102
+ *
103
+ * @param isEnabled to enable or disable the BlueConicClient.
104
+ */
105
+ @ReactMethod
106
+ public void setEnabled(@Nonnull Boolean isEnabled) {
107
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
108
+ if (blueConicClient != null) {
109
+ blueConicClient.setEnabled(isEnabled);
110
+ }
111
+
112
+ }
113
+
114
+ /**
115
+ * Return {@code true} if the BlueConicClient enabled. The value is passed to the provided callback function as separated Strings.
116
+ *
117
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
118
+ * to pass values back to the JavaScript.
119
+ */
120
+ @ReactMethod
121
+ public void isEnabledAsync(@Nonnull Promise promise) {
122
+ final WritableArray result = getWritableArray();
123
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
124
+
125
+ if (blueConicClient != null) {
126
+ result.pushBoolean(blueConicClient.isEnabled());
127
+ }
128
+
129
+ promise.resolve(result);
130
+ }
131
+
132
+ /**
133
+ * Return {@code true} if the BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings
134
+ *
135
+ * @param callback The callback function to handle the obtained value. Callbacks are necessary in
136
+ * Native Modules to pass values back to the JavaScript.
137
+ */
138
+ @ReactMethod
139
+ public void isEnabledWithCallback(@Nonnull Callback callback) {
140
+ final List<Boolean> result = new ArrayList<Boolean>();
141
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
142
+
143
+ if (blueConicClient != null) {
144
+ result.add(blueConicClient.isEnabled());
145
+ }
146
+
147
+ callback.invoke(result);
148
+ }
149
+
150
+ /**
151
+ * Gets the ID of the BlueConic profile. The value is passed to the provided Promise as a String.
152
+ *
153
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
154
+ * to pass values back to the JavaScript.
155
+ */
156
+ @ReactMethod
157
+ public void getProfileIdAsync(@Nonnull Promise promise) {
158
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
159
+ String profileId = "";
160
+ if (blueConicClient != null) {
161
+ profileId = blueConicClient.getProfileId();
162
+ }
163
+
164
+ promise.resolve(profileId);
165
+ }
166
+
167
+ /**
168
+ * Gets the ID of the BlueConic profile. The value is passed to the provided callback function as a String.
169
+ *
170
+ * @param callback The Callback function to handle the obtained value. Callbacks are necessary in Native Modules
171
+ * to pass values back to the JavaScript.
172
+ */
173
+ @ReactMethod
174
+ public void getProfileIdWithCallback(@Nonnull Callback callback) {
175
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
176
+ String profileId = "";
177
+ if (blueConicClient != null) {
178
+ profileId = blueConicClient.getProfileId();
179
+ }
180
+
181
+ callback.invoke(profileId);
182
+ }
183
+
184
+ /**
185
+ * Resets the BlueConic profile id. This will generate a new profile id for the current user.
186
+ */
187
+ @ReactMethod
188
+ public void clearProfileId(@Nonnull Callback callback) {
189
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
190
+ if (blueConicClient != null) {
191
+ blueConicClient.clearProfileId(new com.blueconic.Callback() {
192
+ @Override
193
+ public void onSuccess() {
194
+ callback.invoke(true, null);
195
+ }
196
+
197
+ @Override
198
+ public void onError(@NotNull com.blueconic.Error error) {
199
+ callback.invoke(false, error.toString());
200
+ }
201
+ });
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Returns the current screen name.
207
+ *
208
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
209
+ * to pass values back to the JavaScript.
210
+ */
211
+ @ReactMethod
212
+ public void getScreenNameAsync(@Nonnull Promise promise) {
213
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
214
+ String screenName = "";
215
+ if (blueConicClient != null) {
216
+ screenName = blueConicClient.getScreenName();
217
+ }
218
+
219
+ promise.resolve(screenName);
220
+ }
221
+
222
+ /**
223
+ * Returns the current screen name.
224
+ *
225
+ * @param callback The callback function to handle the obtained value. Callbacks are necessary in Native Modules
226
+ * to pass values back to the JavaScript.
227
+ */
228
+ @ReactMethod
229
+ public void getScreenNameWithCallback(@Nonnull Callback callback) {
230
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
231
+ String screenName = "";
232
+ if (blueConicClient != null) {
233
+ screenName = blueConicClient.getScreenName();
234
+ }
235
+
236
+ callback.invoke(screenName);
237
+ }
238
+
239
+ /**
240
+ * Gets the values of the specified profile property. The values are passed to the provided promise
241
+ * as separate Strings.
242
+ *
243
+ * @param property The profile property for which to get the values.
244
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
245
+ * to pass values back to the JavaScript.
246
+ */
247
+ @ReactMethod
248
+ public void getProfileValueAsync(@Nonnull String property, @Nonnull Promise promise) {
249
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
250
+ final WritableArray result = getWritableArray();
251
+
252
+ if (blueConicClient != null) {
253
+ result.pushString(blueConicClient.getProfileValue(property));
254
+ }
255
+ promise.resolve(result);
256
+ }
257
+
258
+ /**
259
+ * Gets the values of the specified profile property. The values are passed to the provided promise
260
+ * as separate Strings.
261
+ *
262
+ * @param property The profile property for which to get the values.
263
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
264
+ * to pass values back to the JavaScript.
265
+ */
266
+ @ReactMethod
267
+ public void getProfileValuesAsync(@Nonnull String property, @Nonnull Promise promise) {
268
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
269
+ final WritableArray result = getWritableArray();
270
+
271
+ if (blueConicClient != null) {
272
+ Collection<String> values = blueConicClient.getProfileValues(property);
273
+ result.pushArray(fromList(new ArrayList<>(values)));
274
+ }
275
+
276
+ promise.resolve(result);
277
+ }
278
+
279
+ /**
280
+ * Gets the values of the specified profile property. The values are passed to the provided callback function
281
+ * as separate Strings.
282
+ *
283
+ * @param property The profile property for which to get the values.
284
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
285
+ * to pass values back to the JavaScript.
286
+ */
287
+ @ReactMethod
288
+ public void getProfileValueWithCallback(@Nonnull String property, @Nonnull Callback callback) {
289
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
290
+ final WritableArray result = getWritableArray();
291
+
292
+ if (blueConicClient != null) {
293
+ result.pushString(blueConicClient.getProfileValue(property));
294
+ }
295
+
296
+ callback.invoke(result);
297
+ }
298
+
299
+ /**
300
+ * Gets the values of the specified profile property. The values are passed to the provided callback function
301
+ * as separate Strings.
302
+ *
303
+ * @param property The profile property for which to get the values.
304
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
305
+ * to pass values back to the JavaScript.
306
+ */
307
+ @ReactMethod
308
+ public void getProfileValuesWithCallback(@Nonnull String property, @Nonnull Callback callback) {
309
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
310
+ final WritableArray result = getWritableArray();
311
+
312
+ if (blueConicClient != null) {
313
+ Collection<String> values = blueConicClient.getProfileValues(property);
314
+ result.pushArray(fromList(new ArrayList<>(values)));
315
+ }
316
+
317
+ callback.invoke(result);
318
+ }
319
+
320
+ /**
321
+ * Retrieves all the profile properties and their values.
322
+ *
323
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
324
+ */
325
+ @ReactMethod
326
+ public void getAllProfilePropertiesAsync(@Nonnull Promise promise) {
327
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
328
+ final WritableArray result = getWritableArray();
329
+
330
+ if (blueConicClient == null) {
331
+ promise.resolve(result);
332
+ return;
333
+ }
334
+ BlueConicClientImpl implInstance = (BlueConicClientImpl) blueConicClient;
335
+
336
+ for (String propertyName : implInstance.getProfilePropertyNames()) {
337
+ final WritableMap item = getWritableMap();
338
+ item.putString("id", propertyName);
339
+ Collection<String> values = blueConicClient.getProfileValues(propertyName);
340
+ String joinedValues = String.join(",", values);
341
+ item.putString("value", joinedValues);
342
+ result.pushMap(item);
343
+ }
344
+
345
+ promise.resolve(result);
346
+ }
347
+
348
+ /**
349
+ * Gets the privacy legislation. The values are passed to the provided promise
350
+ * as separate String.
351
+ *
352
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
353
+ * to pass values back to the JavaScript.
354
+ */
355
+ @ReactMethod
356
+ public void getPrivacyLegislationAsync(@Nonnull Promise promise) {
357
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
358
+ final WritableArray result = getWritableArray();
359
+
360
+ if (blueConicClient != null) {
361
+ result.pushString(blueConicClient.getPrivacyLegislation());
362
+ }
363
+ promise.resolve(result);
364
+ }
365
+
366
+ /**
367
+ * Gets the privacy legislation. The values are passed to the provided callback function
368
+ * as separate String.
369
+ *
370
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
371
+ * to pass values back to the JavaScript.
372
+ */
373
+ @ReactMethod
374
+ public void getPrivacyLegislationWithCallback(@Nonnull Callback callback) {
375
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
376
+ final WritableArray result = getWritableArray();
377
+
378
+ if (blueConicClient != null) {
379
+ result.pushString(blueConicClient.getPrivacyLegislation());
380
+ }
381
+
382
+ callback.invoke(result);
383
+ }
384
+
385
+ /**
386
+ * Gets the consented objectives. The values are passed to the provided promise
387
+ * as separate Strings.
388
+ *
389
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
390
+ * to pass values back to the JavaScript.
391
+ */
392
+ @ReactMethod
393
+ public void getConsentedObjectivesAsync(@Nonnull Promise promise) {
394
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
395
+ final WritableArray result = getWritableArray();
396
+
397
+ if (blueConicClient != null) {
398
+ Collection<String> values = blueConicClient.getConsentedObjectives();
399
+ result.pushArray(fromList(new ArrayList<>(values)));
400
+ }
401
+
402
+ promise.resolve(result);
403
+ }
404
+
405
+ /**
406
+ * Gets the consented objectives. The values are passed to the provided callback function
407
+ * as separate Strings.
408
+ *
409
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
410
+ * to pass values back to the JavaScript.
411
+ */
412
+ @ReactMethod
413
+ public void getConsentedObjectivesWithCallback(@Nonnull Callback callback) {
414
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
415
+ final WritableArray result = getWritableArray();
416
+
417
+ if (blueConicClient != null) {
418
+ Collection<String> values = blueConicClient.getConsentedObjectives();
419
+ result.pushArray(fromList(new ArrayList<>(values)));
420
+ }
421
+
422
+ callback.invoke(result);
423
+ }
424
+
425
+ /**
426
+ * Gets the refused objectives. The values are passed to the provided promise
427
+ * as separate Strings.
428
+ *
429
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
430
+ * to pass values back to the JavaScript.
431
+ */
432
+ @ReactMethod
433
+ public void getRefusedObjectivesAsync(@Nonnull Promise promise) {
434
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
435
+ final WritableArray result = getWritableArray();
436
+
437
+ if (blueConicClient != null) {
438
+ Collection<String> values = blueConicClient.getRefusedObjectives();
439
+ result.pushArray(fromList(new ArrayList<>(values)));
440
+ }
441
+
442
+ promise.resolve(result);
443
+ }
444
+
445
+ /**
446
+ * Gets the refused objectives. The values are passed to the provided callback function
447
+ * as separate Strings.
448
+ *
449
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
450
+ * to pass values back to the JavaScript.
451
+ */
452
+ @ReactMethod
453
+ public void getRefusedObjectivesWithCallback(@Nonnull Callback callback) {
454
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
455
+ final WritableArray result = getWritableArray();
456
+
457
+ if (blueConicClient != null) {
458
+ Collection<String> values = blueConicClient.getRefusedObjectives();
459
+ result.pushArray(fromList(new ArrayList<>(values)));
460
+ }
461
+
462
+ callback.invoke(result);
463
+ }
464
+
465
+ /**
466
+ * Adds an objective to the consented objectives list.
467
+ *
468
+ * @param objectiveId The id of the objective to add to consented objectives.
469
+ */
470
+ @ReactMethod
471
+ public void addConsentedObjective(@Nonnull String objectiveId) {
472
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
473
+ if (blueConicClient != null) {
474
+ blueConicClient.addConsentedObjective(objectiveId, null);
475
+ }
476
+ }
477
+
478
+ /**
479
+ * Adds an objective to the refused objectives list.
480
+ *
481
+ * @param objectiveId The id of the objective to add to refused objectives.
482
+ */
483
+ @ReactMethod
484
+ public void addRefusedObjective(@Nonnull String objectiveId) {
485
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
486
+ if (blueConicClient != null) {
487
+ blueConicClient.addRefusedObjective(objectiveId, null);
488
+ }
489
+ }
490
+
491
+ /**
492
+ * Set the privacy legislation.
493
+ *
494
+ * @param privacyLegislation The privacy legislation.
495
+ */
496
+ @ReactMethod
497
+ public void setPrivacyLegislation(@Nonnull String privacyLegislation) {
498
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
499
+ if (blueConicClient != null) {
500
+ blueConicClient.setPrivacyLegislation(privacyLegislation);
501
+ }
502
+ }
503
+
504
+ /**
505
+ * Sets the given objectives for consented objectives.
506
+ *
507
+ * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
508
+ */
509
+ @ReactMethod
510
+ public void setConsentedObjectives(@Nonnull ReadableArray objectiveIds) {
511
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
512
+ if (blueConicClient != null) {
513
+ blueConicClient.setConsentedObjectives(toList(objectiveIds));
514
+ }
515
+ }
516
+
517
+ /**
518
+ * Sets the given objectives for consented objectives.
519
+ *
520
+ * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
521
+ */
522
+ @ReactMethod
523
+ public void setRefusedObjectives(@Nonnull ReadableArray objectiveIds) {
524
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
525
+ if (blueConicClient != null) {
526
+ blueConicClient.setRefusedObjectives(toList(objectiveIds));
527
+ }
528
+ }
529
+
530
+ /**
531
+ * Setter for the locale to get the parameters for. By default, the default locale configured in BlueConic is used.
532
+ *
533
+ * @param locale the locale, e.g. 'en_US'.
534
+ */
535
+ @ReactMethod
536
+ public void setLocale(@Nonnull String locale) {
537
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
538
+ if (blueConicClient != null) {
539
+ blueConicClient.setLocale(locale);
540
+ }
541
+ }
542
+
543
+ /**
544
+ * Gets the segments of the profile.
545
+ * To retrieve and update the Segments you have to register a pageview first.
546
+ * The values are passed to the provided promise
547
+ * as a list of Objects containing id and name.
548
+ *
549
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
550
+ * to pass values back to the JavaScript.
551
+ */
552
+ @ReactMethod
553
+ public void getSegments(@Nonnull Promise promise) {
554
+ promise.resolve(getFormattedSegments());
555
+ }
556
+
557
+ /**
558
+ * Gets the segments of the profile.
559
+ * To retrieve and update the Segments you have to register a pageview first.
560
+ * The values are passed to the provided promise
561
+ * as a list of Objects containing id and name.
562
+ *
563
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
564
+ * to pass values back to the JavaScript.
565
+ */
566
+ @ReactMethod
567
+ public void getSegmentsWithCallback(@Nonnull Callback callback) {
568
+ callback.invoke(getFormattedSegments());
569
+ }
570
+
571
+ /**
572
+ * Return whether the BlueConic profile is part of the BlueConic segment.
573
+ * The value is passed to the provided callback function as Boolean.
574
+ *
575
+ * @param segmentId The id of the segment
576
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
577
+ * Native Modules to pass values back to the JavaScript.
578
+ */
579
+ @ReactMethod
580
+ public void hasSegment(@Nonnull String segmentId, @Nonnull Promise promise) {
581
+ final List<Boolean> result = new ArrayList<Boolean>();
582
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
583
+
584
+ if (blueConicClient != null) {
585
+ result.add(blueConicClient.hasSegment(segmentId));
586
+ }
587
+
588
+ promise.resolve(result);
589
+ }
590
+
591
+ /**
592
+ * Return whether the BlueConic profile is part of the BlueConic segment.
593
+ * The value is passed to the provided callback function as Boolean.
594
+ *
595
+ * @param segmentId The id of the segment
596
+ * @param callback The callback function to handle the obtained value. Callbacks are necessary in
597
+ * Native Modules to pass values back to the JavaScript.
598
+ */
599
+ @ReactMethod
600
+ public void hasSegmentWithCallback(@Nonnull String segmentId, @Nonnull Callback callback) {
601
+ final List<Boolean> result = new ArrayList<Boolean>();
602
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
603
+
604
+ if (blueConicClient != null) {
605
+ result.add(blueConicClient.hasSegment(segmentId));
606
+ }
607
+
608
+ callback.invoke(result);
609
+ }
610
+
611
+ /**
612
+ * Adds the given values to the specified profile property.
613
+ *
614
+ * @param property The profile property to which to add the values.
615
+ * @param value A ReadableArray containing Strings that will be added to the profile property.
616
+ */
617
+ @ReactMethod
618
+ public void addProfileValue(@Nonnull String property, @Nonnull String value) {
619
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
620
+ if (blueConicClient != null) {
621
+ blueConicClient.addProfileValue(property, value, null);
622
+ }
623
+ }
624
+
625
+ /**
626
+ * Adds the given values to the specified profile property.
627
+ *
628
+ * @param property The profile property to which to add the values.
629
+ * @param values A ReadableArray containing Strings that will be added to the profile property.
630
+ */
631
+ @ReactMethod
632
+ public void addProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
633
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
634
+ if (blueConicClient != null) {
635
+ blueConicClient.addProfileValues(property, toList(values), null);
636
+ }
637
+ }
638
+
639
+ /**
640
+ * Set the given value for the specified profile property.
641
+ *
642
+ * @param property The profile property for which to set the values.
643
+ * @param value A ReadableArray containing Strings that will be set as the new values for the profile property.
644
+ */
645
+ @ReactMethod
646
+ public void setProfileValue(@Nonnull String property, @Nonnull String value) {
647
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
648
+ if (blueConicClient != null) {
649
+ blueConicClient.setProfileValue(property, value, null);
650
+ }
651
+ }
652
+
653
+ /**
654
+ * Sets the given values for the specified profile property.
655
+ *
656
+ * @param property The profile property for which to set the values.
657
+ * @param values A ReadableArray containing Strings that will be set as the new values for the profile property.
658
+ */
659
+ @ReactMethod
660
+ public void setProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
661
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
662
+ if (blueConicClient != null) {
663
+ blueConicClient.setProfileValues(property, toList(values), null);
664
+ }
665
+ }
666
+
667
+ /**
668
+ * Increments the given values to the specified profile property.
669
+ *
670
+ * @param property The profile property to which to increment the values.
671
+ * @param value A ReadableArray containing Strings that will be incremented to the profile property.
672
+ */
673
+ @ReactMethod
674
+ public void incrementProfileValue(@Nonnull String property, @Nonnull String value) {
675
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
676
+ if (blueConicClient != null) {
677
+ blueConicClient.incrementProfileValue(property, value, null);
678
+ }
679
+ }
680
+
681
+ /**
682
+ * Create Event.
683
+ *
684
+ * @param eventName The name of the event
685
+ * @param readableMap The readable map retrieved from React native
686
+ */
687
+ @ReactMethod
688
+ public void createEvent(@Nonnull String eventName, ReadableMap readableMap) {
689
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
690
+ final Map<String, Object> properties = readableMap.toHashMap();
691
+
692
+ if (blueConicClient != null) {
693
+ blueConicClient.createEvent(eventName, properties, getCurrentActivity(), null);
694
+ }
695
+ }
696
+
697
+ /**
698
+ * Create Event.
699
+ *
700
+ * @param eventName The name of the event
701
+ * @param readableMap The readable map retrieved from React native
702
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
703
+ * Native Modules to pass values back to the JavaScript.
704
+ */
705
+ @ReactMethod
706
+ public void createEventAsync(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Promise promise) {
707
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
708
+ final Map<String, Object> properties = readableMap.toHashMap();
709
+
710
+ if (blueConicClient != null) {
711
+ blueConicClient.createEvent(eventName, properties, getCurrentActivity(), new com.blueconic.Callback() {
712
+ @Override
713
+ public void onSuccess() {
714
+ promise.resolve(getWritableArray());
715
+ }
716
+
717
+ @Override
718
+ public void onError(@NotNull com.blueconic.Error error) {
719
+ promise.resolve(getWritableArray());
720
+ }
721
+ });
722
+ } else {
723
+ promise.resolve(getWritableArray());
724
+ }
725
+ }
726
+
727
+ /**
728
+ * Create Event.
729
+ *
730
+ * @param eventName The name of the event
731
+ * @param readableMap The readable map retrieved from React native
732
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
733
+ * to pass values back to the JavaScript.
734
+ */
735
+ @ReactMethod
736
+ public void createEventWithCallback(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Callback callback) {
737
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
738
+ final Map<String, Object> properties = readableMap.toHashMap();
739
+
740
+ if (blueConicClient != null) {
741
+ blueConicClient.createEvent(eventName, properties, getCurrentActivity(), new com.blueconic.Callback() {
742
+ @Override
743
+ public void onSuccess() {
744
+ callback.invoke(true, null);
745
+ }
746
+
747
+ @Override
748
+ public void onError(@NotNull com.blueconic.Error error) {
749
+ callback.invoke(false, error.toString());
750
+ }
751
+ });
752
+ } else {
753
+ callback.invoke(false, "InternalError");
754
+ }
755
+ }
756
+
757
+ /**
758
+ * Update sync the BlueConic Profile
759
+ */
760
+ @ReactMethod
761
+ public void updateProfile() {
762
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
763
+
764
+ if (blueConicClient != null) {
765
+ blueConicClient.updateProfile(null);
766
+ }
767
+ }
768
+
769
+ /**
770
+ * Update sync the BlueConic Profile
771
+ *
772
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
773
+ * Native Modules to pass values back to the JavaScript.
774
+ */
775
+ @ReactMethod
776
+ public void updateProfileAsync(@Nonnull final Promise promise) {
777
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
778
+
779
+ if (blueConicClient != null) {
780
+ blueConicClient.updateProfile(new com.blueconic.Callback() {
781
+ @Override
782
+ public void onSuccess() {
783
+ promise.resolve(getWritableArray());
784
+ }
785
+
786
+ @Override
787
+ public void onError(@NotNull com.blueconic.Error error) {
788
+ promise.resolve(getWritableArray());
789
+ }
790
+ });
791
+ } else {
792
+ promise.resolve(getWritableArray());
793
+ }
794
+ }
795
+
796
+ /**
797
+ * Update the BlueConic Profile with callback
798
+ *
799
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
800
+ * to pass values back to the JavaScript.
801
+ */
802
+ @ReactMethod
803
+ public void updateProfileWithCallback(@Nonnull final Callback callback) {
804
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
805
+
806
+ if (blueConicClient != null) {
807
+ blueConicClient.updateProfile(new com.blueconic.Callback() {
808
+ @Override
809
+ public void onSuccess() {
810
+ callback.invoke(true, null);
811
+ }
812
+
813
+ @Override
814
+ public void onError(@NotNull com.blueconic.Error error) {
815
+ callback.invoke(false, error.toString());
816
+ }
817
+ });
818
+ } else {
819
+ callback.invoke(false, "InternalError");
820
+ }
821
+ }
822
+
823
+ /**
824
+ * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
825
+ * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
826
+ *
827
+ * @param screenName The name of the screen.
828
+ */
829
+ @ReactMethod
830
+ public void createPageViewEvent(@Nonnull String screenName, ReadableMap readableMap) {
831
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
832
+ if (blueConicClient != null) {
833
+ // blueConicClient instance must have an activity or application
834
+ final Map<String, Object> properties = readableMap.toHashMap();
835
+ Activity activity = getCurrentActivity();
836
+ if (activity == null) {
837
+ activity = new Activity();
838
+ }
839
+
840
+ blueConicClient.createPageViewEvent(screenName, activity, properties, null);
841
+ } else {
842
+ Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
843
+ }
844
+ }
845
+
846
+ /**
847
+ * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
848
+ * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
849
+ *
850
+ * @param screenName The name of the screen.
851
+ */
852
+ @ReactMethod
853
+ public void createPageViewEventAsync(@Nonnull String screenName, ReadableMap readableMap, @Nonnull final Promise promise) {
854
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
855
+ if (blueConicClient != null) {
856
+ // blueConicClient instance must have an activity or application
857
+ final Map<String, Object> properties = readableMap.toHashMap();
858
+ Activity activity = getCurrentActivity();
859
+ if (activity == null) {
860
+ activity = new Activity();
861
+ }
862
+
863
+ blueConicClient.createPageViewEvent(screenName, activity, properties, new com.blueconic.Callback() {
864
+ @Override
865
+ public void onSuccess() {
866
+ promise.resolve(getWritableArray());
867
+ }
868
+
869
+ @Override
870
+ public void onError(@NotNull com.blueconic.Error error) {
871
+ promise.resolve(getWritableArray());
872
+ }
873
+ });
874
+ } else {
875
+ Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
876
+ promise.resolve(getWritableArray());
877
+ }
878
+ }
879
+
880
+ /**
881
+ * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
882
+ * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
883
+ *
884
+ * @param screenName The name of the screen.
885
+ */
886
+ @ReactMethod
887
+ public void createPageViewEventWithCallback(@Nonnull String screenName, ReadableMap readableMap, @Nonnull final Callback callback) {
888
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
889
+ if (blueConicClient != null) {
890
+ // blueConicClient instance must have an activity or application
891
+ final Map<String, Object> properties = readableMap.toHashMap();
892
+ Activity activity = getCurrentActivity();
893
+ if (activity == null) {
894
+ activity = new Activity();
895
+ }
896
+
897
+ blueConicClient.createPageViewEvent(screenName, activity, properties, new com.blueconic.Callback() {
898
+ @Override
899
+ public void onSuccess() {
900
+ callback.invoke(true, null);
901
+ }
902
+
903
+ @Override
904
+ public void onError(@NotNull com.blueconic.Error error) {
905
+ callback.invoke(false, error.toString());
906
+ }
907
+ });
908
+ } else {
909
+ Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
910
+ callback.invoke(getWritableArray());
911
+ }
912
+ }
913
+
914
+ /**
915
+ * Create View Event.
916
+ *
917
+ * @param interactionId The type of event
918
+ * @param readableMap The readable map retrieved from React native
919
+ */
920
+ @ReactMethod
921
+ public void createViewEvent(@Nonnull String interactionId, ReadableMap readableMap) {
922
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
923
+ final Map<String, Object> properties = readableMap.toHashMap();
924
+
925
+ if (blueConicClient != null) {
926
+ Activity activity = getCurrentActivity();
927
+ if (activity == null) {
928
+ activity = new Activity();
929
+ }
930
+
931
+ blueConicClient.createViewEvent(interactionId, properties, activity,null);
932
+ }
933
+ }
934
+
935
+ /**
936
+ * Create View Event.
937
+ *
938
+ * @param interactionId The interaction id of the event
939
+ * @param readableMap The readable map retrieved from React native
940
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
941
+ * Native Modules to pass values back to the JavaScript.
942
+ */
943
+ @ReactMethod
944
+ public void createViewEventAsync(@Nonnull String interactionId, ReadableMap readableMap, @Nonnull final Promise promise) {
945
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
946
+ final Map<String, Object> properties = readableMap.toHashMap();
947
+
948
+ if (blueConicClient != null) {
949
+ Activity activity = getCurrentActivity();
950
+ if (activity == null) {
951
+ activity = new Activity();
952
+ }
953
+
954
+ blueConicClient.createViewEvent(interactionId, properties, activity, new com.blueconic.Callback() {
955
+ @Override
956
+ public void onSuccess() {
957
+ promise.resolve(getWritableArray());
958
+ }
959
+
960
+ @Override
961
+ public void onError(@NotNull com.blueconic.Error error) {
962
+ promise.resolve(getWritableArray());
963
+ }
964
+ });
965
+ } else {
966
+ promise.resolve(getWritableArray());
967
+ }
968
+ }
969
+
970
+ /**
971
+ * Create View Event.
972
+ *
973
+ * @param interactionId The type of event
974
+ * @param readableMap The readable map retrieved from React native
975
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
976
+ * to pass values back to the JavaScript.
977
+ */
978
+ @ReactMethod
979
+ public void createViewEventWithCallback(@Nonnull String interactionId, ReadableMap readableMap, @Nonnull final Callback callback) {
980
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
981
+ final Map<String, Object> properties = readableMap.toHashMap();
982
+
983
+ if (blueConicClient != null) {
984
+ Activity activity = getCurrentActivity();
985
+ if (activity == null) {
986
+ activity = new Activity();
987
+ }
988
+ blueConicClient.createViewEvent(interactionId, properties, activity, new com.blueconic.Callback() {
989
+ @Override
990
+ public void onSuccess() {
991
+ callback.invoke(true, null);
992
+ }
993
+
994
+ @Override
995
+ public void onError(@NotNull com.blueconic.Error error) {
996
+ callback.invoke(false, error.toString());
997
+ }
998
+ });
999
+ } else {
1000
+ callback.invoke(false, "InternalError");
1001
+ }
1002
+ }
1003
+
1004
+ /**
1005
+ * Create Conversion Event.
1006
+ *
1007
+ * @param interactionId The type of event
1008
+ * @param readableMap The readable map retrieved from React native
1009
+ */
1010
+ @ReactMethod
1011
+ public void createConversionEvent(@Nonnull String interactionId, ReadableMap readableMap) {
1012
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1013
+ final Map<String, Object> properties = readableMap.toHashMap();
1014
+
1015
+ if (blueConicClient != null) {
1016
+ Activity activity = getCurrentActivity();
1017
+ if (activity == null) {
1018
+ activity = new Activity();
1019
+ }
1020
+
1021
+ blueConicClient.createConversionEvent(interactionId, properties, activity,null);
1022
+ }
1023
+ }
1024
+
1025
+ /**
1026
+ * Create Conversion Event.
1027
+ *
1028
+ * @param interactionId The interaction id of the event
1029
+ * @param readableMap The readable map retrieved from React native
1030
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
1031
+ * Native Modules to pass values back to the JavaScript.
1032
+ */
1033
+ @ReactMethod
1034
+ public void createConversionEventAsync(@Nonnull String interactionId, ReadableMap readableMap, @Nonnull final Promise promise) {
1035
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1036
+ final Map<String, Object> properties = readableMap.toHashMap();
1037
+
1038
+ if (blueConicClient != null) {
1039
+ Activity activity = getCurrentActivity();
1040
+ if (activity == null) {
1041
+ activity = new Activity();
1042
+ }
1043
+ blueConicClient.createConversionEvent(interactionId, properties, activity, new com.blueconic.Callback() {
1044
+ @Override
1045
+ public void onSuccess() {
1046
+ promise.resolve(getWritableArray());
1047
+ }
1048
+
1049
+ @Override
1050
+ public void onError(@NotNull com.blueconic.Error error) {
1051
+ promise.resolve(getWritableArray());
1052
+ }
1053
+ });
1054
+ } else {
1055
+ promise.resolve(getWritableArray());
1056
+ }
1057
+ }
1058
+
1059
+ /**
1060
+ * Create Conversion Event.
1061
+ *
1062
+ * @param interactionId The type of event
1063
+ * @param readableMap The readable map retrieved from React native
1064
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
1065
+ * to pass values back to the JavaScript.
1066
+ */
1067
+ @ReactMethod
1068
+ public void createConversionEventWithCallback(@Nonnull String interactionId, ReadableMap readableMap, @Nonnull final Callback callback) {
1069
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1070
+ final Map<String, Object> properties = readableMap.toHashMap();
1071
+
1072
+ if (blueConicClient != null) {
1073
+ Activity activity = getCurrentActivity();
1074
+ if (activity == null) {
1075
+ activity = new Activity();
1076
+ }
1077
+ blueConicClient.createConversionEvent(interactionId, properties, activity, new com.blueconic.Callback() {
1078
+ @Override
1079
+ public void onSuccess() {
1080
+ callback.invoke(true, null);
1081
+ }
1082
+
1083
+ @Override
1084
+ public void onError(@NotNull com.blueconic.Error error) {
1085
+ callback.invoke(false, error.toString());
1086
+ }
1087
+ });
1088
+ } else {
1089
+ callback.invoke(false, "InternalError");
1090
+ }
1091
+ }
1092
+
1093
+ /**
1094
+ * Create Click Event.
1095
+ *
1096
+ * @param interactionId The type of event
1097
+ * @param readableMap The readable map retrieved from React native
1098
+ */
1099
+ @ReactMethod
1100
+ public void createClickEvent(@Nonnull String interactionId, ReadableMap readableMap) {
1101
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1102
+ final Map<String, Object> properties = readableMap.toHashMap();
1103
+
1104
+ if (blueConicClient != null) {
1105
+ Activity activity = getCurrentActivity();
1106
+ if (activity == null) {
1107
+ activity = new Activity();
1108
+ }
1109
+
1110
+ blueConicClient.createClickEvent(interactionId, properties, activity,null);
1111
+ }
1112
+ }
1113
+
1114
+ /**
1115
+ * Create Click Event.
1116
+ *
1117
+ * @param interactionId The interaction id of the event
1118
+ * @param readableMap The readable map retrieved from React native
1119
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
1120
+ * Native Modules to pass values back to the JavaScript.
1121
+ */
1122
+ @ReactMethod
1123
+ public void createClickEventAsync(@Nonnull String interactionId, ReadableMap readableMap, @Nonnull final Promise promise) {
1124
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1125
+ final Map<String, Object> properties = readableMap.toHashMap();
1126
+
1127
+ if (blueConicClient != null) {
1128
+ Activity activity = getCurrentActivity();
1129
+ if (activity == null) {
1130
+ activity = new Activity();
1131
+ }
1132
+ blueConicClient.createClickEvent(interactionId, properties, activity, new com.blueconic.Callback() {
1133
+ @Override
1134
+ public void onSuccess() {
1135
+ promise.resolve(getWritableArray());
1136
+ }
1137
+
1138
+ @Override
1139
+ public void onError(@NotNull com.blueconic.Error error) {
1140
+ promise.resolve(getWritableArray());
1141
+ }
1142
+ });
1143
+ } else {
1144
+ promise.resolve(getWritableArray());
1145
+ }
1146
+ }
1147
+
1148
+ /**
1149
+ * Create Click Event.
1150
+ *
1151
+ * @param interactionId The type of event
1152
+ * @param readableMap The readable map retrieved from React native
1153
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
1154
+ * to pass values back to the JavaScript.
1155
+ */
1156
+ @ReactMethod
1157
+ public void createClickEventWithCallback(@Nonnull String interactionId, ReadableMap readableMap, @Nonnull final Callback callback) {
1158
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1159
+ final Map<String, Object> properties = readableMap.toHashMap();
1160
+
1161
+ if (blueConicClient != null) {
1162
+ Activity activity = getCurrentActivity();
1163
+ if (activity == null) {
1164
+ activity = new Activity();
1165
+ }
1166
+ blueConicClient.createClickEvent(interactionId, properties, activity, new com.blueconic.Callback() {
1167
+ @Override
1168
+ public void onSuccess() {
1169
+ callback.invoke(true, null);
1170
+ }
1171
+
1172
+ @Override
1173
+ public void onError(@NotNull com.blueconic.Error error) {
1174
+ callback.invoke(false, error.toString());
1175
+ }
1176
+ });
1177
+ } else {
1178
+ callback.invoke(false, "InternalError");
1179
+ }
1180
+ }
1181
+
1182
+ /**
1183
+ * Create Timeline Event.
1184
+ *
1185
+ * @param eventType The type of event
1186
+ * @param eventDate The date of the event
1187
+ * @param readableMap The readable map retrieved from React native
1188
+ */
1189
+ @ReactMethod
1190
+ public void createTimelineEvent(@Nonnull String eventType, double eventDate, ReadableMap readableMap) {
1191
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1192
+ final Map<String, Object> properties = readableMap.toHashMap();
1193
+
1194
+ if (blueConicClient != null) {
1195
+ blueConicClient.createTimelineEvent(eventType, new Date((long) eventDate), properties, null);
1196
+ }
1197
+ }
1198
+
1199
+ /**
1200
+ * Create Timeline Event.
1201
+ *
1202
+ * @param eventType The type of event
1203
+ * @param eventDate The date of the event
1204
+ * @param readableMap The readable map retrieved from React native
1205
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
1206
+ * Native Modules to pass values back to the JavaScript.
1207
+ */
1208
+ @ReactMethod
1209
+ public void createTimelineEventAsync(@Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Promise promise) {
1210
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1211
+ final Map<String, Object> properties = readableMap.toHashMap();
1212
+
1213
+ if (blueConicClient != null) {
1214
+ blueConicClient.createTimelineEvent(eventType, new Date((long) eventDate), properties, new com.blueconic.Callback() {
1215
+ @Override
1216
+ public void onSuccess() {
1217
+ promise.resolve(getWritableArray());
1218
+ }
1219
+
1220
+ @Override
1221
+ public void onError(@NotNull com.blueconic.Error error) {
1222
+ promise.resolve(getWritableArray());
1223
+ }
1224
+ });
1225
+ } else {
1226
+ promise.resolve(getWritableArray());
1227
+ }
1228
+ }
1229
+
1230
+ /**
1231
+ * Create Timeline Event.
1232
+ *
1233
+ * @param eventType The type of event
1234
+ * @param eventDate The date of the event
1235
+ * @param readableMap The readable map retrieved from React native
1236
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
1237
+ * to pass values back to the JavaScript.
1238
+ */
1239
+ @ReactMethod
1240
+ public void createTimelineEventWithCallback(@Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Callback callback) {
1241
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1242
+ final Map<String, Object> properties = readableMap.toHashMap();
1243
+
1244
+ if (blueConicClient != null) {
1245
+ blueConicClient.createTimelineEvent(eventType, new Date((long) eventDate), properties, new com.blueconic.Callback() {
1246
+ @Override
1247
+ public void onSuccess() {
1248
+ callback.invoke(true, null);
1249
+ }
1250
+
1251
+ @Override
1252
+ public void onError(@NotNull com.blueconic.Error error) {
1253
+ callback.invoke(false, error.toString());
1254
+ }
1255
+ });
1256
+ } else {
1257
+ callback.invoke(false, "InternalError");
1258
+ }
1259
+ }
1260
+
1261
+ /**
1262
+ * Create Timeline Event.
1263
+ *
1264
+ * @param eventType The type of event
1265
+ * @param eventDate The date of the event
1266
+ * @param readableMap The readable map retrieved from React native
1267
+ */
1268
+ @ReactMethod
1269
+ public void createTimelineEventById(@Nonnull String eventId, @Nonnull String eventType, double eventDate, ReadableMap readableMap) {
1270
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1271
+ final Map<String, Object> properties = readableMap.toHashMap();
1272
+
1273
+ if (blueConicClient != null) {
1274
+ blueConicClient.createTimelineEventById(eventId, eventType, new Date((long) eventDate), properties, null);
1275
+ }
1276
+ }
1277
+
1278
+ /**
1279
+ * Create Timeline Event.
1280
+ *
1281
+ * @param eventType The type of event
1282
+ * @param eventDate The date of the event
1283
+ * @param readableMap The readable map retrieved from React native
1284
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
1285
+ * Native Modules to pass values back to the JavaScript.
1286
+ */
1287
+ @ReactMethod
1288
+ public void createTimelineEventByIdAsync(@Nonnull String eventId, @Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Promise promise) {
1289
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1290
+ final Map<String, Object> properties = readableMap.toHashMap();
1291
+
1292
+ if (blueConicClient != null) {
1293
+ blueConicClient.createTimelineEventById(eventId, eventType, new Date((long) eventDate), properties, new com.blueconic.Callback() {
1294
+ @Override
1295
+ public void onSuccess() {
1296
+ promise.resolve(getWritableArray());
1297
+ }
1298
+
1299
+ @Override
1300
+ public void onError(@NotNull com.blueconic.Error error) {
1301
+ promise.resolve(getWritableArray());
1302
+ }
1303
+ });
1304
+ } else {
1305
+ promise.resolve(getWritableArray());
1306
+ }
1307
+ }
1308
+
1309
+ /**
1310
+ * Create Timeline Event.
1311
+ *
1312
+ * @param eventType The type of event
1313
+ * @param eventDate The date of the event
1314
+ * @param readableMap The readable map retrieved from React native
1315
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
1316
+ * to pass values back to the JavaScript.
1317
+ */
1318
+ @ReactMethod
1319
+ public void createTimelineEventByIdWithCallback(@Nonnull String eventId, @Nonnull String eventType, double eventDate, ReadableMap readableMap, @Nonnull final Callback callback) {
1320
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1321
+ final Map<String, Object> properties = readableMap.toHashMap();
1322
+
1323
+ if (blueConicClient != null) {
1324
+ blueConicClient.createTimelineEventById(eventId, eventType, new Date((long) eventDate), properties, new com.blueconic.Callback() {
1325
+ @Override
1326
+ public void onSuccess() {
1327
+ callback.invoke(true, null);
1328
+ }
1329
+
1330
+ @Override
1331
+ public void onError(@NotNull com.blueconic.Error error) {
1332
+ callback.invoke(false, error.toString());
1333
+ }
1334
+ });
1335
+ } else {
1336
+ callback.invoke(false, "InternalError");
1337
+ }
1338
+ }
1339
+
1340
+ @ReactMethod
1341
+ public void subscribe(@Nonnull String eventName, boolean onlyOnce, @Nonnull String identifier) {
1342
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1343
+
1344
+ EventHandler eventHandler = switch (eventName) {
1345
+ case "propertiesDialogueEvent" -> new PropertiesDialogueHandler(eventName);
1346
+ default -> event -> {};
1347
+ };
1348
+
1349
+ blueConicClient.getEventManager().subscribe(eventName, eventHandler, onlyOnce, identifier);
1350
+ }
1351
+
1352
+ @ReactMethod
1353
+ public void unsubscribe(@Nonnull String identifier) {
1354
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1355
+ blueConicClient.getEventManager().unsubscribe(identifier);
1356
+ }
1357
+
1358
+ /**
1359
+ * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
1360
+ *
1361
+ * @param selector The selector to identify the clicked component.
1362
+ */
1363
+ @ReactMethod
1364
+ public void publishClickEvent(@Nonnull String selector, ReadableArray values) {
1365
+ List<String> contextValues;
1366
+ if (values == null) {
1367
+ contextValues = emptyList();
1368
+ } else {
1369
+ contextValues = toList(values);
1370
+ }
1371
+ getBlueConicClientInstance().getEventManager().publishClickEvent(selector, contextValues, null);
1372
+ }
1373
+
1374
+ /**
1375
+ * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
1376
+ *
1377
+ * @param selector The selector to identify the clicked component.
1378
+ */
1379
+ @ReactMethod
1380
+ public void publishClickEventWithCallback(@Nonnull String selector, ReadableArray values, @Nonnull final Callback callback) {
1381
+ List<String> contextValues;
1382
+ if (values == null) {
1383
+ contextValues = emptyList();
1384
+ } else {
1385
+ contextValues = toList(values);
1386
+ }
1387
+ getBlueConicClientInstance().getEventManager().publishClickEvent(selector, contextValues, new com.blueconic.Callback() {
1388
+ @Override
1389
+ public void onSuccess() {
1390
+ callback.invoke(true, null);
1391
+ }
1392
+
1393
+ @Override
1394
+ public void onError(@NotNull com.blueconic.Error error) {
1395
+ callback.invoke(false, error.toString());
1396
+ }
1397
+ });
1398
+ }
1399
+
1400
+ /**
1401
+ * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
1402
+ *
1403
+ * @param selector The selector to identify the clicked component.
1404
+ */
1405
+ @ReactMethod
1406
+ public void publishFormSubmitEvent(@Nonnull String selector, ReadableArray values) {
1407
+ List<String> contextValues;
1408
+ if (values == null) {
1409
+ contextValues = emptyList();
1410
+ } else {
1411
+ contextValues = toList(values);
1412
+ }
1413
+ getBlueConicClientInstance().getEventManager().publishFormSubmitEvent(selector, contextValues, null);
1414
+ }
1415
+
1416
+ /**
1417
+ * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
1418
+ *
1419
+ * @param selector The selector to identify the clicked component.
1420
+ */
1421
+ @ReactMethod
1422
+ public void publishFormSubmitEventWithCallback(@Nonnull String selector, ReadableArray values, @Nonnull final Callback callback) {
1423
+ List<String> contextValues;
1424
+ if (values == null) {
1425
+ contextValues = emptyList();
1426
+ } else {
1427
+ contextValues = toList(values);
1428
+ }
1429
+ getBlueConicClientInstance().getEventManager().publishFormSubmitEvent(selector, contextValues, new com.blueconic.Callback() {
1430
+ @Override
1431
+ public void onSuccess() {
1432
+ callback.invoke(true, null);
1433
+ }
1434
+
1435
+ @Override
1436
+ public void onError(@NotNull com.blueconic.Error error) {
1437
+ callback.invoke(false, error.toString());
1438
+ }
1439
+ });
1440
+ }
1441
+
1442
+ /**
1443
+ * Creates an UpdateContentEvent for the given selector and value, and publishes the event using the EventManager.
1444
+ *
1445
+ * @param selector The selector to identify the component with updated values.
1446
+ * @param value The value to be passed on to BlueConic.
1447
+ */
1448
+ @ReactMethod
1449
+ public void publishUpdateContentEvent(@Nonnull String selector, @Nonnull String value) {
1450
+ getBlueConicClientInstance().getEventManager().publishUpdateContentEvent(selector, value, null);
1451
+ }
1452
+
1453
+ /**
1454
+ * Creates an UpdateContentEvent for the given selector and value, and publishes the event using the EventManager.
1455
+ *
1456
+ * @param selector The selector to identify the component with updated values.
1457
+ * @param value The value to be passed on to BlueConic.
1458
+ */
1459
+ @ReactMethod
1460
+ public void publishUpdateContentEventWithCallback(@Nonnull String selector, @Nonnull String value, @Nonnull final Callback callback) {
1461
+ getBlueConicClientInstance().getEventManager().publishUpdateContentEvent(selector, value, new com.blueconic.Callback() {
1462
+ @Override
1463
+ public void onSuccess() {
1464
+ callback.invoke(true, null);
1465
+ }
1466
+
1467
+ @Override
1468
+ public void onError(@NotNull com.blueconic.Error error) {
1469
+ callback.invoke(false, error.toString());
1470
+ }
1471
+ });
1472
+ }
1473
+
1474
+ /**
1475
+ * Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
1476
+ *
1477
+ * @param selector The selector to identify the component with updated values.
1478
+ * @param value The value to be passed on to BlueConic.
1479
+ */
1480
+ @ReactMethod
1481
+ public void publishUpdateValuesEvent(@Nonnull String selector, @Nonnull String value) {
1482
+ getBlueConicClientInstance().getEventManager().publishUpdateValuesEvent(selector, Collections.singletonList(value), null);
1483
+ }
1484
+
1485
+ /**
1486
+ * Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
1487
+ *
1488
+ * @param selector The selector to identify the component with updated values.
1489
+ * @param value The value to be passed on to BlueConic.
1490
+ */
1491
+ @ReactMethod
1492
+ public void publishUpdateValuesEventWithCallback(@Nonnull String selector, @Nonnull String value, @Nonnull final Callback callback) {
1493
+ getBlueConicClientInstance().getEventManager().publishUpdateValuesEvent(selector, Collections.singletonList(value), new com.blueconic.Callback() {
1494
+ @Override
1495
+ public void onSuccess() {
1496
+ callback.invoke(true, null);
1497
+ }
1498
+
1499
+ @Override
1500
+ public void onError(@NotNull com.blueconic.Error error) {
1501
+ callback.invoke(false, error.toString());
1502
+ }
1503
+ });
1504
+ }
1505
+
1506
+ /**
1507
+ * Creates an AdvancedEvent with the given name and values, and publishes the event using the EventManager.
1508
+ *
1509
+ * @param name The name to identify the event.
1510
+ * @param values The values to pass to BlueConic as context of the event.
1511
+ */
1512
+ @ReactMethod
1513
+ public void publishAdvancedEvent(@Nonnull String name, @Nonnull ReadableArray values) {
1514
+ getBlueConicClientInstance().getEventManager().publishAdvancedEvent(name, toList(values), null);
1515
+ }
1516
+
1517
+ /**
1518
+ * Creates an AdvancedEvent with the given name and values, and publishes the event using the EventManager.
1519
+ *
1520
+ * @param name The name to identify the event.
1521
+ * @param values The values to pass to BlueConic as context of the event.
1522
+ */
1523
+ @ReactMethod
1524
+ public void publishAdvancedEventWithCallback(@Nonnull String name, @Nonnull ReadableArray values, @Nonnull final Callback callback) {
1525
+ getBlueConicClientInstance().getEventManager().publishAdvancedEvent(name, toList(values), new com.blueconic.Callback() {
1526
+ @Override
1527
+ public void onSuccess() {
1528
+ callback.invoke(true, null);
1529
+ }
1530
+
1531
+ @Override
1532
+ public void onError(@NotNull com.blueconic.Error error) {
1533
+ callback.invoke(false, error.toString());
1534
+ }
1535
+ });
1536
+ }
1537
+
1538
+ /**
1539
+ * Destroys all active BlueConic plugins (i.e. instances of listeners and dialogues). This method must be called
1540
+ * in the onPause of an activity if the app targets Android API versions before API 14. It should also be called if
1541
+ * one switches screens in the app without calling the onPause of the previous Activity.
1542
+ */
1543
+ @ReactMethod
1544
+ public void destroyPlugins() {
1545
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1546
+ if (blueConicClient != null) {
1547
+ blueConicClient.destroyPlugins();
1548
+ }
1549
+ }
1550
+
1551
+ @ReactMethod
1552
+ public void addListener(String eventName) {
1553
+ // Keep: Required for RN built in Event Emitter Calls.
1554
+ }
1555
+
1556
+ @ReactMethod
1557
+ public void removeListeners(Integer count) {
1558
+ // Keep: Required for RN built in Event Emitter Calls.
1559
+ }
1560
+
1561
+ /**
1562
+ * Returns an instance of the BlueConicClient
1563
+ *
1564
+ * @return BlueConicClient
1565
+ */
1566
+ protected BlueConicClient getBlueConicClientInstance() {
1567
+ BlueConicClient instance = BlueConicClient.Companion.getInstance();
1568
+ //Set platform information
1569
+ BlueConicClientImpl implInstance = (BlueConicClientImpl) instance;
1570
+ implInstance.setPlatformInformation(BuildConfig.PLATFORM_NAME, BuildConfig.PLATFORM_VERSION);
1571
+
1572
+ return instance;
1573
+ }
1574
+
1575
+ private WritableArray getFormattedSegments() {
1576
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
1577
+ final WritableArray result = getWritableArray();
1578
+
1579
+ if (blueConicClient == null) {
1580
+ return result;
1581
+ }
1582
+ final Collection<Segment> segments = blueConicClient.getSegments();
1583
+
1584
+ for (Segment segment : segments) {
1585
+ final WritableMap item = getWritableMap();
1586
+ item.putString("id", segment.getId());
1587
+ item.putString("name", segment.getName());
1588
+ result.pushMap(item);
1589
+ }
1590
+
1591
+ return result;
1592
+ }
1593
+
1594
+ /**
1595
+ * Static method that is called by the BlueConicInteraction when it receives the parameters of the dialogue,
1596
+ * and when the dialogue is destroyed by the BlueConic SDK. An event is published to which the JavaScript of the
1597
+ * app should subscribe.
1598
+ *
1599
+ * @param properties The properties of the dialogues as received from BlueConic.
1600
+ * @param eventName The name of the event to be published.
1601
+ */
1602
+ static void publishDialogueEvent(@Nonnull Map<String, Object> properties, String eventName) {
1603
+ WritableMap map = Arguments.makeNativeMap(properties);
1604
+
1605
+ if (helper != null) {
1606
+ helper.getReactContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, map);
1607
+ }
1608
+ }
1609
+
1610
+ protected WritableArray getWritableArray() {
1611
+ return new WritableNativeArray();
1612
+ }
1613
+
1614
+ protected WritableMap getWritableMap() {
1615
+ return new WritableNativeMap();
1616
+ }
1617
+
1618
+ protected Handler getHandler() {
1619
+ return new Handler(Looper.getMainLooper());
1620
+ }
1621
+
1622
+ /**
1623
+ * Imported method from React Native.
1624
+ * Reason for copying the method is to allow unit tests to provide the WritableArray implementation.
1625
+ * Should be kept as is without any changes.
1626
+ *
1627
+ * @param list
1628
+ * @return
1629
+ */
1630
+ protected WritableArray fromList(List list) {
1631
+ WritableArray catalystArray = getWritableArray();
1632
+
1633
+ for (Object obj : list) {
1634
+ if (obj == null) {
1635
+ catalystArray.pushNull();
1636
+ } else if (obj.getClass().isArray()) {
1637
+ catalystArray.pushArray(fromArray(obj));
1638
+ } else if (obj instanceof Bundle) {
1639
+ catalystArray.pushMap(fromBundle((Bundle) obj));
1640
+ } else if (obj instanceof List) {
1641
+ catalystArray.pushArray(fromList((List) obj));
1642
+ } else if (obj instanceof String) {
1643
+ catalystArray.pushString((String) obj);
1644
+ } else if (obj instanceof Integer) {
1645
+ catalystArray.pushInt((Integer) obj);
1646
+ } else if (obj instanceof Number) {
1647
+ catalystArray.pushDouble(((Number) obj).doubleValue());
1648
+ } else {
1649
+ if (!(obj instanceof Boolean)) {
1650
+ throw new IllegalArgumentException("Unknown value type " + obj.getClass());
1651
+ }
1652
+
1653
+ catalystArray.pushBoolean((Boolean) obj);
1654
+ }
1655
+ }
1656
+
1657
+ return catalystArray;
1658
+ }
1659
+
1660
+ /**
1661
+ * Imported method from React Native.
1662
+ * Reason for copying the method is to allow unit tests to provide the WritableArray implementation.
1663
+ * Should be kept as is without any changes.
1664
+ *
1665
+ * @param array
1666
+ * @return
1667
+ */
1668
+ protected WritableArray fromArray(Object array) {
1669
+ WritableArray catalystArray = getWritableArray();
1670
+ int var3;
1671
+ int var4;
1672
+ if (array instanceof String[] var2) {
1673
+ var3 = var2.length;
1674
+
1675
+ for (var4 = 0; var4 < var3; ++var4) {
1676
+ String v = var2[var4];
1677
+ catalystArray.pushString(v);
1678
+ }
1679
+ } else if (array instanceof Bundle[] var7) {
1680
+ var3 = var7.length;
1681
+
1682
+ for (var4 = 0; var4 < var3; ++var4) {
1683
+ Bundle v = var7[var4];
1684
+ catalystArray.pushMap(fromBundle(v));
1685
+ }
1686
+ } else if (array instanceof int[] var8) {
1687
+ var3 = var8.length;
1688
+
1689
+ for (var4 = 0; var4 < var3; ++var4) {
1690
+ int v = var8[var4];
1691
+ catalystArray.pushInt(v);
1692
+ }
1693
+ } else if (array instanceof float[] var9) {
1694
+ var3 = var9.length;
1695
+
1696
+ for (var4 = 0; var4 < var3; ++var4) {
1697
+ float v = var9[var4];
1698
+ catalystArray.pushDouble(v);
1699
+ }
1700
+ } else if (array instanceof double[] var10) {
1701
+ var3 = var10.length;
1702
+
1703
+ for (var4 = 0; var4 < var3; ++var4) {
1704
+ double v = var10[var4];
1705
+ catalystArray.pushDouble(v);
1706
+ }
1707
+ } else if (array instanceof boolean[] var11) {
1708
+ var3 = var11.length;
1709
+
1710
+ for (var4 = 0; var4 < var3; ++var4) {
1711
+ boolean v = var11[var4];
1712
+ catalystArray.pushBoolean(v);
1713
+ }
1714
+ } else {
1715
+ if (!(array instanceof Parcelable[] var12)) {
1716
+ throw new IllegalArgumentException("Unknown array type " + array.getClass());
1717
+ }
1718
+
1719
+ var3 = var12.length;
1720
+
1721
+ for (var4 = 0; var4 < var3; ++var4) {
1722
+ Parcelable v = var12[var4];
1723
+ if (!(v instanceof Bundle)) {
1724
+ throw new IllegalArgumentException("Unexpected array member type " + v.getClass());
1725
+ }
1726
+
1727
+ catalystArray.pushMap(fromBundle((Bundle) v));
1728
+ }
1729
+ }
1730
+
1731
+ return catalystArray;
1732
+ }
1733
+ }
1734
+
1735
+ class PropertiesDialogueHandler implements EventHandler {
1736
+ private final String eventName;
1737
+
1738
+ PropertiesDialogueHandler(String eventName) {
1739
+ this.eventName = eventName;
1740
+ }
1741
+
1742
+ @Override
1743
+ public void handleEvent(@NotNull Event event) {
1744
+ PropertiesDialogueEvent propertiesDialogueEvent = (PropertiesDialogueEvent) event;
1745
+ Map<String, Object> values = new HashMap<>();
1746
+ values.put("variantId", propertiesDialogueEvent.getVariantId());
1747
+ values.put("position", propertiesDialogueEvent.getPosition());
1748
+ values.put("data", propertiesDialogueEvent.getData());
1749
+ BlueConicClientModule.publishDialogueEvent(values, eventName);
1750
+ }
1049
1751
  }