reactnative-plugin-appice 1.7.26 → 1.7.28

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 (107) hide show
  1. package/README.md +37 -37
  2. package/android/README.md +14 -14
  3. package/android/build.gradle +158 -158
  4. package/android/gitignore +47 -47
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  6. package/android/gradlew +234 -234
  7. package/android/local.properties +8 -8
  8. package/android/src/main/AndroidManifest.xml +164 -128
  9. package/android/src/main/java/com/reactlibrary/AppICEUtils.java +274 -274
  10. package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +778 -778
  11. package/android/src/main/java/com/reactlibrary/AppIceReactPluginPackage.java +28 -28
  12. package/android/src/main/java/com/reactlibrary/CampaignCampsReceiver.java +56 -56
  13. package/android/src/main/java/com/reactlibrary/EnumConstants.java +282 -282
  14. package/android/src/main/java/com/reactlibrary/NotificationEventService.java +59 -59
  15. package/android/src/main/java/com/reactlibrary/StringConstants.java +24 -24
  16. package/campaign.js +25 -25
  17. package/example/App.js +332 -332
  18. package/example/Gemfile +6 -6
  19. package/example/PageA.tsx +15 -15
  20. package/example/__tests__/App-test.js +14 -14
  21. package/example/ancilliary.js +486 -486
  22. package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
  23. package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
  24. package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
  25. package/example/android/.gradle/7.3.3/gc.properties +0 -0
  26. package/example/android/.gradle/vcs-1/gc.properties +0 -0
  27. package/example/android/app/_BUCK +55 -55
  28. package/example/android/app/build.gradle +320 -320
  29. package/example/android/app/build_defs.bzl +19 -19
  30. package/example/android/app/proguard-rules.pro +10 -10
  31. package/example/android/app/src/debug/AndroidManifest.xml +13 -13
  32. package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +73 -73
  33. package/example/android/app/src/main/AndroidManifest.xml +72 -72
  34. package/example/android/app/src/main/java/com/example/MainActivity.java +48 -48
  35. package/example/android/app/src/main/java/com/example/MainApplication.java +91 -91
  36. package/example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +116 -116
  37. package/example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +36 -36
  38. package/example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -48
  39. package/example/android/app/src/main/jni/Android.mk +48 -48
  40. package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -24
  41. package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -16
  42. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -45
  43. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -38
  44. package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -61
  45. package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -32
  46. package/example/android/app/src/main/jni/OnLoad.cpp +11 -11
  47. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -36
  48. package/example/android/app/src/main/res/values/strings.xml +3 -3
  49. package/example/android/app/src/main/res/values/styles.xml +9 -9
  50. package/example/android/build.gradle +73 -73
  51. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  52. package/example/android/gradle.properties +40 -40
  53. package/example/android/gradlew +234 -234
  54. package/example/android/settings.gradle +11 -11
  55. package/example/app.json +3 -3
  56. package/example/babel.config.js +3 -3
  57. package/example/index.js +9 -9
  58. package/example/ios/Podfile +44 -44
  59. package/example/ios/Podfile.lock +561 -561
  60. package/example/ios/_xcode.env +11 -11
  61. package/example/ios/example/AppDelegate.h +8 -8
  62. package/example/ios/example/AppDelegate.mm +174 -174
  63. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -53
  64. package/example/ios/example/Images.xcassets/Contents.json +6 -6
  65. package/example/ios/example/Info.plist +62 -62
  66. package/example/ios/example/LaunchScreen.storyboard +47 -47
  67. package/example/ios/example/example.entitlements +8 -8
  68. package/example/ios/example/main.m +10 -10
  69. package/example/ios/example.xcodeproj/project.pbxproj +712 -712
  70. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -88
  71. package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -10
  72. package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  73. package/example/ios/exampleTests/Info.plist +24 -24
  74. package/example/ios/exampleTests/exampleTests.m +66 -66
  75. package/example/metro.config.js +17 -17
  76. package/example/package.json +36 -36
  77. package/example/yarn.lock +7176 -7176
  78. package/index.js +590 -590
  79. package/ios/AppICEReactEvent.h +23 -23
  80. package/ios/AppICEReactEvent.m +86 -86
  81. package/ios/AppIceReactPlugin.h +65 -65
  82. package/ios/AppIceReactPlugin.m +683 -683
  83. package/ios/AppIceReactPlugin.xcodeproj/project.pbxproj +364 -364
  84. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
  85. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  86. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  87. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  88. package/ios/AppIceReactPlugin.xcworkspace/contents.xcworkspacedata +10 -10
  89. package/ios/AppIceReactPlugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  90. package/ios/Podfile +10 -10
  91. package/ios/Podfile.lock +3 -3
  92. package/ios/Pods/Manifest.lock +3 -3
  93. package/ios/Pods/Pods.xcodeproj/project.pbxproj +395 -395
  94. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/Pods-AppIceReactPlugin.xcscheme +58 -58
  95. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +18 -18
  96. package/ios/Pods/Pods.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  97. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-Info.plist +26 -26
  98. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.markdown +3 -3
  99. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.plist +29 -29
  100. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-dummy.m +5 -5
  101. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-umbrella.h +16 -16
  102. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.debug.xcconfig +6 -6
  103. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.modulemap +6 -6
  104. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.release.xcconfig +6 -6
  105. package/package.json +9 -6
  106. package/reactnative-plugin-appice.podspec +30 -30
  107. package/android/.idea/workspace.xml +0 -103
package/index.js CHANGED
@@ -1,590 +1,590 @@
1
- import { DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
2
- import { Platform, Component, AppState } from 'react-native';
3
- // import { MMKV } from 'react-native-mmkv'
4
- import AsyncStorage from '@react-native-async-storage/async-storage';
5
- import Campaign from './campaign';
6
-
7
- const AppIceReactPlugin = NativeModules.AppIceReactPlugin;
8
- var eventEmitter;
9
- if (Platform.OS === 'ios') {
10
- eventEmitter = NativeModules.AppICEReactEvent ? new NativeEventEmitter(NativeModules.AppICEReactEvent) : DeviceEventEmitter;
11
- }
12
- else {
13
- eventEmitter = new NativeEventEmitter(NativeModules.AppIceReactPlugin);
14
- }
15
-
16
- // export const appStorage = new MMKV({
17
- // id: 'AppICE-storage',
18
- // })
19
-
20
- const EVENT_KEY = "lastEvent"
21
- const LAST_EVENT_KEY = "event_"
22
-
23
- export const CAMP_ID = AppIceReactPlugin.CAMP_ID;
24
- export const ACTION_URL = AppIceReactPlugin.ACTION_URL;
25
- export const ACTION_TYPE = AppIceReactPlugin.ACTION_TYPE;
26
- export const CUSTOMDATA = AppIceReactPlugin.CUSTOMDATA;
27
-
28
- const CampaignType = {
29
- NATIVE: 'NATIVE',
30
- INAPP: 'INAPP',
31
- PUSH: 'PUSH',
32
- };
33
-
34
-
35
- var AppICEReact = {
36
-
37
- validateIntegration: AppIceReactPlugin.validateIntegration,
38
-
39
- //========================
40
- // PUSH
41
- //========================
42
- AppICEPushNotificationClicked: AppIceReactPlugin.AppICEPushNotificationClicked,
43
-
44
- //==========================
45
- // IN-APP
46
- //==========================
47
- AppICEInAppClicked: AppIceReactPlugin.AppICEInAppClicked,
48
-
49
- //========================
50
- // APP-INBOX
51
- //========================
52
- INBOX_MESSAGE: AppIceReactPlugin.INBOX_MESSAGE,
53
- INBOX_TITLE: AppIceReactPlugin.INBOX_TITLE,
54
- INBOX_MESSAGE_STATUS: AppIceReactPlugin.INBOX_MESSAGE_STATUS,
55
- INBOX_CAMPAIGN_TYPE: AppIceReactPlugin.INBOX_CAMPAIGN_TYPE,
56
- INBOX_MESSAGE_LANGUAGE: AppIceReactPlugin.INBOX_MESSAGE_LANGUAGE,
57
- INBOX_MESSAGE_ID: AppIceReactPlugin.INBOX_MESSAGE_ID,
58
- INBOX_CAMPAIGN_ID: AppIceReactPlugin.INBOX_CAMPAIGN_ID,
59
- INBOX_MESSAGE_ICON: AppIceReactPlugin.INBOX_MESSAGE_ICON,
60
- INBOX_CUSTOM_DATA: AppIceReactPlugin.INBOX_CUSTOM_DATA,
61
- INBOX_MESSAGE_EXPANDED_IMAGE: AppIceReactPlugin.INBOX_MESSAGE_EXPANDED_IMAGE,
62
-
63
-
64
- //=======================
65
- // USER-PROFILE SETTING
66
- //=======================
67
- name: AppIceReactPlugin.APPICE_USER_NAME,
68
- email: AppIceReactPlugin.APPICE_USER_EMAIL,
69
- phone: AppIceReactPlugin.APPICE_USER_PHONE,
70
- age: AppIceReactPlugin.APPICE_USER_AGE,
71
- gender: AppIceReactPlugin.APPICE_USER_GENDER,
72
- educationType: AppIceReactPlugin.APPICE_USER_EDUCATION_TYPE,
73
- employmentType: AppIceReactPlugin.APPICE_USER_EMPLOYMENT_TYPE,
74
- married: AppIceReactPlugin.APPICE_USER_MARRIED,
75
- isEmployed: AppIceReactPlugin.APPICE_USER_IS_EMPLOYED,
76
- dob: AppIceReactPlugin.APPICE_DATE_OF_BIRTH,
77
-
78
-
79
- TOP_N_PRODUCTS_VIEWED: AppIceReactPlugin.TOP_N_PRODUCTS_VIEWED,
80
- N_COMPLAINTS_RAISED: AppIceReactPlugin.N_COMPLAINTS_RAISED,
81
- PREF_LOGIN_DEVICE: AppIceReactPlugin.PREF_LOGIN_DEVICE,
82
- REFERRAL_CAMPAIGN: AppIceReactPlugin.REFERRAL_CAMPAIGN,
83
- FIRST_SEEN: AppIceReactPlugin.FIRST_SEEN,
84
- LAST_SEEN: AppIceReactPlugin.LAST_SEEN,
85
- DEMOGRAPHIC_INFO: AppIceReactPlugin.DEMOGRAPHIC_INFO,
86
-
87
- //================
88
- // ECOMMERCE
89
- //================
90
- TOTAL_ORDER_VALUE: AppIceReactPlugin.TOTAL_ORDER_VALUE,
91
- ADD_TO_CART_N_DAYS: AppIceReactPlugin.ADD_TO_CART_N_DAYS,
92
-
93
- //====================
94
- // FinancialServices
95
- //====================
96
- FINANCIAL_SERVICES: AppIceReactPlugin.FINANCIAL_SERVICES,
97
- CREDIT_SCORE: AppIceReactPlugin.CREDIT_SCORE,
98
- DEBT_TO_INCOME_RATIO: AppIceReactPlugin.DEBT_TO_INCOME_RATIO,
99
- SAVINGS_BALANCE: AppIceReactPlugin.SAVINGS_BALANCE,
100
- CHECKING_BALANCE: AppIceReactPlugin.CHECKING_BALANCE,
101
- AVERAGE_TRANSACTION_AMOUNT: AppIceReactPlugin.AVERAGE_TRANSACTION_AMOUNT,
102
- FREQUENCY_OF_TRANSACTION: AppIceReactPlugin.FREQUENCY_OF_TRANSACTION,
103
- TYPE_OF_TRANSACTION: AppIceReactPlugin.TYPE_OF_TRANSACTION,
104
-
105
-
106
- //======================
107
- // LISTENER
108
- //======================
109
- /**
110
- * add all of the registered listeners for given eventName.
111
- *
112
- * @param {string} eventName - name of the event whose registered listeners to remove
113
- * @param {callback} handler - handler for events
114
- */
115
- addListener: function (eventName, handler) {
116
- if (eventEmitter) {
117
- eventEmitter.addListener(eventName, handler);
118
- }
119
- },
120
-
121
- /**
122
- * Removes all of the registered listeners for given eventName.
123
- *
124
- * @param {string} eventName - name of the event whose registered listeners to remove
125
- */
126
- removeListener: function (eventName) {
127
- if (eventEmitter) {
128
- eventEmitter.removeAllListeners(eventName);
129
- }
130
- },
131
-
132
-
133
- //=========================
134
- // SDK CONFIG
135
- //========================
136
-
137
- /**
138
- * call this function before clearing old data from db/keychain
139
- */
140
- preInitialise: function () {
141
- this.getDeviceId((res) => {
142
- if (res) {
143
- this.setInternalId(res);
144
- }
145
- });
146
- },
147
-
148
- /**
149
- * Meta data of the apps that is needed for sdk setting
150
- * @param {string} appID - meta key
151
- * @param {string} appKey - meta key
152
- * @param {string} apiKey - meta key
153
- * @param {string} deviceID - unique value to idetify the data from panel
154
- * @param {string} region - e.i. US/GCC/IND
155
- * @param {string} baseUrl -
156
- * @param {object} certs - arrays of certificate paths
157
- * startContext executes after getDeviceId callback
158
- * if res exist assign the value of res else assign deviceID
159
- */
160
- startContext: function (appID, appKey, apiKey, deviceID, region, baseUrl, certs) {
161
- this.getDeviceId((res) => {
162
- if (res) {
163
- AppIceReactPlugin.startContext(appID, appKey, apiKey, res, region, baseUrl, certs)
164
- } else {
165
- AppIceReactPlugin.startContext(appID, appKey, apiKey, deviceID, region, baseUrl, certs)
166
- }
167
- });
168
- AppState.addEventListener('change', (nextAppState) => {
169
- if (nextAppState === 'active') {
170
- AppIceReactPlugin.isDeviceReady(true);
171
- AppIceReactPlugin.registerLifeCycle();
172
- } else if (nextAppState === 'background') {
173
- AppIceReactPlugin.isDeviceReady(false);
174
- AppIceReactPlugin.registerLifeCycle();
175
- }
176
- });
177
- },
178
-
179
- /**
180
- * call this function to register the lifeCycle state of the app
181
- */
182
- registerLifeCycle: function () {
183
- AppIceReactPlugin.registerLifeCycle();
184
- },
185
-
186
- //===========================
187
- // EVENTS AND VARIABLES
188
- //===========================
189
- /**
190
- * Record an event with optional event properties
191
- * @param {string} eventName - the name of the event
192
- * @param {object} props - the key-value properties of the event.
193
- * @param {boolean} flush - to use caching feature.
194
- * keys are strings and values can be string, number or boolean.
195
- */
196
- tagEvent: async function (eventName, props, flush) {
197
- console.log("tagEvent : eventName " + eventName + ", prop " + props + ", flush " + flush);
198
-
199
- if (flush == undefined || flush == null) {
200
- await AppIceReactPlugin.tagEvent(eventName, props);
201
- } else {
202
- const lastEventData = await getEventData(LAST_EVENT_KEY)
203
-
204
-
205
- if (lastEventData != undefined && lastEventData !== eventName) {
206
- try {
207
- const storedEvents = await getEventData(EVENT_KEY + lastEventData)
208
-
209
- console.log("tagEvent : storedEvents " + storedEvents);
210
-
211
- if (storedEvents != null && storedEvents.length > 0) {
212
- let events = storedEvents ? JSON.parse(storedEvents) : [];
213
-
214
- const lastPropsData = events.reduce((acc, event) => {
215
- return { ...acc, ...event.props };
216
- }, {});
217
-
218
- await AppIceReactPlugin.tagEvent(lastEventData, lastPropsData);
219
-
220
- await deleteData(EVENT_KEY + lastEventData)
221
- await deleteData(LAST_EVENT_KEY)
222
-
223
- }
224
- } catch (error) {
225
- console.error('Failed to flush events:', error);
226
- }
227
-
228
- await handleStoredEvents(eventName, props);
229
- } else {
230
- if (flush) {
231
- await handleFlushEvent(eventName, props);
232
- } else {
233
- await handleStoredEvents(eventName, props);
234
- }
235
- }
236
- }
237
- },
238
-
239
-
240
- /**
241
- * to store custom varibles like fcm token..
242
- * @param {string} eventName - the name of the event
243
- * @param {string} props - the name of the event
244
- */
245
- setCustomVariable: function (eventName, props) {
246
- AppIceReactPlugin.setCustomVariable(eventName, props);
247
- },
248
-
249
- //===========================
250
- // CAMPAIGN SETTING
251
- //===========================
252
- /**
253
- * Record an click event
254
- * @param {string} eventName - the name of the event
255
- */
256
- pushNotificationClicked: function (payload) {
257
- AppIceReactPlugin.pushNotificationClicked(payload);
258
- },
259
-
260
- getCustomDataFromPayload: function (object) {
261
- let userObj = JSON.parse(object, (key, value) => {
262
- return value;
263
- });
264
-
265
- let map = new Map(Object.entries(userObj.cdata));
266
-
267
- return map;
268
- },
269
-
270
- //=======================
271
- // USER-PROFILE SETTING
272
- //=======================
273
- /**
274
- * Set key-value properties on a user profile
275
- * @param {object} profile - key-value profile properties. keys are strings and values can be string, number or boolean.
276
- */
277
- setUser: function (profile) {
278
- AppIceReactPlugin.setUser(profile);
279
- },
280
-
281
- /**
282
- * get the properties of a user profile
283
- * return JSONObject
284
- */
285
- getUser: function (callback) {
286
- callWithCallback('getUser', null, callback);
287
- },
288
-
289
- //===============================================
290
- // User id setting
291
- //===============================================
292
-
293
- /**
294
- * Set unique user id
295
- * @param {object} values - array of userids
296
- */
297
- setUserId: function (values) {
298
- AppIceReactPlugin.setUserId(values);
299
- },
300
-
301
- /**
302
- * Getuser id
303
- * @param {object} values - array of userids
304
- */
305
- getUserId: function (callback) {
306
- callWithCallback('getUserId', null, callback);
307
- },
308
-
309
- //===============================================
310
- // Device id setting
311
- //===============================================
312
-
313
- getDeviceId: function (callback) {
314
- callWithCallback('getDeviceId', null, callback)
315
- },
316
-
317
- setInternalId: function (deviceId) {
318
- AppIceReactPlugin.setInternalId(deviceId);
319
- },
320
-
321
- //===============================================
322
- // AppInbox
323
- //===============================================
324
-
325
- /**
326
- * Get inbox messages list.
327
- *
328
- * @param type the message type
329
- * 1 = ALL
330
- * 2 = UNREAD
331
- * 3 = READ
332
- * 4 = VIEWED
333
- * 5 = DELETED
334
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
335
- * @callback will have the string json array
336
- */
337
- getInboxMessages: function (type, userIds, callback) {
338
- callWithCallback('getInboxMessages', [type, userIds], callback);
339
- },
340
-
341
-
342
- /**
343
- * Get inbox messages count.
344
- *
345
- * @param type the message type is integer
346
- * 1 = ALL
347
- * 2 = UNREAD
348
- * 3 = READ
349
- * 4 = VIEWED
350
- * 5 = DELETED
351
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
352
- * @callback will have the integer
353
- */
354
- getMessageCount: function (type, userIds, callback) {
355
- callWithCallback('getMessageCount', [type, userIds], callback);
356
- },
357
-
358
- /**
359
- * Get messages payload based on message id.
360
- *
361
- * @param messageId - message id of the notification
362
- * @param userId - single userid in string ie. "useridA"
363
- * @callback will have the json object
364
- */
365
- getInboxMessageForId: function (messageId, userId, callback) {
366
- callWithCallback('getInboxMessageForId', [messageId, userId], callback);
367
- },
368
-
369
- /**
370
- * update message status ex. UNREAD to READ.
371
- *
372
- * @param messageId - message id of the notification
373
- * @param type - integer value for status
374
- * @param userId - single userid in string
375
- * @callback will have the boolean
376
- */
377
- updateInboxMessage: function (messageId, type, userId, callback) {
378
- callWithCallback('updateInboxMessage', [messageId, type, userId], callback);
379
- },
380
-
381
- synchronizeInbox: function (timeout, callback) {
382
- callWithCallback('synchronizeInbox', [timeout], callback)
383
- },
384
-
385
- //===============================================
386
- // Rich Push AppInbox
387
- //===============================================
388
-
389
- /**
390
- * getMediaData
391
- * @param instanceInboxMessage - instance Dictionary
392
- * @param values - NSString
393
- * @callback will have the Dictionary
394
- */
395
-
396
- getMediaData: function (instanceInboxMessage, mediaKey, callback) {
397
- callWithCallback('getMediaData', [instanceInboxMessage, mediaKey], callback);
398
- },
399
-
400
- /**
401
- * getMediaUrl
402
- * @param instanceInboxMessage - instance Dictionary
403
- * @param values - Dictionary
404
- * @callback will have the string
405
- */
406
- getMediaUrl: function (instanceInboxMessage, values, callback) {
407
- callWithCallback('getMediaUrl', [instanceInboxMessage, values], callback);
408
- },
409
-
410
- /**
411
- * getMediaType
412
- * @param instanceInboxMessage - instance Dictionary
413
- * @param values - Dictionary
414
- * @callback will have the string
415
- */
416
- getMediaType: function (instanceInboxMessage, values, callback) {
417
- callWithCallback('getMediaType', [instanceInboxMessage, values], callback);
418
- },
419
-
420
- /**
421
- * getMediaThumbnail
422
- * @param instanceInboxMessage - instance Dictionary
423
- * @param values - Dictionary
424
- * @callback will have the string
425
- */
426
-
427
- getMediaThumbnail: function (instanceInboxMessage, values, callback) {
428
- callWithCallback('getMediaThumbnail', [instanceInboxMessage, values], callback);
429
- },
430
-
431
- /*==================
432
- isDeviceReady
433
- =====================*/
434
- isDeviceReady: function (isActive) {
435
- AppIceReactPlugin.isDeviceReady(isActive);
436
- },
437
-
438
- /*===============
439
- synchronizeData
440
- ================*/
441
- synchronizeData: function (timeout, callback) {
442
- callWithCallback('synchronizeData', [timeout], callback)
443
- },
444
-
445
- /*===================
446
- getUserForIds with userIds
447
- =====================*/
448
-
449
- getUserForIds: function (userIds, callback) {
450
- callWithCallback('getUserForIds', [userIds], callback);
451
- },
452
-
453
- /*===================
454
- GetCampaign
455
- =====================*/
456
-
457
- /**
458
- * getCampaigns
459
- * @param campType - string
460
- * @callback - Return array of Campaign objects
461
- */
462
-
463
- getCampaigns: function (campType, callback) {
464
- AppIceReactPlugin.getCampaigns(campType, (campaignArray) => {
465
- const campaigns = campaignArray.map(
466
- (campaignData) =>
467
- new Campaign(
468
- campaignData[CAMP_ID],
469
- campaignData[ACTION_URL],
470
- campaignData[ACTION_TYPE],
471
- campaignData[CUSTOMDATA]
472
- )
473
- );
474
- callback(campaigns);
475
- });
476
- },
477
-
478
-
479
-
480
- /**
481
- * getCampaignById
482
- * @param campId - string
483
- * @callback -Return a single Campaign object
484
- */
485
-
486
- getCampaignById: function (campId, callback) {
487
- AppIceReactPlugin.getCampaignById(campId, (campaignData) => {
488
- const getCampaign = new Campaign(
489
- campaignData[CAMP_ID],
490
- campaignData[ACTION_URL],
491
- campaignData[ACTION_TYPE],
492
- campaignData[CUSTOMDATA]
493
- );
494
- callback(getCampaign);
495
- });
496
- },
497
-
498
- //campaign enum
499
- CampaignType,
500
- };
501
-
502
-
503
-
504
- //================================
505
- // INTERNAL COMMON APIS
506
- //=================================
507
-
508
- // internal function for callback
509
- function callWithCallback(method, args, callback) {
510
- if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') {
511
- callback = (err, res) => {
512
- defaultCallback(method, err, res);
513
- };
514
- }
515
-
516
- if (args == null) {
517
- args = [];
518
- }
519
-
520
- args.push(callback);
521
-
522
- AppIceReactPlugin[method].apply(this, args);
523
- }
524
-
525
- const handleStoredEvents = async (eventName, props) => {
526
- try {
527
- const storedEvents = await getEventData(EVENT_KEY + eventName);
528
- let events = storedEvents ? JSON.parse(storedEvents) : [];
529
-
530
- // Add the current event
531
- events.push({ eventName, props });
532
-
533
- // Save the updated events list
534
- // appStorage.set(EVENT_KEY + eventName, JSON.stringify(events));
535
- // appStorage.set(LAST_EVENT_KEY, eventName);
536
-
537
- // async Storage
538
- await AsyncStorage.setItem(EVENT_KEY + eventName, JSON.stringify(events))
539
- await AsyncStorage.setItem(LAST_EVENT_KEY, eventName)
540
-
541
-
542
- } catch (error) {
543
- console.error('Failed to store event:', error);
544
- }
545
- };
546
-
547
- const handleFlushEvent = async (eventName, props) => {
548
- try {
549
- const storedEvents = await getEventData(EVENT_KEY + eventName);
550
- let events = storedEvents ? JSON.parse(storedEvents) : [];
551
-
552
- events.forEach(event => {
553
- Object.assign(props, event.props);
554
- });
555
-
556
- await AppIceReactPlugin.tagEvent(eventName, props);
557
-
558
- await deleteData(EVENT_KEY + eventName)
559
- await deleteData(LAST_EVENT_KEY)
560
-
561
-
562
- } catch (error) {
563
- console.error('Failed to flush events:', error);
564
- }
565
- };
566
-
567
- const deleteData = async (eventName) => {
568
- try {
569
- //appStorage.delete(EVENT_KEY + eventName);
570
- //appStorage.delete(LAST_EVENT_KEY);
571
-
572
- await AsyncStorage.removeItem(eventName)
573
- } catch (error) {
574
- console.error('Failed to delete events:', error);
575
- }
576
- };
577
-
578
- const getEventData = async (eventName) => {
579
- try {
580
-
581
- // const storedEvents1 = appStorage.getString(EVENT_KEY + lastEventData);
582
-
583
- return await AsyncStorage.getItem(eventName)
584
- } catch (error) {
585
- console.error('Failed to fetch events:', error);
586
- }
587
- };
588
-
589
-
590
- module.exports = AppICEReact;
1
+ import { DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
2
+ import { Platform, Component, AppState } from 'react-native';
3
+ // import { MMKV } from 'react-native-mmkv'
4
+ import AsyncStorage from '@react-native-async-storage/async-storage';
5
+ import Campaign from './campaign';
6
+
7
+ const AppIceReactPlugin = NativeModules.AppIceReactPlugin;
8
+ var eventEmitter;
9
+ if (Platform.OS === 'ios') {
10
+ eventEmitter = NativeModules.AppICEReactEvent ? new NativeEventEmitter(NativeModules.AppICEReactEvent) : DeviceEventEmitter;
11
+ }
12
+ else {
13
+ eventEmitter = new NativeEventEmitter(NativeModules.AppIceReactPlugin);
14
+ }
15
+
16
+ // export const appStorage = new MMKV({
17
+ // id: 'AppICE-storage',
18
+ // })
19
+
20
+ const EVENT_KEY = "lastEvent"
21
+ const LAST_EVENT_KEY = "event_"
22
+
23
+ export const CAMP_ID = AppIceReactPlugin.CAMP_ID;
24
+ export const ACTION_URL = AppIceReactPlugin.ACTION_URL;
25
+ export const ACTION_TYPE = AppIceReactPlugin.ACTION_TYPE;
26
+ export const CUSTOMDATA = AppIceReactPlugin.CUSTOMDATA;
27
+
28
+ const CampaignType = {
29
+ NATIVE: 'NATIVE',
30
+ INAPP: 'INAPP',
31
+ PUSH: 'PUSH',
32
+ };
33
+
34
+
35
+ var AppICEReact = {
36
+
37
+ validateIntegration: AppIceReactPlugin.validateIntegration,
38
+
39
+ //========================
40
+ // PUSH
41
+ //========================
42
+ AppICEPushNotificationClicked: AppIceReactPlugin.AppICEPushNotificationClicked,
43
+
44
+ //==========================
45
+ // IN-APP
46
+ //==========================
47
+ AppICEInAppClicked: AppIceReactPlugin.AppICEInAppClicked,
48
+
49
+ //========================
50
+ // APP-INBOX
51
+ //========================
52
+ INBOX_MESSAGE: AppIceReactPlugin.INBOX_MESSAGE,
53
+ INBOX_TITLE: AppIceReactPlugin.INBOX_TITLE,
54
+ INBOX_MESSAGE_STATUS: AppIceReactPlugin.INBOX_MESSAGE_STATUS,
55
+ INBOX_CAMPAIGN_TYPE: AppIceReactPlugin.INBOX_CAMPAIGN_TYPE,
56
+ INBOX_MESSAGE_LANGUAGE: AppIceReactPlugin.INBOX_MESSAGE_LANGUAGE,
57
+ INBOX_MESSAGE_ID: AppIceReactPlugin.INBOX_MESSAGE_ID,
58
+ INBOX_CAMPAIGN_ID: AppIceReactPlugin.INBOX_CAMPAIGN_ID,
59
+ INBOX_MESSAGE_ICON: AppIceReactPlugin.INBOX_MESSAGE_ICON,
60
+ INBOX_CUSTOM_DATA: AppIceReactPlugin.INBOX_CUSTOM_DATA,
61
+ INBOX_MESSAGE_EXPANDED_IMAGE: AppIceReactPlugin.INBOX_MESSAGE_EXPANDED_IMAGE,
62
+
63
+
64
+ //=======================
65
+ // USER-PROFILE SETTING
66
+ //=======================
67
+ name: AppIceReactPlugin.APPICE_USER_NAME,
68
+ email: AppIceReactPlugin.APPICE_USER_EMAIL,
69
+ phone: AppIceReactPlugin.APPICE_USER_PHONE,
70
+ age: AppIceReactPlugin.APPICE_USER_AGE,
71
+ gender: AppIceReactPlugin.APPICE_USER_GENDER,
72
+ educationType: AppIceReactPlugin.APPICE_USER_EDUCATION_TYPE,
73
+ employmentType: AppIceReactPlugin.APPICE_USER_EMPLOYMENT_TYPE,
74
+ married: AppIceReactPlugin.APPICE_USER_MARRIED,
75
+ isEmployed: AppIceReactPlugin.APPICE_USER_IS_EMPLOYED,
76
+ dob: AppIceReactPlugin.APPICE_DATE_OF_BIRTH,
77
+
78
+
79
+ TOP_N_PRODUCTS_VIEWED: AppIceReactPlugin.TOP_N_PRODUCTS_VIEWED,
80
+ N_COMPLAINTS_RAISED: AppIceReactPlugin.N_COMPLAINTS_RAISED,
81
+ PREF_LOGIN_DEVICE: AppIceReactPlugin.PREF_LOGIN_DEVICE,
82
+ REFERRAL_CAMPAIGN: AppIceReactPlugin.REFERRAL_CAMPAIGN,
83
+ FIRST_SEEN: AppIceReactPlugin.FIRST_SEEN,
84
+ LAST_SEEN: AppIceReactPlugin.LAST_SEEN,
85
+ DEMOGRAPHIC_INFO: AppIceReactPlugin.DEMOGRAPHIC_INFO,
86
+
87
+ //================
88
+ // ECOMMERCE
89
+ //================
90
+ TOTAL_ORDER_VALUE: AppIceReactPlugin.TOTAL_ORDER_VALUE,
91
+ ADD_TO_CART_N_DAYS: AppIceReactPlugin.ADD_TO_CART_N_DAYS,
92
+
93
+ //====================
94
+ // FinancialServices
95
+ //====================
96
+ FINANCIAL_SERVICES: AppIceReactPlugin.FINANCIAL_SERVICES,
97
+ CREDIT_SCORE: AppIceReactPlugin.CREDIT_SCORE,
98
+ DEBT_TO_INCOME_RATIO: AppIceReactPlugin.DEBT_TO_INCOME_RATIO,
99
+ SAVINGS_BALANCE: AppIceReactPlugin.SAVINGS_BALANCE,
100
+ CHECKING_BALANCE: AppIceReactPlugin.CHECKING_BALANCE,
101
+ AVERAGE_TRANSACTION_AMOUNT: AppIceReactPlugin.AVERAGE_TRANSACTION_AMOUNT,
102
+ FREQUENCY_OF_TRANSACTION: AppIceReactPlugin.FREQUENCY_OF_TRANSACTION,
103
+ TYPE_OF_TRANSACTION: AppIceReactPlugin.TYPE_OF_TRANSACTION,
104
+
105
+
106
+ //======================
107
+ // LISTENER
108
+ //======================
109
+ /**
110
+ * add all of the registered listeners for given eventName.
111
+ *
112
+ * @param {string} eventName - name of the event whose registered listeners to remove
113
+ * @param {callback} handler - handler for events
114
+ */
115
+ addListener: function (eventName, handler) {
116
+ if (eventEmitter) {
117
+ eventEmitter.addListener(eventName, handler);
118
+ }
119
+ },
120
+
121
+ /**
122
+ * Removes all of the registered listeners for given eventName.
123
+ *
124
+ * @param {string} eventName - name of the event whose registered listeners to remove
125
+ */
126
+ removeListener: function (eventName) {
127
+ if (eventEmitter) {
128
+ eventEmitter.removeAllListeners(eventName);
129
+ }
130
+ },
131
+
132
+
133
+ //=========================
134
+ // SDK CONFIG
135
+ //========================
136
+
137
+ /**
138
+ * call this function before clearing old data from db/keychain
139
+ */
140
+ preInitialise: function () {
141
+ this.getDeviceId((res) => {
142
+ if (res) {
143
+ this.setInternalId(res);
144
+ }
145
+ });
146
+ },
147
+
148
+ /**
149
+ * Meta data of the apps that is needed for sdk setting
150
+ * @param {string} appID - meta key
151
+ * @param {string} appKey - meta key
152
+ * @param {string} apiKey - meta key
153
+ * @param {string} deviceID - unique value to idetify the data from panel
154
+ * @param {string} region - e.i. US/GCC/IND
155
+ * @param {string} baseUrl -
156
+ * @param {object} certs - arrays of certificate paths
157
+ * startContext executes after getDeviceId callback
158
+ * if res exist assign the value of res else assign deviceID
159
+ */
160
+ startContext: function (appID, appKey, apiKey, deviceID, region, baseUrl, certs) {
161
+ this.getDeviceId((res) => {
162
+ if (res) {
163
+ AppIceReactPlugin.startContext(appID, appKey, apiKey, res, region, baseUrl, certs)
164
+ } else {
165
+ AppIceReactPlugin.startContext(appID, appKey, apiKey, deviceID, region, baseUrl, certs)
166
+ }
167
+ });
168
+ AppState.addEventListener('change', (nextAppState) => {
169
+ if (nextAppState === 'active') {
170
+ AppIceReactPlugin.isDeviceReady(true);
171
+ AppIceReactPlugin.registerLifeCycle();
172
+ } else if (nextAppState === 'background') {
173
+ AppIceReactPlugin.isDeviceReady(false);
174
+ AppIceReactPlugin.registerLifeCycle();
175
+ }
176
+ });
177
+ },
178
+
179
+ /**
180
+ * call this function to register the lifeCycle state of the app
181
+ */
182
+ registerLifeCycle: function () {
183
+ AppIceReactPlugin.registerLifeCycle();
184
+ },
185
+
186
+ //===========================
187
+ // EVENTS AND VARIABLES
188
+ //===========================
189
+ /**
190
+ * Record an event with optional event properties
191
+ * @param {string} eventName - the name of the event
192
+ * @param {object} props - the key-value properties of the event.
193
+ * @param {boolean} flush - to use caching feature.
194
+ * keys are strings and values can be string, number or boolean.
195
+ */
196
+ tagEvent: async function (eventName, props, flush) {
197
+ console.log("tagEvent : eventName " + eventName + ", prop " + props + ", flush " + flush);
198
+
199
+ if (flush == undefined || flush == null) {
200
+ await AppIceReactPlugin.tagEvent(eventName, props);
201
+ } else {
202
+ const lastEventData = await getEventData(LAST_EVENT_KEY)
203
+
204
+
205
+ if (lastEventData != undefined && lastEventData !== eventName) {
206
+ try {
207
+ const storedEvents = await getEventData(EVENT_KEY + lastEventData)
208
+
209
+ console.log("tagEvent : storedEvents " + storedEvents);
210
+
211
+ if (storedEvents != null && storedEvents.length > 0) {
212
+ let events = storedEvents ? JSON.parse(storedEvents) : [];
213
+
214
+ const lastPropsData = events.reduce((acc, event) => {
215
+ return { ...acc, ...event.props };
216
+ }, {});
217
+
218
+ await AppIceReactPlugin.tagEvent(lastEventData, lastPropsData);
219
+
220
+ await deleteData(EVENT_KEY + lastEventData)
221
+ await deleteData(LAST_EVENT_KEY)
222
+
223
+ }
224
+ } catch (error) {
225
+ console.error('Failed to flush events:', error);
226
+ }
227
+
228
+ await handleStoredEvents(eventName, props);
229
+ } else {
230
+ if (flush) {
231
+ await handleFlushEvent(eventName, props);
232
+ } else {
233
+ await handleStoredEvents(eventName, props);
234
+ }
235
+ }
236
+ }
237
+ },
238
+
239
+
240
+ /**
241
+ * to store custom varibles like fcm token..
242
+ * @param {string} eventName - the name of the event
243
+ * @param {string} props - the name of the event
244
+ */
245
+ setCustomVariable: function (eventName, props) {
246
+ AppIceReactPlugin.setCustomVariable(eventName, props);
247
+ },
248
+
249
+ //===========================
250
+ // CAMPAIGN SETTING
251
+ //===========================
252
+ /**
253
+ * Record an click event
254
+ * @param {string} eventName - the name of the event
255
+ */
256
+ pushNotificationClicked: function (payload) {
257
+ AppIceReactPlugin.pushNotificationClicked(payload);
258
+ },
259
+
260
+ getCustomDataFromPayload: function (object) {
261
+ let userObj = JSON.parse(object, (key, value) => {
262
+ return value;
263
+ });
264
+
265
+ let map = new Map(Object.entries(userObj.cdata));
266
+
267
+ return map;
268
+ },
269
+
270
+ //=======================
271
+ // USER-PROFILE SETTING
272
+ //=======================
273
+ /**
274
+ * Set key-value properties on a user profile
275
+ * @param {object} profile - key-value profile properties. keys are strings and values can be string, number or boolean.
276
+ */
277
+ setUser: function (profile) {
278
+ AppIceReactPlugin.setUser(profile);
279
+ },
280
+
281
+ /**
282
+ * get the properties of a user profile
283
+ * return JSONObject
284
+ */
285
+ getUser: function (callback) {
286
+ callWithCallback('getUser', null, callback);
287
+ },
288
+
289
+ //===============================================
290
+ // User id setting
291
+ //===============================================
292
+
293
+ /**
294
+ * Set unique user id
295
+ * @param {object} values - array of userids
296
+ */
297
+ setUserId: function (values) {
298
+ AppIceReactPlugin.setUserId(values);
299
+ },
300
+
301
+ /**
302
+ * Getuser id
303
+ * @param {object} values - array of userids
304
+ */
305
+ getUserId: function (callback) {
306
+ callWithCallback('getUserId', null, callback);
307
+ },
308
+
309
+ //===============================================
310
+ // Device id setting
311
+ //===============================================
312
+
313
+ getDeviceId: function (callback) {
314
+ callWithCallback('getDeviceId', null, callback)
315
+ },
316
+
317
+ setInternalId: function (deviceId) {
318
+ AppIceReactPlugin.setInternalId(deviceId);
319
+ },
320
+
321
+ //===============================================
322
+ // AppInbox
323
+ //===============================================
324
+
325
+ /**
326
+ * Get inbox messages list.
327
+ *
328
+ * @param type the message type
329
+ * 1 = ALL
330
+ * 2 = UNREAD
331
+ * 3 = READ
332
+ * 4 = VIEWED
333
+ * 5 = DELETED
334
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
335
+ * @callback will have the string json array
336
+ */
337
+ getInboxMessages: function (type, userIds, callback) {
338
+ callWithCallback('getInboxMessages', [type, userIds], callback);
339
+ },
340
+
341
+
342
+ /**
343
+ * Get inbox messages count.
344
+ *
345
+ * @param type the message type is integer
346
+ * 1 = ALL
347
+ * 2 = UNREAD
348
+ * 3 = READ
349
+ * 4 = VIEWED
350
+ * 5 = DELETED
351
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
352
+ * @callback will have the integer
353
+ */
354
+ getMessageCount: function (type, userIds, callback) {
355
+ callWithCallback('getMessageCount', [type, userIds], callback);
356
+ },
357
+
358
+ /**
359
+ * Get messages payload based on message id.
360
+ *
361
+ * @param messageId - message id of the notification
362
+ * @param userId - single userid in string ie. "useridA"
363
+ * @callback will have the json object
364
+ */
365
+ getInboxMessageForId: function (messageId, userId, callback) {
366
+ callWithCallback('getInboxMessageForId', [messageId, userId], callback);
367
+ },
368
+
369
+ /**
370
+ * update message status ex. UNREAD to READ.
371
+ *
372
+ * @param messageId - message id of the notification
373
+ * @param type - integer value for status
374
+ * @param userId - single userid in string
375
+ * @callback will have the boolean
376
+ */
377
+ updateInboxMessage: function (messageId, type, userId, callback) {
378
+ callWithCallback('updateInboxMessage', [messageId, type, userId], callback);
379
+ },
380
+
381
+ synchronizeInbox: function (timeout, callback) {
382
+ callWithCallback('synchronizeInbox', [timeout], callback)
383
+ },
384
+
385
+ //===============================================
386
+ // Rich Push AppInbox
387
+ //===============================================
388
+
389
+ /**
390
+ * getMediaData
391
+ * @param instanceInboxMessage - instance Dictionary
392
+ * @param values - NSString
393
+ * @callback will have the Dictionary
394
+ */
395
+
396
+ getMediaData: function (instanceInboxMessage, mediaKey, callback) {
397
+ callWithCallback('getMediaData', [instanceInboxMessage, mediaKey], callback);
398
+ },
399
+
400
+ /**
401
+ * getMediaUrl
402
+ * @param instanceInboxMessage - instance Dictionary
403
+ * @param values - Dictionary
404
+ * @callback will have the string
405
+ */
406
+ getMediaUrl: function (instanceInboxMessage, values, callback) {
407
+ callWithCallback('getMediaUrl', [instanceInboxMessage, values], callback);
408
+ },
409
+
410
+ /**
411
+ * getMediaType
412
+ * @param instanceInboxMessage - instance Dictionary
413
+ * @param values - Dictionary
414
+ * @callback will have the string
415
+ */
416
+ getMediaType: function (instanceInboxMessage, values, callback) {
417
+ callWithCallback('getMediaType', [instanceInboxMessage, values], callback);
418
+ },
419
+
420
+ /**
421
+ * getMediaThumbnail
422
+ * @param instanceInboxMessage - instance Dictionary
423
+ * @param values - Dictionary
424
+ * @callback will have the string
425
+ */
426
+
427
+ getMediaThumbnail: function (instanceInboxMessage, values, callback) {
428
+ callWithCallback('getMediaThumbnail', [instanceInboxMessage, values], callback);
429
+ },
430
+
431
+ /*==================
432
+ isDeviceReady
433
+ =====================*/
434
+ isDeviceReady: function (isActive) {
435
+ AppIceReactPlugin.isDeviceReady(isActive);
436
+ },
437
+
438
+ /*===============
439
+ synchronizeData
440
+ ================*/
441
+ synchronizeData: function (timeout, callback) {
442
+ callWithCallback('synchronizeData', [timeout], callback)
443
+ },
444
+
445
+ /*===================
446
+ getUserForIds with userIds
447
+ =====================*/
448
+
449
+ getUserForIds: function (userIds, callback) {
450
+ callWithCallback('getUserForIds', [userIds], callback);
451
+ },
452
+
453
+ /*===================
454
+ GetCampaign
455
+ =====================*/
456
+
457
+ /**
458
+ * getCampaigns
459
+ * @param campType - string
460
+ * @callback - Return array of Campaign objects
461
+ */
462
+
463
+ getCampaigns: function (campType, callback) {
464
+ AppIceReactPlugin.getCampaigns(campType, (campaignArray) => {
465
+ const campaigns = campaignArray.map(
466
+ (campaignData) =>
467
+ new Campaign(
468
+ campaignData[CAMP_ID],
469
+ campaignData[ACTION_URL],
470
+ campaignData[ACTION_TYPE],
471
+ campaignData[CUSTOMDATA]
472
+ )
473
+ );
474
+ callback(campaigns);
475
+ });
476
+ },
477
+
478
+
479
+
480
+ /**
481
+ * getCampaignById
482
+ * @param campId - string
483
+ * @callback -Return a single Campaign object
484
+ */
485
+
486
+ getCampaignById: function (campId, callback) {
487
+ AppIceReactPlugin.getCampaignById(campId, (campaignData) => {
488
+ const getCampaign = new Campaign(
489
+ campaignData[CAMP_ID],
490
+ campaignData[ACTION_URL],
491
+ campaignData[ACTION_TYPE],
492
+ campaignData[CUSTOMDATA]
493
+ );
494
+ callback(getCampaign);
495
+ });
496
+ },
497
+
498
+ //campaign enum
499
+ CampaignType,
500
+ };
501
+
502
+
503
+
504
+ //================================
505
+ // INTERNAL COMMON APIS
506
+ //=================================
507
+
508
+ // internal function for callback
509
+ function callWithCallback(method, args, callback) {
510
+ if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') {
511
+ callback = (err, res) => {
512
+ defaultCallback(method, err, res);
513
+ };
514
+ }
515
+
516
+ if (args == null) {
517
+ args = [];
518
+ }
519
+
520
+ args.push(callback);
521
+
522
+ AppIceReactPlugin[method].apply(this, args);
523
+ }
524
+
525
+ const handleStoredEvents = async (eventName, props) => {
526
+ try {
527
+ const storedEvents = await getEventData(EVENT_KEY + eventName);
528
+ let events = storedEvents ? JSON.parse(storedEvents) : [];
529
+
530
+ // Add the current event
531
+ events.push({ eventName, props });
532
+
533
+ // Save the updated events list
534
+ // appStorage.set(EVENT_KEY + eventName, JSON.stringify(events));
535
+ // appStorage.set(LAST_EVENT_KEY, eventName);
536
+
537
+ // async Storage
538
+ await AsyncStorage.setItem(EVENT_KEY + eventName, JSON.stringify(events))
539
+ await AsyncStorage.setItem(LAST_EVENT_KEY, eventName)
540
+
541
+
542
+ } catch (error) {
543
+ console.error('Failed to store event:', error);
544
+ }
545
+ };
546
+
547
+ const handleFlushEvent = async (eventName, props) => {
548
+ try {
549
+ const storedEvents = await getEventData(EVENT_KEY + eventName);
550
+ let events = storedEvents ? JSON.parse(storedEvents) : [];
551
+
552
+ events.forEach(event => {
553
+ Object.assign(props, event.props);
554
+ });
555
+
556
+ await AppIceReactPlugin.tagEvent(eventName, props);
557
+
558
+ await deleteData(EVENT_KEY + eventName)
559
+ await deleteData(LAST_EVENT_KEY)
560
+
561
+
562
+ } catch (error) {
563
+ console.error('Failed to flush events:', error);
564
+ }
565
+ };
566
+
567
+ const deleteData = async (eventName) => {
568
+ try {
569
+ //appStorage.delete(EVENT_KEY + eventName);
570
+ //appStorage.delete(LAST_EVENT_KEY);
571
+
572
+ await AsyncStorage.removeItem(eventName)
573
+ } catch (error) {
574
+ console.error('Failed to delete events:', error);
575
+ }
576
+ };
577
+
578
+ const getEventData = async (eventName) => {
579
+ try {
580
+
581
+ // const storedEvents1 = appStorage.getString(EVENT_KEY + lastEventData);
582
+
583
+ return await AsyncStorage.getItem(eventName)
584
+ } catch (error) {
585
+ console.error('Failed to fetch events:', error);
586
+ }
587
+ };
588
+
589
+
590
+ module.exports = AppICEReact;