forked from CleverTap/clevertap-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
786 lines (695 loc) · 30.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
import { DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
const CleverTapReact = NativeModules.CleverTapReact;
const EventEmitter = NativeModules.CleverTapReactEventEmitter ? new NativeEventEmitter(NativeModules.CleverTapReactEventEmitter) : DeviceEventEmitter;
function defaultCallback(method, err, res) {
if (err) {
console.log('CleverTap ' + method + ' default callback error', err);
} else {
console.log('CleverTap ' + method + ' default callback result', res);
}
}
/**
* Calls a CleverTap method with a default callback if necessary
* @param {string} method - the CleverTap method name as a string
* @param {array} args - The method args
* @param {function(err, res)} callback - callback
*/
function callWithCallback(method, args, callback) {
if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') {
callback = (err, res) => {
defaultCallback(method, err, res);
};
}
if (args == null) {
args = [];
}
args.push(callback);
CleverTapReact[method].apply(this, args);
}
var CleverTap = {
CleverTapProfileDidInitialize: CleverTapReact.CleverTapProfileDidInitialize,
CleverTapProfileSync: CleverTapReact.CleverTapProfileSync,
CleverTapInAppNotificationDismissed: CleverTapReact.CleverTapInAppNotificationDismissed,
FCM: CleverTapReact.FCM,
XPS: CleverTapReact.XPS,
BPS: CleverTapReact.BPS,
HPS: CleverTapReact.HPS,
CleverTapInboxDidInitialize: CleverTapReact.CleverTapInboxDidInitialize,
CleverTapInboxMessagesDidUpdate: CleverTapReact.CleverTapInboxMessagesDidUpdate,
CleverTapInboxMessageButtonTapped: CleverTapReact.CleverTapInboxMessageButtonTapped,
CleverTapDisplayUnitsLoaded: CleverTapReact.CleverTapDisplayUnitsLoaded,
CleverTapInAppNotificationButtonTapped: CleverTapReact.CleverTapInAppNotificationButtonTapped,
CleverTapFeatureFlagsDidUpdate: CleverTapReact.CleverTapFeatureFlagsDidUpdate,
CleverTapProductConfigDidInitialize: CleverTapReact.CleverTapProductConfigDidInitialize,
CleverTapProductConfigDidFetch: CleverTapReact.CleverTapProductConfigDidFetch,
CleverTapProductConfigDidActivate: CleverTapReact.CleverTapProductConfigDidActivate,
CleverTapPushNotificationClicked: CleverTapReact.CleverTapPushNotificationClicked,
/**
* Add a CleverTap event listener
* supported events are CleverTap.CleverTapProfileDidInitialize, CleverTap.CleverTapProfileSync,CleverTap.CleverTapOnInboxButtonClick
* ,CleverTap.CleverTapOnInAppButtonClick,CleverTap.CleverTapOnDisplayUnitsLoaded and CleverTap.CleverTapInAppNotificationDismissed
* @param {string} eventName - the CleverTap event name
* @param {function(event)} your event handler
*/
addListener: function (eventName, handler) {
if (EventEmitter) {
EventEmitter.addListener(eventName, handler);
}
},
/**
* Removes all of the registered listeners for given eventName.
*
* @param {string} eventName - name of the event whose registered listeners to remove
*/
removeListener: function (eventName) {
if (EventEmitter) {
EventEmitter.removeAllListeners(eventName);
}
},
/**
* Deprecated - Since version 0.5.0. Use removeListener(eventName) instead
* Remove all event listeners
*/
removeListeners: function () {
if (DeviceEventEmitter) {
DeviceEventEmitter.removeAllListeners();
}
},
/**
* If an application is launched from a push notification click, returns the CleverTap deep link included in the push notification
* @param {function(err, res)} callback that return the url as string in res or a string error in err
*/
getInitialUrl: function (callback) {
callWithCallback('getInitialUrl', null, callback);
},
/**
* Registers the application to receive push notifications
* only necessary for iOS.
*/
registerForPush: function () {
CleverTapReact.registerForPush();
},
/**
* Manually set the push token on the CleverTap user profile
* @param {string} token - the device token
* @param {string} type - for Android only, specifying the type of push service token. Values can be CleverTap.FCM for Firebase or CleverTap.XPS for Xiaomi or CleverTap.BPS for Baidu or CleverTap.HPS for Huawei
*/
setPushToken: function (token, type) {
CleverTapReact.setPushTokenAsString(token, type);
},
/**
* Method to create Notification Channels in Android O
* @param {string} channelId - A String for setting the id of the notification channel
* @param {string} channelName - A String for setting the name of the notification channel
* @param {string} channelDescription - A String for setting the description of the notification channel
* @param {int} importance - An Integer value setting the importance of the notifications sent in this channel
* @param {boolean} showBadge - A boolean value as to whether this channel shows a badge
*/
createNotificationChannel: function (channelId, channelName, channelDescription, importance, showBadge) {
CleverTapReact.createNotificationChannel(channelId, channelName, channelDescription, importance, showBadge);
},
/**
* Method to create Notification Channels in Android O
* @param {string} channelId - A String for setting the id of the notification channel
* @param {string} channelName - A String for setting the name of the notification channel
* @param {string} channelDescription - A String for setting the description of the notification channel
* @param {int} importance - An Integer value setting the importance of the notifications sent in this channel
* @param {boolean} showBadge - A boolean value as to whether this channel shows a badge
* @param {string} sound - A String for setting the custom sound of the notification channel
*/
createNotificationChannelWithSound: function (channelId, channelName, channelDescription, importance, showBadge, sound) {
CleverTapReact.createNotificationChannelWithSound(channelId, channelName, channelDescription, importance, showBadge, sound);
},
/**
* Method to create Notification Channels in Android O
* @param {string} channelId - A String for setting the id of the notification channel
* @param {string} channelName - A String for setting the name of the notification channel
* @param {string} channelDescription - A String for setting the description of the notification channel
* @param {int} importance - An Integer value setting the importance of the notifications sent in this channel
* @param {string} groupId - A String for setting the notification channel as a part of a notification group
* @param {boolean} showBadge - A boolean value as to whether this channel shows a badge
*/
createNotificationChannelWithGroupId: function (channelId, channelName, channelDescription, importance, groupId, showBadge) {
CleverTapReact.createNotificationChannelWithGroupId(channelId, channelName, channelDescription, importance, groupId, showBadge);
},
/**
* Method to create Notification Channels in Android O
* @param {string} channelId - A String for setting the id of the notification channel
* @param {string} channelName - A String for setting the name of the notification channel
* @param {string} channelDescription - A String for setting the description of the notification channel
* @param {int} importance - An Integer value setting the importance of the notifications sent in this channel
* @param {string} groupId - A String for setting the notification channel as a part of a notification group
* @param {boolean} showBadge - A boolean value as to whether this channel shows a badge
* @param {string} sound - A String for setting the custom sound of the notification channel
*/
createNotificationChannelWithGroupIdAndSound: function (channelId, channelName, channelDescription, importance, groupId, showBadge, sound) {
CleverTapReact.createNotificationChannelWithGroupIdAndSound(channelId, channelName, channelDescription, importance, groupId, showBadge, sound);
},
/**
* Method to create Notification Channel Groups in Android O
* @param {string} groupId - A String for setting the id of the notification channel group
* @param {string} groupName - A String for setting the name of the notification channel group
*/
createNotificationChannelGroup: function (groupId, groupName) {
CleverTapReact.createNotificationChannelGroup(groupId, groupName);
},
/**
* Method to delete Notification Channels in Android O
* @param {string} channelId - A String for setting the id of the notification channel
*/
deleteNotificationChannel: function (channelId) {
CleverTapReact.deleteNotificationChannel(channelId);
},
/**
* Method to delete Notification Channel Groups in Android O
* @param {string} groupId - A String for setting the id of the notification channel group
*/
deleteNotificationChannelGroup: function (groupId) {
CleverTapReact.deleteNotificationChannelGroup(groupId);
},
/**
* Method to show the App Inbox
* @param {object} extras - key-value data from RemoteMessage.getData(). keys and values are strings
*/
createNotification: function (extras) {
CleverTapReact.createNotification(extras);
},
/**
* Enables tracking opt out for the currently active user.
* @param {boolean} value - A boolean for enabling or disabling tracking for current user
*/
setOptOut: function (value) {
CleverTapReact.setOptOut(value);
},
/**
* Sets the CleverTap SDK to offline mode
* @param {boolean} value - A boolean for enabling or disabling sending events for current user
*/
setOffline: function (value) {
CleverTapReact.setOffline(value);
},
/**
* Enables the reporting of device network related information, including IP address. This reporting is disabled by default.
* @param {boolean} - A boolean for enabling or disabling device network related information to be sent to CleverTap
*/
enableDeviceNetworkInfoReporting: function (value) {
CleverTapReact.enableDeviceNetworkInfoReporting(value);
},
/**
* Enables the personalization API. Call this prior to using the profile/event API getters
*/
enablePersonalization: function () {
CleverTapReact.enablePersonalization();
},
/**
* Disables the personalization API.
*/
disablePersonalization: function () {
CleverTapReact.disablePersonalization();
},
/**
* Record a Screen View
* @param {string} screenName - the name of the screen
*/
recordScreenView: function (screenName) {
CleverTapReact.recordScreenView(screenName);
},
/**
* Record an event with optional event properties
* @param {string} eventName - the name of the event
* @param {object} props - the key-value properties of the event.
* keys are strings and values can be string, number or boolean.
*/
recordEvent: function (eventName, props) {
convertDateToEpochInProperties(props);
CleverTapReact.recordEvent(eventName, props);
},
/**
* Record the special Charged event
* @param {object} details - the key-value properties for the transaction.
* @param {array<object>} items - an array of objects containing the key-value data for the items that make up the transaction.
*/
recordChargedEvent: function (details, items) {
convertDateToEpochInProperties(details);
if (Array.isArray(items) && items.length) {
items.forEach(value => {
convertDateToEpochInProperties(value);
});
}
CleverTapReact.recordChargedEvent(details, items);
},
/**
* Get the time of the first occurrence of an event
* @param {string} eventName - the name of the event
* @param {function(err, res)} callback that returns a res of epoch seconds or -1
*/
eventGetFirstTime: function (eventName, callback) {
callWithCallback('eventGetFirstTime', [eventName], callback);
},
/**
* Get the time of the most recent occurrence of an event
* @param {string} eventName - the name of the event
* @param {function(err, res)} callback that returns a res of epoch seconds or -1
*/
eventGetLastTime: function (eventName, callback) {
callWithCallback('eventGetLastTime', [eventName], callback);
},
/**
* Get the number of occurrences of an event
* @param {string} eventName - the name of the event
* @param {function(err, res)} callback that returns a res of int
*/
eventGetOccurrences: function (eventName, callback) {
callWithCallback('eventGetOccurrences', [eventName], callback);
},
/**
* Get the summary details of an event
* @param {string} eventName - the name of the event
* @param {function(err, res)} callback that returns a res of object {"eventName": <string>, "firstTime":<epoch seconds>, "lastTime": <epoch seconds>, "count": <int>} or empty object
*/
eventGetDetail: function (eventName, callback) {
callWithCallback('eventGetDetail', [eventName], callback);
},
/**
* Get the user's event history
* @param {function(err, res)} callback that returns a res of object {"eventName1":<event1 details object>, "eventName2":<event2 details object>}
*/
getEventHistory: function (callback) {
callWithCallback('getEventHistory', null, callback);
},
/**
* Set the user's location as a latitude,longitude coordinate
* @param {float} latitude
* @param {float} longitude
*/
setLocation: function (latitude, longitude) {
CleverTapReact.setLocation(latitude, longitude);
},
/**
* Deprecated - Since version 0.6.0. Use getCleverTapID(callback) instead
* Get a unique CleverTap identifier suitable for use with install attribution providers
* @param {function(err, res)} callback that returns a string res
*/
profileGetCleverTapAttributionIdentifier: function (callback) {
callWithCallback('profileGetCleverTapAttributionIdentifier', null, callback);
},
/**
* Deprecated - Since version 0.6.0. Use getCleverTapID(callback) instead
* Get the user profile's CleverTap identifier value
* @param {function(err, res)} callback that returns a string res
*/
profileGetCleverTapID: function (callback) {
callWithCallback('profileGetCleverTapID', null, callback);
},
/**
* Creates a separate and distinct user profile identified by one or more of Identity, Email, FBID or GPID values, and populated with the key-values included in the profile dictionary.
* If your app is used by multiple users, you can use this method to assign them each a unique profile to track them separately.
* If instead you wish to assign multiple Identity, Email, FBID and/or GPID values to the same user profile, use profileSet rather than this method.
* If none of Identity, Email, FBID or GPID is included in the profile object, all properties values will be associated with the current user profile.
* When initially installed on this device, your app is assigned an "anonymous" profile.
* The first time you identify a user on this device (whether via onUserLogin or profileSet), the "anonymous" history on the device will be associated with the newly identified user.
* Then, use this method to switch between subsequent separate identified users.
* Please note that switching from one identified user to another is a costly operation
* in that the current session for the previous user is automatically closed
* and data relating to the old user removed, and a new session is started
* for the new user and data for that user refreshed via a network call to CleverTap.
* In addition, any global frequency caps are reset as part of the switch.
* @param {object} profile - key-value profile properties. keys are strings and values can be string, number or boolean.
*/
onUserLogin: function (profile) {
convertDateToEpochInProperties(profile);
CleverTapReact.onUserLogin(profile);
},
/**
* Set key-value properties on a user profile
* @param {object} profile - key-value profile properties. keys are strings and values can be string, number or boolean.
*/
profileSet: function (profile) {
convertDateToEpochInProperties(profile);
CleverTapReact.profileSet(profile);
},
/**
* Get the value of a profile property
* @param {string} the property key
* @param {function(err, res)} callback that returns a res of the property value or null
*/
profileGetProperty: function (key, callback) {
callWithCallback('profileGetProperty', [key], callback);
},
/**
* Remove a key-value from the user profile
* @param {string} the key to remove
*/
profileRemoveValueForKey: function (key) {
CleverTapReact.profileRemoveValueForKey(key);
},
/**
* Set an array of strings as a multi-value user profile property
* @param {array} an array of string values
* @param {string} the property key
*/
profileSetMultiValuesForKey: function (values, key) {
CleverTapReact.profileSetMultiValues(values, key);
},
/**
* Add a string value to a multi-value user profile property
* @param {string} value
* @param {string} the property key
*/
profileAddMultiValueForKey: function (value, key) {
CleverTapReact.profileAddMultiValue(value, key);
},
/**
* Add an array of strings to a multi-value user profile property
* @param {array} an array of string values
* @param {string} the property key
*/
profileAddMultiValuesForKey: function (values, key) {
CleverTapReact.profileAddMultiValues(values, key);
},
/**
* Remove a string value from a multi-value user profile property
* @param {string} value
* @param {string} the property key
*/
profileRemoveMultiValueForKey: function (value, key) {
CleverTapReact.profileRemoveMultiValue(value, key);
},
/**
* Remove an array of strings from a multi-value user profile property
* @param {array} an array of string values
* @param {string} the property key
*/
profileRemoveMultiValuesForKey: function (values, key) {
CleverTapReact.profileRemoveMultiValues(values, key);
},
/**
* This method is used to increment the given value
*
* @param value {Number} can be int,double or float only (NaN,Infinity etc not supported)
* @param key {string} profile property
*/
profileIncrementValueForKey: function (value, key) {
CleverTapReact.profileIncrementValueForKey(value, key);
},
/**
* This method is used to decrement the given value
*
* @param value {Number} can be int,double or float only (NaN,Infinity etc not supported)
* @param key {string} profile property
*/
profileDecrementValueForKey: function (value, key) {
CleverTapReact.profileDecrementValueForKey(value, key);
},
/**
* Manually track the utm app install referrer
* @param {string} the utm referrer source
* @param {string} the utm referrer medium
* @param {string} the utm referrer campaign
*/
pushInstallReferrer: function (source, medium, campaign) {
CleverTapReact.pushInstallReferrer(source, medium, campaign);
},
/**
* Get the elapsed time of the current user session
* @param {function(err, res)} callback that returns a res of int seconds
*/
sessionGetTimeElapsed: function (callback) {
callWithCallback('sessionGetTimeElapsed', null, callback);
},
/**
* Get the total number of vists by the user
* @param {function(err, res)} callback that returns a res of int
*/
sessionGetTotalVisits: function (callback) {
callWithCallback('sessionGetTotalVisits', null, callback);
},
/**
* Get the number of screens viewed by the user during the session
* @param {function(err, res)} callback that returns a res of int
*/
sessionGetScreenCount: function (callback) {
callWithCallback('sessionGetScreenCount', null, callback);
},
/**
* Get the most recent previous visit time of the user
* @param {function(err, res)} callback that returns a res of epoch seconds or -1
*/
sessionGetPreviousVisitTime: function (callback) {
callWithCallback('sessionGetPreviousVisitTime', null, callback);
},
/**
* Get the utm referrer info for the current session
* @param {function(err, res)} callback that returns a res of object {"source": <string>, "medium": <string>, "campaign": <string>} or empty object
*/
sessionGetUTMDetails: function (callback) {
callWithCallback('sessionGetUTMDetails', null, callback);
},
/**
* Method to initalize the App Inbox
*/
initializeInbox: function () {
CleverTapReact.initializeInbox();
},
/**
* Method to show the App Inbox
* @param {object} styleConfig - key-value profile properties. keys and values are strings
*/
showInbox: function (styleConfig) {
CleverTapReact.showInbox(styleConfig);
},
/**
* Get the total number of Inbox Messages
* @param {function(err, res)} callback that returns a res of count of inbox messages or -1
*/
getInboxMessageCount: function (callback) {
callWithCallback('getInboxMessageCount', null, callback);
},
/**
* Get the total number of Unread Inbox Messages
* @param {function(err, res)} callback that returns a res of count of unread inbox messages or -1
*/
getInboxMessageUnreadCount: function (callback) {
callWithCallback('getInboxMessageUnreadCount', null, callback);
},
/**
* Get All inbox messages
* @param {function(err, res)} callback that returns a list of json string representation of CTInboxMessage
*/
getAllInboxMessages: function (callback) {
callWithCallback('getAllInboxMessages', null, callback);
},
/**
* Get All unread inbox messages
* @param {function(err, res)} callback that returns a list of json string representation of CTInboxMessage
*/
getUnreadInboxMessages: function (callback) {
callWithCallback('getUnreadInboxMessages', null, callback);
},
/**
* Get Inbox Message that belongs to the given message id
* @param {function(err, res)} callback that returns json string representation of CTInboxMessage
*/
getInboxMessageForId: function (messageId, callback) {
callWithCallback('getInboxMessageForId', [messageId], callback);
},
/**
* Deletes Inbox Message that belongs to the given message id
* @param {string} message id of inbox message of type CTInboxMessage
*/
deleteInboxMessageForId: function (messageId) {
CleverTapReact.deleteInboxMessageForId(messageId);
},
/**
* Marks Inbox Message that belongs to the given message id as read
* @param {string} message id of inbox message of type CTInboxMessage
*/
markReadInboxMessageForId: function (messageId) {
CleverTapReact.markReadInboxMessageForId(messageId);
},
/**
* Pushes the Notification Clicked event for App Inbox to CleverTap.
* @param {string} message id of inbox message of type CTInboxMessage
*/
pushInboxNotificationClickedEventForId: function (messageId) {
CleverTapReact.pushInboxNotificationClickedEventForId(messageId);
},
/**
* Pushes the Notification Viewed event for App Inbox to CleverTap.
* @param {string} message id of inbox message of type CTInboxMessage
*/
pushInboxNotificationViewedEventForId: function (messageId) {
CleverTapReact.pushInboxNotificationViewedEventForId(messageId);
},
/**
* Get all display units
* @param {function(err, res)} callback that returns a list of json string representation of CleverTapDisplayUnit
*/
getAllDisplayUnits: function (callback) {
callWithCallback('getAllDisplayUnits', null, callback);
},
/**
* Get display unit for given unitID.
* @param {string} unit id of display unit of type CleverTapDisplayUnit
* @param {function(err, res)} callback that returns a json string representation of CleverTapDisplayUnit
*/
getDisplayUnitForId: function (unitID, callback) {
callWithCallback('getDisplayUnitForId', [unitID], callback);
},
/**
* Raises the Display Unit Viewed event
* @param {string} unit id of display unit of type CleverTapDisplayUnit
*/
pushDisplayUnitViewedEventForID: function (unitID) {
CleverTapReact.pushDisplayUnitViewedEventForID(unitID);
},
/**
* Raises the Display Unit Clicked event
* @param {string} unit id of display unit of type CleverTapDisplayUnit
*/
pushDisplayUnitClickedEventForID: function (unitID) {
CleverTapReact.pushDisplayUnitClickedEventForID(unitID);
},
/**
* Sets default product config params using the given object.
* @param {object} productConfigMap - key-value product config properties. keys are strings and values can be string, double, integer, boolean or json in string format.
*/
setDefaultsMap: function (productConfigMap) {
CleverTapReact.setDefaultsMap(productConfigMap);
},
/**
* Starts fetching product configs, adhering to the default minimum fetch interval.
*/
fetch: function () {
CleverTapReact.fetch();
},
/**
* Starts fetching product configs, adhering to the specified minimum fetch interval in seconds.
* @param {int} intervalInSecs - minimum fetch interval in seconds.
*/
fetchWithMinimumIntervalInSeconds: function (intervalInSecs) {
CleverTapReact.fetchWithMinimumFetchIntervalInSeconds(intervalInSecs);
},
/**
* Activates the most recently fetched product configs, so that the fetched key value pairs take effect.
*/
activate: function () {
CleverTapReact.activate();
},
/**
* Asynchronously fetches and then activates the fetched product configs.
*/
fetchAndActivate: function () {
CleverTapReact.fetchAndActivate();
},
/**
* Sets the minimum interval in seconds between successive fetch calls.
* @param {int} intervalInSecs - interval in seconds between successive fetch calls.
*/
setMinimumFetchIntervalInSeconds: function (intervalInSecs) {
CleverTapReact.setMinimumFetchIntervalInSeconds(intervalInSecs);
},
/**
* Deletes all activated, fetched and defaults configs as well as all Product Config settings.
*/
resetProductConfig: function () {
CleverTapReact.reset();
},
/**
* Returns the product config parameter value for the given key as a String.
* @param {string} the property key
* @param {function(err, res)} callback that returns a value of type string if present else blank
*/
getProductConfigString: function (key, callback) {
callWithCallback('getString', [key], callback);
},
/**
* Returns the product config parameter value for the given key as a boolean.
* @param {string} the property key
* @param {function(err, res)} callback that returns a value of type boolean if present else false
*/
getProductConfigBoolean: function (key, callback) {
callWithCallback('getBoolean', [key], callback);
},
/**
* Returns the product config parameter value for the given key as a number.
* @param {string} the property key
* @param {function(err, res)} callback that returns a value of type number if present else 0
*/
getNumber: function (key, callback) {
callWithCallback('getDouble', [key], callback);
},
/**
* Returns the last fetched timestamp in millis.
* @param {function(err, res)} callback that returns value of timestamp in millis as a string.
*/
getLastFetchTimeStampInMillis: function (callback) {
callWithCallback('getLastFetchTimeStampInMillis', null, callback);
},
/**
* Getter to return the feature flag configured at the dashboard
* @param {string} key of the feature flag
* @param {string} default value of the key, in case we don't find any feature flag with the key.
* @param {function(err, res)} callback that returns a feature flag value of type boolean if present else provided default value
*/
getFeatureFlag: function (name, defaultValue, callback) {
callWithCallback('getFeatureFlag', [name, defaultValue], callback);
},
/**
* Returns a unique identifier through callback by which CleverTap identifies this user
*
* @param {function(err, res)} non-null callback to retrieve identifier
*/
getCleverTapID: function (callback) {
callWithCallback('getCleverTapID', null, callback);
},
/**
* Suspends display of InApp Notifications.
* The InApp Notifications are queued once this method is called
* and will be displayed once resumeInAppNotifications() is called.
*/
suspendInAppNotifications: function () {
CleverTapReact.suspendInAppNotifications();
},
/**
* Suspends the display of InApp Notifications and discards any new InApp Notifications to be shown
* after this method is called.
* The InApp Notifications will be displayed only once resumeInAppNotifications() is called.
*/
discardInAppNotifications: function () {
CleverTapReact.discardInAppNotifications();
},
/**
* Resumes display of InApp Notifications.
*
* If suspendInAppNotifications() was called previously, calling this method will instantly show
* all queued InApp Notifications and also resume InApp Notifications on events raised after this
* method is called.
*
* If discardInAppNotifications() was called previously, calling this method will only resume
* InApp Notifications on events raised after this method is called.
*/
resumeInAppNotifications: function () {
CleverTapReact.resumeInAppNotifications();
},
/**
* Set the SDK debug level
* @param {int} 0 = off, 1 = on
*/
setDebugLevel: function (level) {
CleverTapReact.setDebugLevel(level);
}
};
function convertDateToEpochInProperties(map) {
/**
* Conversion of date object in suitable CleverTap format(Epoch)
*/
if (map) {
for (let [key, value] of Object.entries(map)) {
if (Object.prototype.toString.call(value) === '[object Date]') {
map[key] = "$D_" + Math.floor(value.getTime() / 1000);
}
}
}
};
module.exports = CleverTap;