@blueconic/blueconic-react-native 1.2.0 → 2.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.
Files changed (28) hide show
  1. package/BlueConicReactNative.podspec +23 -23
  2. package/CHANGELOG.md +88 -75
  3. package/LICENSE +3 -3
  4. package/README.md +484 -511
  5. package/android/build.gradle +38 -41
  6. package/android/gradle/wrapper/gradle-wrapper.properties +6 -6
  7. package/android/gradlew +172 -172
  8. package/android/local.properties +8 -8
  9. package/android/src/main/AndroidManifest.xml +5 -5
  10. package/android/src/main/java/com/blueconic/blueconicreactnative/BlueConicClientModule.java +870 -857
  11. package/android/src/main/java/com/blueconic/blueconicreactnative/BlueConicClientModuleHelper.java +17 -17
  12. package/android/src/main/java/com/blueconic/blueconicreactnative/BlueConicClientPackage.java +29 -29
  13. package/android/src/main/java/com/blueconic/blueconicreactnative/BlueConicInteraction.java +68 -68
  14. package/index.js +6 -6
  15. package/ios/BlueConicClient-Bridging-Header.h +6 -6
  16. package/ios/BlueConicClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -7
  17. package/ios/BlueConicClient.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  18. package/ios/BlueConicClient.xcodeproj/xcuserdata/youri.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  19. package/ios/BlueConicClientModule.m +74 -72
  20. package/ios/BlueConicClientModule.swift +516 -506
  21. package/ios/BlueConicInteraction.swift +63 -63
  22. package/package.json +18 -18
  23. package/android/.idea/gradle.xml +0 -17
  24. package/android/.idea/misc.xml +0 -9
  25. package/android/.idea/modules/android.iml +0 -18
  26. package/android/.idea/modules.xml +0 -8
  27. package/android/.idea/vcs.xml +0 -6
  28. package/android/.idea/workspace.xml +0 -57
@@ -1,858 +1,871 @@
1
-
2
- package com.blueconic.blueconicreactnative;
3
-
4
- import android.app.Activity;
5
- import android.app.Application;
6
- import android.util.Log;
7
-
8
- import com.facebook.react.bridge.ReactApplicationContext;
9
-
10
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
11
- import com.facebook.react.bridge.ReactMethod;
12
- import com.facebook.react.bridge.ReadableArray;
13
- import com.facebook.react.bridge.Callback;
14
- import com.facebook.react.bridge.Promise;
15
- import com.facebook.react.bridge.Arguments;
16
- import com.facebook.react.bridge.ReadableMap;
17
- import com.facebook.react.bridge.WritableArray;
18
- import com.facebook.react.bridge.WritableMap;
19
- import com.facebook.react.bridge.WritableNativeArray;
20
- import com.facebook.react.bridge.WritableNativeMap;
21
- import com.facebook.react.modules.core.DeviceEventManagerModule;
22
-
23
- import java.util.Map;
24
- import java.util.HashMap;
25
- import java.util.Collections;
26
- import java.util.Collection;
27
- import java.util.List;
28
- import java.util.ArrayList;
29
-
30
- import javax.annotation.Nonnull;
31
-
32
- import com.blueconic.BlueConicClient;
33
- import com.blueconic.BlueConicClientFactory;
34
- import com.blueconic.plugin.events.BlueConicEventFactory;
35
- import com.blueconic.plugin.events.BlueConicEventManager;
36
- import com.blueconic.plugin.events.ClickEvent;
37
- import com.blueconic.plugin.events.UpdateValuesEvent;
38
- import com.blueconic.plugin.events.AdvancedEvent;
39
-
40
- public class BlueConicClientModule extends ReactContextBaseJavaModule {
41
- private static BlueConicClientModuleHelper helper;
42
- private ReactApplicationContext reactContext;
43
-
44
- /**
45
- * The constructor calls the constructor of the superclass and creates an instance of
46
- * the BlueConicClientModuleHelper class which is referred to by a static instance variable. This helper stores the
47
- * reactContext, making it available for use by the static publishReceivedParametersEvent method.
48
- * @param reactContext The application context.
49
- */
50
- public BlueConicClientModule(ReactApplicationContext reactContext) {
51
- super(reactContext);
52
- this.reactContext = reactContext;
53
- helper = new BlueConicClientModuleHelper(reactContext);
54
- getBlueConicClientInstance().registerPluginClass(BlueConicInteraction.class, "BlueConicClient.BlueConicInteraction");
55
-
56
- }
57
-
58
- /**
59
- * The superclass ReactContextBaseJavaModule requires that the getName method is implemented.
60
- * The purpose of this method is to return the name of the Native Module which represents this class in JavaScript.
61
- * Hence, this method allows us to access the native module through NativeModules.BlueConic in JavaScript.
62
- * @return String representing the name of this module.
63
- */
64
- @Override
65
- public String getName() {
66
- return "BlueConicClient";
67
- }
68
-
69
-
70
- // MARK: GETTERS
71
- /**
72
- * Gets the ID of the BlueConic profile. The value is passed to the provided promiseas a String.
73
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
74
- * to pass values back to the JavaScript.
75
- */
76
- @ReactMethod
77
- public void getProfileId(@Nonnull Promise promise) {
78
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
79
- String profileId = "";
80
- if (blueConicClient != null) {
81
- profileId = blueConicClient.getProfileId();
82
- }
83
-
84
- promise.resolve(profileId);
85
- }
86
-
87
- /**
88
- * Gets the values of the specified profile property. The values are passed to the provided promise
89
- * as separate Strings.
90
- * @param property The profile property for which to get the values.
91
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
92
- * to pass values back to the JavaScript.
93
- */
94
- @ReactMethod
95
- public void getProfileValue(@Nonnull String property, @Nonnull Promise promise) {
96
- final List<String> result = new ArrayList<String>();
97
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
98
-
99
- if (blueConicClient != null) {
100
- result.add(blueConicClient.getProfileValue(property));
101
- }
102
-
103
- promise.resolve(result);
104
- }
105
-
106
- /**
107
- * Gets the values of the specified profile property. The values are passed to the provided promise
108
- * as separate Strings.
109
- * @param property The profile property for which to get the values.
110
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
111
- * to pass values back to the JavaScript.
112
- */
113
- @ReactMethod
114
- public void getProfileValues(@Nonnull String property, @Nonnull Promise promise) {
115
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
116
-
117
- if (blueConicClient != null) {
118
- Collection<String> values = blueConicClient.getProfileValues(property);
119
- promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
120
- } else {
121
- promise.resolve(Arguments.createArray());
122
- }
123
- }
124
-
125
- /**
126
- * Gets the ID of the BlueConic profile. The value is passed to the provided callback function as a String.
127
- * @param callback The Callback function to handle the obtained value. Callbacks are necessary in Native Modules
128
- * to pass values back to the JavaScript.
129
- */
130
- @ReactMethod
131
- public void getProfileIdWithCallback(@Nonnull Callback callback) {
132
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
133
- String profileId = "";
134
- if (blueConicClient != null) {
135
- profileId = blueConicClient.getProfileId();
136
- }
137
-
138
- callback.invoke(profileId);
139
- }
140
-
141
- /**
142
- * Gets the values of the specified profile property. The values are passed to the provided callback function
143
- * as separate Strings.
144
- * @param property The profile property for which to get the values.
145
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
146
- * to pass values back to the JavaScript.
147
- */
148
- @ReactMethod
149
- public void getProfileValueWithCallback(@Nonnull String property, @Nonnull Callback callback) {
150
- final List<String> result = new ArrayList<String>();
151
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
152
-
153
- if (blueConicClient != null) {
154
- result.add(blueConicClient.getProfileValue(property));
155
- }
156
-
157
- callback.invoke(result);
158
- }
159
-
160
- /**
161
- * Gets the values of the specified profile property. The values are passed to the provided callback function
162
- * as separate Strings.
163
- * @param property The profile property for which to get the values.
164
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
165
- * to pass values back to the JavaScript.
166
- */
167
- @ReactMethod
168
- public void getProfileValuesWithCallback(@Nonnull String property, @Nonnull Callback callback) {
169
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
170
-
171
- if (blueConicClient != null) {
172
- Collection<String> values = blueConicClient.getProfileValues(property);
173
- callback.invoke(values.toArray());
174
- } else {
175
- callback.invoke(new ArrayList<String>());
176
- }
177
- }
178
-
179
- /**
180
- * Gets the privacy legislation. The values are passed to the provided promise
181
- * as separate String.
182
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
183
- * to pass values back to the JavaScript.
184
- */
185
- @ReactMethod
186
- public void getPrivacyLegislation(@Nonnull Promise promise) {
187
- final List<String> result = new ArrayList<String>();
188
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
189
-
190
- if (blueConicClient != null) {
191
- result.add(blueConicClient.getPrivacyLegislation());
192
- }
193
-
194
- promise.resolve(result);
195
- }
196
-
197
- /**
198
- * Gets the privacy legislation. The values are passed to the provided callback function
199
- * as separate String.
200
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
201
- * to pass values back to the JavaScript.
202
- */
203
- @ReactMethod
204
- public void getPrivacyLegislationWithCallback(@Nonnull Callback callback) {
205
- final List<String> result = new ArrayList<String>();
206
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
207
-
208
- if (blueConicClient != null) {
209
- result.add(blueConicClient.getPrivacyLegislation());
210
- }
211
-
212
- callback.invoke(result);
213
- }
214
-
215
- /**
216
- * Gets the consented objectives. The values are passed to the provided promise
217
- * as separate Strings.
218
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
219
- * to pass values back to the JavaScript.
220
- */
221
- @ReactMethod
222
- public void getConsentedObjectives(@Nonnull Promise promise) {
223
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
224
-
225
- if (blueConicClient != null) {
226
- Collection<String> values = blueConicClient.getConsentedObjectives();
227
- promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
228
- } else {
229
- promise.resolve(Arguments.createArray());
230
- }
231
- }
232
-
233
- /**
234
- * Gets the consented objectives. The values are passed to the provided callback function
235
- * as separate Strings.
236
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
237
- * to pass values back to the JavaScript.
238
- */
239
- @ReactMethod
240
- public void getConsentedObjectivesWithCallback(@Nonnull Callback callback) {
241
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
242
-
243
- if (blueConicClient != null) {
244
- Collection<String> values = blueConicClient.getConsentedObjectives();
245
- callback.invoke(values.toArray());
246
- } else {
247
- callback.invoke(new ArrayList<String>());
248
- }
249
- }
250
-
251
- /**
252
- * Gets the refused objectives. The values are passed to the provided promise
253
- * as separate Strings.
254
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
255
- * to pass values back to the JavaScript.
256
- */
257
- @ReactMethod
258
- public void getRefusedObjectives(@Nonnull Promise promise) {
259
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
260
-
261
- if (blueConicClient != null) {
262
- Collection<String> values = blueConicClient.getRefusedObjectives();
263
- promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
264
- } else {
265
- promise.resolve(Arguments.createArray());
266
- }
267
- }
268
-
269
- /**
270
- * Gets the refused objectives. The values are passed to the provided callback function
271
- * as separate Strings.
272
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
273
- * to pass values back to the JavaScript.
274
- */
275
- @ReactMethod
276
- public void getRefusedObjectivesWithCallback(@Nonnull Callback callback) {
277
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
278
-
279
- if (blueConicClient != null) {
280
- Collection<String> values = blueConicClient.getRefusedObjectives();
281
- callback.invoke(values.toArray());
282
- } else {
283
- callback.invoke(new ArrayList<String>());
284
- }
285
- }
286
-
287
-
288
- /**
289
- * Gets the segments of the profile.
290
- * To retrieve and update the Segments you have to register a pageview first.
291
- * The values are passed to the provided promise
292
- * as a list of Objects containing id and name.
293
- * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
294
- * to pass values back to the JavaScript.
295
- */
296
- @ReactMethod
297
- public void getSegments(@Nonnull Promise promise) {
298
- promise.resolve(getFormattedSegments());
299
- }
300
-
301
- /**
302
- * Gets the segments of the profile.
303
- * To retrieve and update the Segments you have to register a pageview first.
304
- * The values are passed to the provided promise
305
- * as a list of Objects containing id and name.
306
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
307
- * to pass values back to the JavaScript.
308
- */
309
- @ReactMethod
310
- public void getSegmentsWithCallback(@Nonnull Callback callback) {
311
- callback.invoke(getFormattedSegments());
312
- }
313
-
314
- // MARK: ADDERS
315
- /**
316
- * Adds the given values to the specified profile property.
317
- * @param property The profile property to which to add the values.
318
- * @param values A ReadableArray containing Strings that will be added to the profile property.
319
- */
320
- @ReactMethod
321
- public void addProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
322
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
323
- if (blueConicClient != null) {
324
- blueConicClient.addProfileValues(property, Arguments.toList(values));
325
- }
326
- }
327
-
328
- /**
329
- * Adds the given values to the specified profile property.
330
- * @param property The profile property to which to add the values.
331
- * @param value A ReadableArray containing Strings that will be added to the profile property.
332
- */
333
- @ReactMethod
334
- public void addProfileValue(@Nonnull String property, @Nonnull String value) {
335
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
336
- if (blueConicClient != null) {
337
- blueConicClient.addProfileValue(property, value);
338
- }
339
- }
340
-
341
- /**
342
- * Adds an objective to the consented objectives list.
343
- * @param objectiveId The id of the objective to add to consented objectives.
344
- */
345
- @ReactMethod
346
- public void addConsentedObjective(@Nonnull String objectiveId) {
347
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
348
- if (blueConicClient != null) {
349
- blueConicClient.addConsentedObjective(objectiveId);
350
- }
351
- }
352
-
353
- /**
354
- * Adds an objective to the refused objectives list.
355
- * @param objectiveId The id of the objective to add to refused objectives.
356
- */
357
- @ReactMethod
358
- public void addRefusedObjective(@Nonnull String objectiveId) {
359
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
360
- if (blueConicClient != null) {
361
- blueConicClient.addRefusedObjective(objectiveId);
362
- }
363
- }
364
-
365
- // MARK: SETTERS
366
- /**
367
- * Sets the given values for the specified profile property.
368
- * @param property The profile property for which to set the values.
369
- * @param values A ReadableArray containing Strings that will be set as the new values for the profile property.
370
- */
371
- @ReactMethod
372
- public void setProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
373
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
374
- if (blueConicClient != null) {
375
- blueConicClient.setProfileValues(property, Arguments.toList(values));
376
- }
377
- }
378
-
379
- /**
380
- * Set the given value for the specified profile property.
381
- * @param property The profile property for which to set the values.
382
- * @param value A ReadableArray containing Strings that will be set as the new values for the profile property.
383
- */
384
- @ReactMethod
385
- public void setProfileValue(@Nonnull String property, @Nonnull String value) {
386
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
387
- if (blueConicClient != null) {
388
- blueConicClient.setProfileValue(property, value);
389
- }
390
- }
391
-
392
- /**
393
- * Set the privacy legislation.
394
- * @param privacyLegislation The privacy legislation.
395
- */
396
- @ReactMethod
397
- public void setPrivacyLegislation(@Nonnull String privacyLegislation) {
398
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
399
- if (blueConicClient != null) {
400
- blueConicClient.setPrivacyLegislation(privacyLegislation);
401
- }
402
- }
403
-
404
- /**
405
- * Sets the given objectives for consented objectives.
406
- * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
407
- */
408
- @ReactMethod
409
- public void setConsentedObjectives(@Nonnull ReadableArray objectiveIds) {
410
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
411
- if (blueConicClient != null) {
412
- blueConicClient.setConsentedObjectives(Arguments.toList(objectiveIds));
413
- }
414
- }
415
-
416
- /**
417
- * Sets the given objectives for consented objectives.
418
- * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
419
- */
420
- @ReactMethod
421
- public void setRefusedObjectives(@Nonnull ReadableArray objectiveIds) {
422
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
423
- if (blueConicClient != null) {
424
- blueConicClient.setRefusedObjectives(Arguments.toList(objectiveIds));
425
- }
426
- }
427
-
428
- /**
429
- * Set enabled.
430
- * Define to enable and disable the BlueConicClient
431
- * To prevent or re-activate tracking data
432
- * @param isEnabled to enable or disable the BlueConicClient.
433
- */
434
- @ReactMethod
435
- public void setEnabled(@Nonnull Boolean isEnabled) {
436
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
437
- if (blueConicClient != null) {
438
- blueConicClient.setEnabled(isEnabled == null ? false : isEnabled.booleanValue());
439
- }
440
-
441
- }
442
-
443
- /**
444
- * Return is BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings.
445
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
446
- * Native Modules to pass values back to the JavaScript.
447
- */
448
- @ReactMethod
449
- public void isEnabled(@Nonnull Promise promise) {
450
- final List<Boolean> result = new ArrayList<Boolean>();
451
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
452
-
453
- if (blueConicClient != null) {
454
- result.add(Boolean.valueOf(blueConicClient.isEnabled()));
455
- }
456
-
457
- promise.resolve(result);
458
- }
459
-
460
- /**
461
- * Return is BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings
462
- * @param callback: The callback function to handle the obtained value. Callbacks are necessary in
463
- * Native Modules to pass values back to the JavaScript.
464
- */
465
- @ReactMethod
466
- public void isEnabledWithCallback(@Nonnull Callback callback) {
467
- final List<Boolean> result = new ArrayList<Boolean>();
468
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
469
-
470
- if (blueConicClient != null) {
471
- result.add(Boolean.valueOf(blueConicClient.isEnabled()));
472
- }
473
-
474
- callback.invoke(result);
475
- }
476
-
477
- /**
478
- * Return whether the BlueConic profile is part of the BlueConic segment. The value is passed to the provided callback function as Boolean.
479
- * @param segmentId The id of the segment
480
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
481
- * Native Modules to pass values back to the JavaScript.
482
- */
483
- @ReactMethod
484
- public void hasSegment(@Nonnull String segmentId, @Nonnull Promise promise) {
485
- final List<Boolean> result = new ArrayList<Boolean>();
486
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
487
-
488
- if (blueConicClient != null) {
489
- result.add(Boolean.valueOf(blueConicClient.hasSegment(segmentId)));
490
- }
491
-
492
- promise.resolve(result);
493
- }
494
-
495
- /**
496
- * Return whether the BlueConic profile is part of the BlueConic segment. The value is passed to the provided callback function as Boolean.
497
- * @param segmentId The id of the segment
498
- * @param callback: The callback function to handle the obtained value. Callbacks are necessary in
499
- * Native Modules to pass values back to the JavaScript.
500
- */
501
- @ReactMethod
502
- public void hasSegmentWithCallback(@Nonnull String segmentId, @Nonnull Callback callback) {
503
- final List<Boolean> result = new ArrayList<Boolean>();
504
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
505
-
506
- if (blueConicClient != null) {
507
- result.add(Boolean.valueOf(blueConicClient.hasSegment(segmentId)));
508
- }
509
-
510
- callback.invoke(result);
511
- }
512
-
513
- // MARK: REGISTERS
514
- /**
515
- * Create Event.
516
- * @param eventName The name of the event
517
- * @param readableMap The readable map retrieved from React native
518
- */
519
- @ReactMethod
520
- public void createEvent(@Nonnull String eventName, ReadableMap readableMap) {
521
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
522
- final Map<String, Object> properties = readableMap.toHashMap();
523
-
524
- if (blueConicClient != null) {
525
- blueConicClient.createEventWithData(eventName, properties);
526
- }
527
- }
528
-
529
- /**
530
- * Create Event.
531
- * @param eventName The name of the event
532
- * @param readableMap The readable map retrieved from React native
533
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
534
- * Native Modules to pass values back to the JavaScript.
535
- */
536
- @ReactMethod
537
- public void createEventSync(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Promise promise) {
538
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
539
- final Map<String, Object> properties = readableMap.toHashMap();
540
-
541
- if (blueConicClient != null) {
542
- blueConicClient.createEventWithData(eventName, properties, new Runnable() {
543
- @Override
544
- public void run() {
545
- promise.resolve(Arguments.createArray());
546
- }
547
- });
548
- return;
549
- }
550
-
551
- promise.resolve(Arguments.createArray());
552
- }
553
-
554
- /**
555
- * Create Event.
556
- * @param eventName The name of the event
557
- * @param readableMap The readable map retrieved from React native
558
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
559
- * to pass values back to the JavaScript.
560
- */
561
- @ReactMethod
562
- public void createEventSyncWithCallback(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Callback callback) {
563
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
564
- final Map<String, Object> properties = readableMap.toHashMap();
565
-
566
- if (blueConicClient != null) {
567
- blueConicClient.createEventWithData(eventName, properties, new Runnable() {
568
- @Override
569
- public void run() {
570
- callback.invoke(Arguments.createArray());
571
- }
572
- });
573
- return;
574
- }
575
-
576
- callback.invoke(Arguments.createArray());
577
- }
578
-
579
-
580
- /**
581
- * Update sync the BlueConic Profile
582
- */
583
- @ReactMethod
584
- public void updateProfile() {
585
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
586
-
587
- if (blueConicClient != null) {
588
- blueConicClient.updateProfile();
589
- }
590
- }
591
-
592
- /**
593
- * Update sync the BlueConic Profile
594
- * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
595
- * Native Modules to pass values back to the JavaScript.
596
- */
597
- @ReactMethod
598
- public void updateProfileSync(@Nonnull final Promise promise) {
599
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
600
-
601
- if (blueConicClient != null) {
602
- blueConicClient.updateProfile(new Runnable() {
603
- @Override
604
- public void run() {
605
- promise.resolve(Arguments.createArray());
606
- }
607
- });
608
-
609
- return;
610
- }
611
-
612
- promise.resolve(Arguments.createArray());
613
- }
614
-
615
- /**
616
- * Update sync the BlueConic Profile
617
- * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
618
- * to pass values back to the JavaScript.
619
- */
620
- @ReactMethod
621
- public void updateProfileSyncWithCallback(@Nonnull final Callback callback) {
622
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
623
-
624
- if (blueConicClient != null) {
625
- blueConicClient.updateProfile(new Runnable() {
626
- @Override
627
- public void run() {
628
- callback.invoke(Arguments.createArray());
629
- }
630
- });
631
-
632
- return;
633
- }
634
-
635
- callback.invoke(Arguments.createArray());
636
- }
637
-
638
- /**
639
- * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
640
- * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
641
- * @param screenName The name of the screen.
642
- */
643
- @ReactMethod
644
- public void registerPageView(@Nonnull String screenName) {
645
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
646
- if (blueConicClient != null) {
647
- // blueConicClient instance must have an activity or application
648
- final Map<String, String> properties = new HashMap<>();
649
- properties.put("screenName", screenName);
650
- Activity activity = getCurrentActivity();
651
- if (activity == null) {
652
- activity = new Activity();
653
- }
654
-
655
- blueConicClient.createEvent("PAGEVIEW", properties, activity);
656
- } else {
657
- Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
658
- }
659
- }
660
-
661
- /**
662
- * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
663
- * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
664
- * @param screenName The name of the screen.
665
- */
666
- @ReactMethod
667
- public void registerPageViewSync(@Nonnull String screenName, @Nonnull final Promise promise) {
668
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
669
- if (blueConicClient != null) {
670
- // blueConicClient instance must have an activity or application
671
- final Map<String, String> properties = new HashMap<>();
672
- properties.put("screenName", screenName);
673
- Activity activity = getCurrentActivity();
674
- if (activity == null) {
675
- activity = new Activity();
676
- }
677
-
678
- blueConicClient.createEvent("PAGEVIEW", properties, activity, new Runnable() {
679
- @Override
680
- public void run() {
681
- promise.resolve(Arguments.createArray());
682
- }
683
- });
684
- } else {
685
- Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
686
- promise.resolve(Arguments.createArray());
687
- }
688
- }
689
-
690
- /**
691
- * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
692
- * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
693
- * @param screenName The name of the screen.
694
- */
695
- @ReactMethod
696
- public void registerPageViewSyncCallback(@Nonnull String screenName, @Nonnull final Callback callback) {
697
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
698
- if (blueConicClient != null) {
699
- // blueConicClient instance must have an activity or application
700
- final Map<String, String> properties = new HashMap<>();
701
- properties.put("screenName", screenName);
702
- Activity activity = getCurrentActivity();
703
- if (activity == null) {
704
- activity = new Activity();
705
- }
706
-
707
- blueConicClient.createEvent("PAGEVIEW", properties, activity, new Runnable() {
708
- @Override
709
- public void run() {
710
- callback.invoke(Arguments.createArray());
711
- }
712
- });
713
- } else {
714
- Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
715
- callback.invoke(Arguments.createArray());
716
- }
717
- }
718
-
719
- /**
720
- * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
721
- * @param selector The selector to identify the clicked component.
722
- */
723
- @ReactMethod
724
- public void registerClickEvent(@Nonnull String selector) {
725
- getBlueConicEventManagerInstance().publish(new ClickEvent(selector));
726
- }
727
-
728
- /**
729
- * Creates a ClickEvent for the given selector and values, and publishes the event using the EventManager.
730
- * @param selector The selector to identify the clicked component.
731
- * @param values The values to pass to BlueConic as context of the event.
732
- */
733
- @ReactMethod
734
- public void registerClickEventWithContext(@Nonnull String selector, @Nonnull ReadableArray values) {
735
- getBlueConicEventManagerInstance().publish(new ClickEvent(selector, Arguments.toList(values)));
736
- }
737
-
738
- /**
739
- * Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
740
- * @param selector The selector to identify the component with updated values.
741
- * @param value The value to be passed on to BlueConic.
742
- */
743
- @ReactMethod
744
- public void registerUpdateValuesEvent(@Nonnull String selector, @Nonnull String value) {
745
- UpdateValuesEvent event = new UpdateValuesEvent(selector, Collections.singletonList(value));
746
- getBlueConicEventManagerInstance().publish(event);
747
- }
748
-
749
- /**
750
- * Creates an AdvancedEvent with the given name and values, and publishes the event using the EventManager.
751
- * @param name The name to identify the event.
752
- * @param values The values to pass to BlueConic as context of the event.
753
- */
754
- @ReactMethod
755
- public void registerAdvancedEvent(@Nonnull String name, @Nonnull ReadableArray values) {
756
- AdvancedEvent event = new AdvancedEvent(name, Arguments.toList(values));
757
- getBlueConicEventManagerInstance().publish(event);
758
- }
759
-
760
-
761
-
762
- /**
763
- * Destroys all active BlueConic plugins (i.e. instances of listeners and dialogues). This method must be called
764
- * in the onPause of an activity if the app targets Android API versions before API 14. It should also be called if
765
- * one switches screens in the app without calling the onPause of the previous Activity.
766
- *
767
- */
768
- @ReactMethod
769
- public void destroyPlugins() {
770
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
771
- if (blueConicClient != null) {
772
- blueConicClient.destroyPlugins();
773
- }
774
- }
775
-
776
- /**
777
- * Sends an event to the BlueConic server, indicating that a certain interaction was viewed, clicked, or converted for.
778
- * @param eventType The event type to register for the interaction. Possible events are "VIEW", "CLICK" and "CONVERSION".
779
- * @param interactionId The unique identifier of the interaction.
780
- */
781
- @ReactMethod
782
- public void registerDialogueEvent(@Nonnull String eventType, @Nonnull String interactionId) {
783
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
784
- if (blueConicClient != null) {
785
- final Map<String, String> interactionIdMap = new HashMap<>();
786
- interactionIdMap.put("interactionId", interactionId);
787
- blueConicClient.createEvent(eventType, interactionIdMap);
788
- }
789
- }
790
-
791
-
792
- /**
793
- * Returns an instance of the BlueConicClient
794
- * @return BlueConicClient
795
- */
796
- private BlueConicClient getBlueConicClientInstance() {
797
- // Retrieve current Activity from ReactContextBaseJavaModule
798
- final Activity currentActivity = getCurrentActivity();
799
- if (currentActivity != null) {
800
- // Activity found and return a BlueConicClient instance
801
- return BlueConicClientFactory.getInstance(currentActivity);
802
- }
803
-
804
- // Current Activity is not set yet, try using BaseContext as a safe-cast to Application
805
- if (this.reactContext.getApplicationContext() instanceof Application) {
806
- // Cast BaseContext to an Application
807
- final Application application = (Application) this.reactContext.getApplicationContext();
808
- return BlueConicClientFactory.getInstance(application);
809
- }
810
-
811
- return null;
812
- }
813
-
814
- /**
815
- * Returns an instance of the BlueConicEventManager
816
- * @return BlueConicClient
817
- */
818
- private BlueConicEventManager getBlueConicEventManagerInstance() {
819
- return BlueConicEventFactory.getInstance();
820
- }
821
-
822
- private WritableArray getFormattedSegments() {
823
- final WritableArray result = new WritableNativeArray();
824
- final BlueConicClient blueConicClient = getBlueConicClientInstance();
825
-
826
- if (blueConicClient == null) {
827
- return result;
828
- }
829
- final Collection<BlueConicClient.Segment> segments = blueConicClient.getSegments();
830
-
831
- for (BlueConicClient.Segment segment : segments) {
832
- final WritableMap item = new WritableNativeMap();
833
- item.putString("id", segment.getId());
834
- item.putString("name", segment.getName());
835
- result.pushMap(item);
836
- }
837
-
838
- return result;
839
- }
840
-
841
- /**
842
- * Static method that is called by the BlueConicInteraction when it receives the parameters of the dialogue,
843
- * and when the dialogue is destroyed by the BlueConic SDK. An event is published to which the JavaScript of the
844
- * app should subscribe.
845
- * @param properties The properties of the dialogues as received from BlueConic.
846
- * @param eventName The name of the event to be published.
847
- */
848
- static void publishDialogueEvent(@Nonnull Map<String, Object> properties, String eventName) {
849
- WritableMap map = Arguments.makeNativeMap(properties);
850
-
851
- if (helper != null) {
852
- helper
853
- .getReactContext()
854
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
855
- .emit(eventName, map);
856
- }
857
- }
1
+
2
+ package com.blueconic.blueconicreactnative;
3
+
4
+ import android.app.Activity;
5
+ import android.app.Application;
6
+ import android.util.Log;
7
+
8
+ import com.facebook.react.bridge.ReactApplicationContext;
9
+
10
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
11
+ import com.facebook.react.bridge.ReactMethod;
12
+ import com.facebook.react.bridge.ReadableArray;
13
+ import com.facebook.react.bridge.Callback;
14
+ import com.facebook.react.bridge.Promise;
15
+ import com.facebook.react.bridge.Arguments;
16
+ import com.facebook.react.bridge.ReadableMap;
17
+ import com.facebook.react.bridge.WritableArray;
18
+ import com.facebook.react.bridge.WritableMap;
19
+ import com.facebook.react.bridge.WritableNativeArray;
20
+ import com.facebook.react.bridge.WritableNativeMap;
21
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
22
+
23
+ import java.util.Map;
24
+ import java.util.HashMap;
25
+ import java.util.Collections;
26
+ import java.util.Collection;
27
+ import java.util.List;
28
+ import java.util.ArrayList;
29
+
30
+ import javax.annotation.Nonnull;
31
+
32
+ import com.blueconic.BlueConicClient;
33
+ import com.blueconic.BlueConicClientFactory;
34
+ import com.blueconic.plugin.events.BlueConicEventFactory;
35
+ import com.blueconic.plugin.events.BlueConicEventManager;
36
+ import com.blueconic.plugin.events.ClickEvent;
37
+ import com.blueconic.plugin.events.UpdateValuesEvent;
38
+ import com.blueconic.plugin.events.AdvancedEvent;
39
+
40
+ public class BlueConicClientModule extends ReactContextBaseJavaModule {
41
+ private static BlueConicClientModuleHelper helper;
42
+ private ReactApplicationContext reactContext;
43
+
44
+ /**
45
+ * The constructor calls the constructor of the superclass and creates an instance of
46
+ * the BlueConicClientModuleHelper class which is referred to by a static instance variable. This helper stores the
47
+ * reactContext, making it available for use by the static publishReceivedParametersEvent method.
48
+ * @param reactContext The application context.
49
+ */
50
+ public BlueConicClientModule(ReactApplicationContext reactContext) {
51
+ super(reactContext);
52
+ this.reactContext = reactContext;
53
+ helper = new BlueConicClientModuleHelper(reactContext);
54
+ getBlueConicClientInstance().registerPluginClass(BlueConicInteraction.class, "BlueConicClient.BlueConicInteraction");
55
+
56
+ }
57
+
58
+ /**
59
+ * The superclass ReactContextBaseJavaModule requires that the getName method is implemented.
60
+ * The purpose of this method is to return the name of the Native Module which represents this class in JavaScript.
61
+ * Hence, this method allows us to access the native module through NativeModules.BlueConic in JavaScript.
62
+ * @return String representing the name of this module.
63
+ */
64
+ @Override
65
+ public String getName() {
66
+ return "BlueConicClient";
67
+ }
68
+
69
+
70
+ // MARK: GETTERS
71
+ /**
72
+ * Gets the ID of the BlueConic profile. The value is passed to the provided promiseas a String.
73
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
74
+ * to pass values back to the JavaScript.
75
+ */
76
+ @ReactMethod
77
+ public void getProfileId(@Nonnull Promise promise) {
78
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
79
+ String profileId = "";
80
+ if (blueConicClient != null) {
81
+ profileId = blueConicClient.getProfileId();
82
+ }
83
+
84
+ promise.resolve(profileId);
85
+ }
86
+
87
+ /**
88
+ * Gets the values of the specified profile property. The values are passed to the provided promise
89
+ * as separate Strings.
90
+ * @param property The profile property for which to get the values.
91
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
92
+ * to pass values back to the JavaScript.
93
+ */
94
+ @ReactMethod
95
+ public void getProfileValue(@Nonnull String property, @Nonnull Promise promise) {
96
+ final List<String> result = new ArrayList<String>();
97
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
98
+
99
+ if (blueConicClient != null) {
100
+ result.add(blueConicClient.getProfileValue(property));
101
+ }
102
+
103
+ promise.resolve(result);
104
+ }
105
+
106
+ /**
107
+ * Gets the values of the specified profile property. The values are passed to the provided promise
108
+ * as separate Strings.
109
+ * @param property The profile property for which to get the values.
110
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
111
+ * to pass values back to the JavaScript.
112
+ */
113
+ @ReactMethod
114
+ public void getProfileValues(@Nonnull String property, @Nonnull Promise promise) {
115
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
116
+
117
+ if (blueConicClient != null) {
118
+ Collection<String> values = blueConicClient.getProfileValues(property);
119
+ promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
120
+ } else {
121
+ promise.resolve(Arguments.createArray());
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Gets the ID of the BlueConic profile. The value is passed to the provided callback function as a String.
127
+ * @param callback The Callback function to handle the obtained value. Callbacks are necessary in Native Modules
128
+ * to pass values back to the JavaScript.
129
+ */
130
+ @ReactMethod
131
+ public void getProfileIdWithCallback(@Nonnull Callback callback) {
132
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
133
+ String profileId = "";
134
+ if (blueConicClient != null) {
135
+ profileId = blueConicClient.getProfileId();
136
+ }
137
+
138
+ callback.invoke(profileId);
139
+ }
140
+
141
+ /**
142
+ * Gets the values of the specified profile property. The values are passed to the provided callback function
143
+ * as separate Strings.
144
+ * @param property The profile property for which to get the values.
145
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
146
+ * to pass values back to the JavaScript.
147
+ */
148
+ @ReactMethod
149
+ public void getProfileValueWithCallback(@Nonnull String property, @Nonnull Callback callback) {
150
+ final List<String> result = new ArrayList<String>();
151
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
152
+
153
+ if (blueConicClient != null) {
154
+ result.add(blueConicClient.getProfileValue(property));
155
+ }
156
+
157
+ callback.invoke(result);
158
+ }
159
+
160
+ /**
161
+ * Gets the values of the specified profile property. The values are passed to the provided callback function
162
+ * as separate Strings.
163
+ * @param property The profile property for which to get the values.
164
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
165
+ * to pass values back to the JavaScript.
166
+ */
167
+ @ReactMethod
168
+ public void getProfileValuesWithCallback(@Nonnull String property, @Nonnull Callback callback) {
169
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
170
+
171
+ if (blueConicClient != null) {
172
+ Collection<String> values = blueConicClient.getProfileValues(property);
173
+ callback.invoke(values.toArray());
174
+ } else {
175
+ callback.invoke(new ArrayList<String>());
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Gets the privacy legislation. The values are passed to the provided promise
181
+ * as separate String.
182
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
183
+ * to pass values back to the JavaScript.
184
+ */
185
+ @ReactMethod
186
+ public void getPrivacyLegislation(@Nonnull Promise promise) {
187
+ final List<String> result = new ArrayList<String>();
188
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
189
+
190
+ if (blueConicClient != null) {
191
+ result.add(blueConicClient.getPrivacyLegislation());
192
+ }
193
+
194
+ promise.resolve(result);
195
+ }
196
+
197
+ /**
198
+ * Gets the privacy legislation. The values are passed to the provided callback function
199
+ * as separate String.
200
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
201
+ * to pass values back to the JavaScript.
202
+ */
203
+ @ReactMethod
204
+ public void getPrivacyLegislationWithCallback(@Nonnull Callback callback) {
205
+ final List<String> result = new ArrayList<String>();
206
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
207
+
208
+ if (blueConicClient != null) {
209
+ result.add(blueConicClient.getPrivacyLegislation());
210
+ }
211
+
212
+ callback.invoke(result);
213
+ }
214
+
215
+ /**
216
+ * Gets the consented objectives. The values are passed to the provided promise
217
+ * as separate Strings.
218
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
219
+ * to pass values back to the JavaScript.
220
+ */
221
+ @ReactMethod
222
+ public void getConsentedObjectives(@Nonnull Promise promise) {
223
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
224
+
225
+ if (blueConicClient != null) {
226
+ Collection<String> values = blueConicClient.getConsentedObjectives();
227
+ promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
228
+ } else {
229
+ promise.resolve(Arguments.createArray());
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Gets the consented objectives. The values are passed to the provided callback function
235
+ * as separate Strings.
236
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
237
+ * to pass values back to the JavaScript.
238
+ */
239
+ @ReactMethod
240
+ public void getConsentedObjectivesWithCallback(@Nonnull Callback callback) {
241
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
242
+
243
+ if (blueConicClient != null) {
244
+ Collection<String> values = blueConicClient.getConsentedObjectives();
245
+ callback.invoke(values.toArray());
246
+ } else {
247
+ callback.invoke(new ArrayList<String>());
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Gets the refused objectives. The values are passed to the provided promise
253
+ * as separate Strings.
254
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
255
+ * to pass values back to the JavaScript.
256
+ */
257
+ @ReactMethod
258
+ public void getRefusedObjectives(@Nonnull Promise promise) {
259
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
260
+
261
+ if (blueConicClient != null) {
262
+ Collection<String> values = blueConicClient.getRefusedObjectives();
263
+ promise.resolve(Arguments.fromList(new ArrayList<String>(values)));
264
+ } else {
265
+ promise.resolve(Arguments.createArray());
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Gets the refused objectives. The values are passed to the provided callback function
271
+ * as separate Strings.
272
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
273
+ * to pass values back to the JavaScript.
274
+ */
275
+ @ReactMethod
276
+ public void getRefusedObjectivesWithCallback(@Nonnull Callback callback) {
277
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
278
+
279
+ if (blueConicClient != null) {
280
+ Collection<String> values = blueConicClient.getRefusedObjectives();
281
+ callback.invoke(values.toArray());
282
+ } else {
283
+ callback.invoke(new ArrayList<String>());
284
+ }
285
+ }
286
+
287
+
288
+ /**
289
+ * Gets the segments of the profile.
290
+ * To retrieve and update the Segments you have to register a pageview first.
291
+ * The values are passed to the provided promise
292
+ * as a list of Objects containing id and name.
293
+ * @param promise The Promise to handle the obtained values. Promises are necessary in Native Modules
294
+ * to pass values back to the JavaScript.
295
+ */
296
+ @ReactMethod
297
+ public void getSegments(@Nonnull Promise promise) {
298
+ promise.resolve(getFormattedSegments());
299
+ }
300
+
301
+ /**
302
+ * Gets the segments of the profile.
303
+ * To retrieve and update the Segments you have to register a pageview first.
304
+ * The values are passed to the provided promise
305
+ * as a list of Objects containing id and name.
306
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
307
+ * to pass values back to the JavaScript.
308
+ */
309
+ @ReactMethod
310
+ public void getSegmentsWithCallback(@Nonnull Callback callback) {
311
+ callback.invoke(getFormattedSegments());
312
+ }
313
+
314
+ // MARK: ADDERS
315
+ /**
316
+ * Adds the given values to the specified profile property.
317
+ * @param property The profile property to which to add the values.
318
+ * @param values A ReadableArray containing Strings that will be added to the profile property.
319
+ */
320
+ @ReactMethod
321
+ public void addProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
322
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
323
+ if (blueConicClient != null) {
324
+ blueConicClient.addProfileValues(property, Arguments.toList(values));
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Adds the given values to the specified profile property.
330
+ * @param property The profile property to which to add the values.
331
+ * @param value A ReadableArray containing Strings that will be added to the profile property.
332
+ */
333
+ @ReactMethod
334
+ public void addProfileValue(@Nonnull String property, @Nonnull String value) {
335
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
336
+ if (blueConicClient != null) {
337
+ blueConicClient.addProfileValue(property, value);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Adds an objective to the consented objectives list.
343
+ * @param objectiveId The id of the objective to add to consented objectives.
344
+ */
345
+ @ReactMethod
346
+ public void addConsentedObjective(@Nonnull String objectiveId) {
347
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
348
+ if (blueConicClient != null) {
349
+ blueConicClient.addConsentedObjective(objectiveId);
350
+ }
351
+ }
352
+
353
+ /**
354
+ * Adds an objective to the refused objectives list.
355
+ * @param objectiveId The id of the objective to add to refused objectives.
356
+ */
357
+ @ReactMethod
358
+ public void addRefusedObjective(@Nonnull String objectiveId) {
359
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
360
+ if (blueConicClient != null) {
361
+ blueConicClient.addRefusedObjective(objectiveId);
362
+ }
363
+ }
364
+
365
+ // MARK: SETTERS
366
+ /**
367
+ * Sets the given values for the specified profile property.
368
+ * @param property The profile property for which to set the values.
369
+ * @param values A ReadableArray containing Strings that will be set as the new values for the profile property.
370
+ */
371
+ @ReactMethod
372
+ public void setProfileValues(@Nonnull String property, @Nonnull ReadableArray values) {
373
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
374
+ if (blueConicClient != null) {
375
+ blueConicClient.setProfileValues(property, Arguments.toList(values));
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Set the given value for the specified profile property.
381
+ * @param property The profile property for which to set the values.
382
+ * @param value A ReadableArray containing Strings that will be set as the new values for the profile property.
383
+ */
384
+ @ReactMethod
385
+ public void setProfileValue(@Nonnull String property, @Nonnull String value) {
386
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
387
+ if (blueConicClient != null) {
388
+ blueConicClient.setProfileValue(property, value);
389
+ }
390
+ }
391
+
392
+ /**
393
+ * Increments the given values to the specified profile property.
394
+ * @param property The profile property to which to increment the values.
395
+ * @param value A ReadableArray containing Strings that will be incremented to the profile property.
396
+ */
397
+ @ReactMethod
398
+ public void incrementProfileValue(@Nonnull String property, @Nonnull String value) {
399
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
400
+ if (blueConicClient != null) {
401
+ blueConicClient.incrementProfileValue(property, value);
402
+ }
403
+ }
404
+
405
+ /**
406
+ * Set the privacy legislation.
407
+ * @param privacyLegislation The privacy legislation.
408
+ */
409
+ @ReactMethod
410
+ public void setPrivacyLegislation(@Nonnull String privacyLegislation) {
411
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
412
+ if (blueConicClient != null) {
413
+ blueConicClient.setPrivacyLegislation(privacyLegislation);
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Sets the given objectives for consented objectives.
419
+ * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
420
+ */
421
+ @ReactMethod
422
+ public void setConsentedObjectives(@Nonnull ReadableArray objectiveIds) {
423
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
424
+ if (blueConicClient != null) {
425
+ blueConicClient.setConsentedObjectives(Arguments.toList(objectiveIds));
426
+ }
427
+ }
428
+
429
+ /**
430
+ * Sets the given objectives for consented objectives.
431
+ * @param objectiveIds A ReadableArray containing IDs of Objectives that will be set as the new values for Consented objectives.
432
+ */
433
+ @ReactMethod
434
+ public void setRefusedObjectives(@Nonnull ReadableArray objectiveIds) {
435
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
436
+ if (blueConicClient != null) {
437
+ blueConicClient.setRefusedObjectives(Arguments.toList(objectiveIds));
438
+ }
439
+ }
440
+
441
+ /**
442
+ * Set enabled.
443
+ * Define to enable and disable the BlueConicClient
444
+ * To prevent or re-activate tracking data
445
+ * @param isEnabled to enable or disable the BlueConicClient.
446
+ */
447
+ @ReactMethod
448
+ public void setEnabled(@Nonnull Boolean isEnabled) {
449
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
450
+ if (blueConicClient != null) {
451
+ blueConicClient.setEnabled(isEnabled == null ? false : isEnabled.booleanValue());
452
+ }
453
+
454
+ }
455
+
456
+ /**
457
+ * Return is BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings.
458
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
459
+ * Native Modules to pass values back to the JavaScript.
460
+ */
461
+ @ReactMethod
462
+ public void isEnabled(@Nonnull Promise promise) {
463
+ final List<Boolean> result = new ArrayList<Boolean>();
464
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
465
+
466
+ if (blueConicClient != null) {
467
+ result.add(Boolean.valueOf(blueConicClient.isEnabled()));
468
+ }
469
+
470
+ promise.resolve(result);
471
+ }
472
+
473
+ /**
474
+ * Return is BlueConicClient enabled. The value is passed to the provided callback function as seperated Strings
475
+ * @param callback: The callback function to handle the obtained value. Callbacks are necessary in
476
+ * Native Modules to pass values back to the JavaScript.
477
+ */
478
+ @ReactMethod
479
+ public void isEnabledWithCallback(@Nonnull Callback callback) {
480
+ final List<Boolean> result = new ArrayList<Boolean>();
481
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
482
+
483
+ if (blueConicClient != null) {
484
+ result.add(Boolean.valueOf(blueConicClient.isEnabled()));
485
+ }
486
+
487
+ callback.invoke(result);
488
+ }
489
+
490
+ /**
491
+ * Return whether the BlueConic profile is part of the BlueConic segment. The value is passed to the provided callback function as Boolean.
492
+ * @param segmentId The id of the segment
493
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
494
+ * Native Modules to pass values back to the JavaScript.
495
+ */
496
+ @ReactMethod
497
+ public void hasSegment(@Nonnull String segmentId, @Nonnull Promise promise) {
498
+ final List<Boolean> result = new ArrayList<Boolean>();
499
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
500
+
501
+ if (blueConicClient != null) {
502
+ result.add(Boolean.valueOf(blueConicClient.hasSegment(segmentId)));
503
+ }
504
+
505
+ promise.resolve(result);
506
+ }
507
+
508
+ /**
509
+ * Return whether the BlueConic profile is part of the BlueConic segment. The value is passed to the provided callback function as Boolean.
510
+ * @param segmentId The id of the segment
511
+ * @param callback: The callback function to handle the obtained value. Callbacks are necessary in
512
+ * Native Modules to pass values back to the JavaScript.
513
+ */
514
+ @ReactMethod
515
+ public void hasSegmentWithCallback(@Nonnull String segmentId, @Nonnull Callback callback) {
516
+ final List<Boolean> result = new ArrayList<Boolean>();
517
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
518
+
519
+ if (blueConicClient != null) {
520
+ result.add(Boolean.valueOf(blueConicClient.hasSegment(segmentId)));
521
+ }
522
+
523
+ callback.invoke(result);
524
+ }
525
+
526
+ // MARK: REGISTERS
527
+ /**
528
+ * Create Event.
529
+ * @param eventName The name of the event
530
+ * @param readableMap The readable map retrieved from React native
531
+ */
532
+ @ReactMethod
533
+ public void createEvent(@Nonnull String eventName, ReadableMap readableMap) {
534
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
535
+ final Map<String, Object> properties = readableMap.toHashMap();
536
+
537
+ if (blueConicClient != null) {
538
+ blueConicClient.createEventWithData(eventName, properties);
539
+ }
540
+ }
541
+
542
+ /**
543
+ * Create Event.
544
+ * @param eventName The name of the event
545
+ * @param readableMap The readable map retrieved from React native
546
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
547
+ * Native Modules to pass values back to the JavaScript.
548
+ */
549
+ @ReactMethod
550
+ public void createEventSync(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Promise promise) {
551
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
552
+ final Map<String, Object> properties = readableMap.toHashMap();
553
+
554
+ if (blueConicClient != null) {
555
+ blueConicClient.createEventWithData(eventName, properties, new Runnable() {
556
+ @Override
557
+ public void run() {
558
+ promise.resolve(Arguments.createArray());
559
+ }
560
+ });
561
+ return;
562
+ }
563
+
564
+ promise.resolve(Arguments.createArray());
565
+ }
566
+
567
+ /**
568
+ * Create Event.
569
+ * @param eventName The name of the event
570
+ * @param readableMap The readable map retrieved from React native
571
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
572
+ * to pass values back to the JavaScript.
573
+ */
574
+ @ReactMethod
575
+ public void createEventSyncWithCallback(@Nonnull String eventName, ReadableMap readableMap, @Nonnull final Callback callback) {
576
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
577
+ final Map<String, Object> properties = readableMap.toHashMap();
578
+
579
+ if (blueConicClient != null) {
580
+ blueConicClient.createEventWithData(eventName, properties, new Runnable() {
581
+ @Override
582
+ public void run() {
583
+ callback.invoke(Arguments.createArray());
584
+ }
585
+ });
586
+ return;
587
+ }
588
+
589
+ callback.invoke(Arguments.createArray());
590
+ }
591
+
592
+
593
+ /**
594
+ * Update sync the BlueConic Profile
595
+ */
596
+ @ReactMethod
597
+ public void updateProfile() {
598
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
599
+
600
+ if (blueConicClient != null) {
601
+ blueConicClient.updateProfile();
602
+ }
603
+ }
604
+
605
+ /**
606
+ * Update sync the BlueConic Profile
607
+ * @param promise The promise to handle the obtained value. Promises are necessary in Native Modules
608
+ * Native Modules to pass values back to the JavaScript.
609
+ */
610
+ @ReactMethod
611
+ public void updateProfileSync(@Nonnull final Promise promise) {
612
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
613
+
614
+ if (blueConicClient != null) {
615
+ blueConicClient.updateProfile(new Runnable() {
616
+ @Override
617
+ public void run() {
618
+ promise.resolve(Arguments.createArray());
619
+ }
620
+ });
621
+
622
+ return;
623
+ }
624
+
625
+ promise.resolve(Arguments.createArray());
626
+ }
627
+
628
+ /**
629
+ * Update sync the BlueConic Profile
630
+ * @param callback The Callback function to handle the obtained values. Callbacks are necessary in Native Modules
631
+ * to pass values back to the JavaScript.
632
+ */
633
+ @ReactMethod
634
+ public void updateProfileSyncWithCallback(@Nonnull final Callback callback) {
635
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
636
+
637
+ if (blueConicClient != null) {
638
+ blueConicClient.updateProfile(new Runnable() {
639
+ @Override
640
+ public void run() {
641
+ callback.invoke(Arguments.createArray());
642
+ }
643
+ });
644
+
645
+ return;
646
+ }
647
+
648
+ callback.invoke(Arguments.createArray());
649
+ }
650
+
651
+ /**
652
+ * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
653
+ * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
654
+ * @param screenName The name of the screen.
655
+ */
656
+ @ReactMethod
657
+ public void registerPageView(@Nonnull String screenName) {
658
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
659
+ if (blueConicClient != null) {
660
+ // blueConicClient instance must have an activity or application
661
+ final Map<String, String> properties = new HashMap<>();
662
+ properties.put("screenName", screenName);
663
+ Activity activity = getCurrentActivity();
664
+ if (activity == null) {
665
+ activity = new Activity();
666
+ }
667
+
668
+ blueConicClient.createEvent("PAGEVIEW", properties, activity);
669
+ } else {
670
+ Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
671
+ }
672
+ }
673
+
674
+ /**
675
+ * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
676
+ * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
677
+ * @param screenName The name of the screen.
678
+ */
679
+ @ReactMethod
680
+ public void registerPageViewSync(@Nonnull String screenName, @Nonnull final Promise promise) {
681
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
682
+ if (blueConicClient != null) {
683
+ // blueConicClient instance must have an activity or application
684
+ final Map<String, String> properties = new HashMap<>();
685
+ properties.put("screenName", screenName);
686
+ Activity activity = getCurrentActivity();
687
+ if (activity == null) {
688
+ activity = new Activity();
689
+ }
690
+
691
+ blueConicClient.createEvent("PAGEVIEW", properties, activity, new Runnable() {
692
+ @Override
693
+ public void run() {
694
+ promise.resolve(Arguments.createArray());
695
+ }
696
+ });
697
+ } else {
698
+ Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
699
+ promise.resolve(Arguments.createArray());
700
+ }
701
+ }
702
+
703
+ /**
704
+ * Calls the createEvent method of the BlueConicClient to register a PAGEVIEW event. This must be called on every
705
+ * screen change as it triggers the BlueConic SDK to load all plugins (i.e. listeners, dialogues) for the screen.
706
+ * @param screenName The name of the screen.
707
+ */
708
+ @ReactMethod
709
+ public void registerPageViewSyncCallback(@Nonnull String screenName, @Nonnull final Callback callback) {
710
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
711
+ if (blueConicClient != null) {
712
+ // blueConicClient instance must have an activity or application
713
+ final Map<String, String> properties = new HashMap<>();
714
+ properties.put("screenName", screenName);
715
+ Activity activity = getCurrentActivity();
716
+ if (activity == null) {
717
+ activity = new Activity();
718
+ }
719
+
720
+ blueConicClient.createEvent("PAGEVIEW", properties, activity, new Runnable() {
721
+ @Override
722
+ public void run() {
723
+ callback.invoke(Arguments.createArray());
724
+ }
725
+ });
726
+ } else {
727
+ Log.e("BlueConic", "Unable to register a PAGEVIEW-event: Activity not available.");
728
+ callback.invoke(Arguments.createArray());
729
+ }
730
+ }
731
+
732
+ /**
733
+ * Creates a ClickEvent for the given selector and publishes the event to BlueConic using the EventManager.
734
+ * @param selector The selector to identify the clicked component.
735
+ */
736
+ @ReactMethod
737
+ public void registerClickEvent(@Nonnull String selector) {
738
+ getBlueConicEventManagerInstance().publish(new ClickEvent(selector));
739
+ }
740
+
741
+ /**
742
+ * Creates a ClickEvent for the given selector and values, and publishes the event using the EventManager.
743
+ * @param selector The selector to identify the clicked component.
744
+ * @param values The values to pass to BlueConic as context of the event.
745
+ */
746
+ @ReactMethod
747
+ public void registerClickEventWithContext(@Nonnull String selector, @Nonnull ReadableArray values) {
748
+ getBlueConicEventManagerInstance().publish(new ClickEvent(selector, Arguments.toList(values)));
749
+ }
750
+
751
+ /**
752
+ * Creates an UpdateValuesEvent for the given selector and value, and publishes the event using the EventManager.
753
+ * @param selector The selector to identify the component with updated values.
754
+ * @param value The value to be passed on to BlueConic.
755
+ */
756
+ @ReactMethod
757
+ public void registerUpdateValuesEvent(@Nonnull String selector, @Nonnull String value) {
758
+ UpdateValuesEvent event = new UpdateValuesEvent(selector, Collections.singletonList(value));
759
+ getBlueConicEventManagerInstance().publish(event);
760
+ }
761
+
762
+ /**
763
+ * Creates an AdvancedEvent with the given name and values, and publishes the event using the EventManager.
764
+ * @param name The name to identify the event.
765
+ * @param values The values to pass to BlueConic as context of the event.
766
+ */
767
+ @ReactMethod
768
+ public void registerAdvancedEvent(@Nonnull String name, @Nonnull ReadableArray values) {
769
+ AdvancedEvent event = new AdvancedEvent(name, Arguments.toList(values));
770
+ getBlueConicEventManagerInstance().publish(event);
771
+ }
772
+
773
+
774
+
775
+ /**
776
+ * Destroys all active BlueConic plugins (i.e. instances of listeners and dialogues). This method must be called
777
+ * in the onPause of an activity if the app targets Android API versions before API 14. It should also be called if
778
+ * one switches screens in the app without calling the onPause of the previous Activity.
779
+ *
780
+ */
781
+ @ReactMethod
782
+ public void destroyPlugins() {
783
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
784
+ if (blueConicClient != null) {
785
+ blueConicClient.destroyPlugins();
786
+ }
787
+ }
788
+
789
+ /**
790
+ * Sends an event to the BlueConic server, indicating that a certain interaction was viewed, clicked, or converted for.
791
+ * @param eventType The event type to register for the interaction. Possible events are "VIEW", "CLICK" and "CONVERSION".
792
+ * @param interactionId The unique identifier of the interaction.
793
+ */
794
+ @ReactMethod
795
+ public void registerDialogueEvent(@Nonnull String eventType, @Nonnull String interactionId) {
796
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
797
+ if (blueConicClient != null) {
798
+ final Map<String, String> interactionIdMap = new HashMap<>();
799
+ interactionIdMap.put("interactionId", interactionId);
800
+ blueConicClient.createEvent(eventType, interactionIdMap);
801
+ }
802
+ }
803
+
804
+
805
+ /**
806
+ * Returns an instance of the BlueConicClient
807
+ * @return BlueConicClient
808
+ */
809
+ private BlueConicClient getBlueConicClientInstance() {
810
+ // Retrieve current Activity from ReactContextBaseJavaModule
811
+ final Activity currentActivity = getCurrentActivity();
812
+ if (currentActivity != null) {
813
+ // Activity found and return a BlueConicClient instance
814
+ return BlueConicClientFactory.getInstance(currentActivity);
815
+ }
816
+
817
+ // Current Activity is not set yet, try using BaseContext as a safe-cast to Application
818
+ if (this.reactContext.getApplicationContext() instanceof Application) {
819
+ // Cast BaseContext to an Application
820
+ final Application application = (Application) this.reactContext.getApplicationContext();
821
+ return BlueConicClientFactory.getInstance(application);
822
+ }
823
+
824
+ return null;
825
+ }
826
+
827
+ /**
828
+ * Returns an instance of the BlueConicEventManager
829
+ * @return BlueConicClient
830
+ */
831
+ private BlueConicEventManager getBlueConicEventManagerInstance() {
832
+ return BlueConicEventFactory.getInstance();
833
+ }
834
+
835
+ private WritableArray getFormattedSegments() {
836
+ final WritableArray result = new WritableNativeArray();
837
+ final BlueConicClient blueConicClient = getBlueConicClientInstance();
838
+
839
+ if (blueConicClient == null) {
840
+ return result;
841
+ }
842
+ final Collection<BlueConicClient.Segment> segments = blueConicClient.getSegments();
843
+
844
+ for (BlueConicClient.Segment segment : segments) {
845
+ final WritableMap item = new WritableNativeMap();
846
+ item.putString("id", segment.getId());
847
+ item.putString("name", segment.getName());
848
+ result.pushMap(item);
849
+ }
850
+
851
+ return result;
852
+ }
853
+
854
+ /**
855
+ * Static method that is called by the BlueConicInteraction when it receives the parameters of the dialogue,
856
+ * and when the dialogue is destroyed by the BlueConic SDK. An event is published to which the JavaScript of the
857
+ * app should subscribe.
858
+ * @param properties The properties of the dialogues as received from BlueConic.
859
+ * @param eventName The name of the event to be published.
860
+ */
861
+ static void publishDialogueEvent(@Nonnull Map<String, Object> properties, String eventName) {
862
+ WritableMap map = Arguments.makeNativeMap(properties);
863
+
864
+ if (helper != null) {
865
+ helper
866
+ .getReactContext()
867
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
868
+ .emit(eventName, map);
869
+ }
870
+ }
858
871
  }