react-native-moengage 7.4.1 → 8.1.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 (55) hide show
  1. package/CHANGELOG.md +72 -1
  2. package/ReactNativeMoEngage.podspec +3 -3
  3. package/android/build.gradle +11 -12
  4. package/android/gradle/wrapper/gradle-wrapper.properties +3 -3
  5. package/android/gradle.properties +0 -1
  6. package/android/src/main/java/com/moengage/react/EventEmitterImpl.kt +57 -22
  7. package/android/src/main/java/com/moengage/react/MoEInitializer.kt +44 -13
  8. package/android/src/main/java/com/moengage/react/MoEReactBridge.kt +116 -82
  9. package/android/src/main/java/com/moengage/react/MoEReactHelper.kt +2 -2
  10. package/android/src/main/java/com/moengage/react/PayloadGenerator.kt +41 -17
  11. package/iOS/MoEReactBridge/MoEReactBridge.h +1 -1
  12. package/iOS/MoEReactBridge/MoEReactBridge.m +34 -60
  13. package/iOS/MoEReactBridge/MoEngageInitializer.h +61 -0
  14. package/iOS/MoEReactBridge/MoEngageInitializer.m +164 -0
  15. package/iOS/MoEReactBridge/{MoEReactConstants.h → MoEngageReactConstants.h} +13 -3
  16. package/iOS/MoEReactBridge/{MoEReactConstants.m → MoEngageReactConstants.m} +14 -7
  17. package/iOS/MoEReactBridge/MoEngageReactPluginInfo.h +2 -0
  18. package/iOS/MoEReactBridge.xcodeproj/project.pbxproj +6 -6
  19. package/package.json +8 -3
  20. package/src/index.ts +196 -208
  21. package/src/models/MoEAccountMeta.ts +8 -0
  22. package/src/models/MoEAction.ts +4 -0
  23. package/src/models/MoEActionType.ts +4 -0
  24. package/src/models/MoECampaignContext.ts +10 -0
  25. package/src/models/MoECampaignData.ts +14 -0
  26. package/src/models/MoEClickData.ts +18 -0
  27. package/src/models/MoEGeoLocation.ts +2 -10
  28. package/src/models/MoEInAppCustomAction.ts +8 -13
  29. package/src/models/MoEInAppData.ts +16 -0
  30. package/src/models/MoEInAppNavigation.ts +14 -24
  31. package/src/models/MoENavigationType.ts +4 -0
  32. package/src/models/MoEPlatform.ts +4 -0
  33. package/src/models/MoEProperties.ts +19 -15
  34. package/src/models/MoEPushCampaign.ts +6 -22
  35. package/src/models/MoEPushPayload.ts +14 -0
  36. package/src/models/MoEPushService.ts +4 -4
  37. package/src/models/MoEPushToken.ts +6 -15
  38. package/src/models/MoESelfHandledCampaign.ts +10 -0
  39. package/src/models/MoESelfHandledCampaignData.ts +18 -0
  40. package/src/models/MoEngagePermissionType.ts +3 -0
  41. package/src/models/MoEngagePersimissionResultData.ts +14 -0
  42. package/src/moeParser/MoEInAppParser.ts +192 -0
  43. package/src/moeParser/MoEPushNotificationParser.ts +78 -0
  44. package/src/moeParser/MoEngagePayloadParser.ts +11 -0
  45. package/src/platform/MoERNAndroid.ts +62 -92
  46. package/src/platform/MoERNiOS.ts +27 -60
  47. package/src/utils/MoEConstants.ts +61 -0
  48. package/src/utils/MoEEventHandlerHelper.ts +47 -28
  49. package/src/utils/MoEJsonBuilder.ts +229 -0
  50. package/src/utils/MoEObjectToJson.ts +44 -0
  51. package/iOS/MoEReactBridge/MOReactInitializer.h +0 -46
  52. package/iOS/MoEReactBridge/MOReactInitializer.m +0 -172
  53. package/iOS/MoEReactBridge/MOReactPluginInfo.h +0 -2
  54. package/src/models/MoEInAppCampaign.ts +0 -46
  55. package/src/models/MoEInAppSelfHandledCampaign.ts +0 -34
package/src/index.ts CHANGED
@@ -1,22 +1,50 @@
1
- import { Platform, NativeEventEmitter } from "react-native";
2
- import MoEInAppSelfHandledCampaign from "./models/MoEInAppSelfHandledCampaign";
1
+ import {NativeEventEmitter, Platform} from "react-native";
3
2
  import MoEProperties from "./models/MoEProperties";
4
3
  import MoEGeoLocation from "./models/MoEGeoLocation";
5
4
  import * as MoEHelper from "./utils/MoEHelper";
6
5
 
7
- import { MoEAppStatus } from "./models/MoEAppStatus";
8
- import { MoERNAndroid } from "./platform/MoERNAndroid";
9
- import { MoERNiOS } from "./platform/MoERNiOS";
6
+ import {MoEAppStatus} from "./models/MoEAppStatus";
7
+ import {MoERNAndroid} from "./platform/MoERNAndroid";
8
+ import {MoERNiOS} from "./platform/MoERNiOS";
10
9
 
11
- import MoEInAppCampaign from "./models/MoEInAppCampaign";
12
10
  import MoEInAppCustomAction from "./models/MoEInAppCustomAction";
13
11
  import MoEInAppNavigation from "./models/MoEInAppNavigation";
14
- import { executeHandler } from "./utils/MoEEventHandlerHelper";
12
+ import {executeHandler} from "./utils/MoEEventHandlerHelper";
13
+ import {
14
+ getAdIdTrackingJson,
15
+ getAliasJson,
16
+ getAndroidIdTrackingJson,
17
+ getAppIdJson,
18
+ getAppStatusJson,
19
+ getInAppContextJson,
20
+ getMoEPropertiesJson,
21
+ getMoEPushCampaignJson,
22
+ getMoEPushTokenJson,
23
+ getOptOutTrackingJson,
24
+ getSdkStateJson,
25
+ getSelfHandledJson,
26
+ getUserAttributeJson,
27
+ getUserLocAttributeJson
28
+ } from "./utils/MoEJsonBuilder";
29
+ import {
30
+ USER_ATTRIBUTE_UNIQUE_ID,
31
+ USER_ATTRIBUTE_USER_BDAY,
32
+ USER_ATTRIBUTE_USER_EMAIL,
33
+ USER_ATTRIBUTE_USER_FIRST_NAME,
34
+ USER_ATTRIBUTE_USER_GENDER,
35
+ USER_ATTRIBUTE_USER_LAST_NAME,
36
+ USER_ATTRIBUTE_USER_LOCATION,
37
+ USER_ATTRIBUTE_USER_MOBILE,
38
+ USER_ATTRIBUTE_USER_NAME
39
+ } from "./utils/MoEConstants";
40
+ import MoESelfHandledCampaignData from "./models/MoESelfHandledCampaignData";
41
+ import {MoEngagePermissionType} from "./models/MoEngagePermissionType";
15
42
 
16
43
  const MoEReactBridge = require("react-native").NativeModules.MoEReactBridge;
17
44
  const PLATFORM_ANDROID = "android";
18
45
  const PLATFORM_IOS = "ios";
19
46
  const GENERAL = "general";
47
+ const TIMESTAMP = 'timestamp';
20
48
 
21
49
  const MOE_PUSH_CLICKED = "MoEPushClicked";
22
50
  const MOE_PUSH_REGISTERED = "MoEPushTokenGenerated";
@@ -25,6 +53,7 @@ const MOE_INAPP_CLICKED = "MoEInAppCampaignClicked";
25
53
  const MOE_INAPP_DISMISSED = "MoEInAppCampaignDismissed";
26
54
  const MOE_INAPP_CUSTOM_ACTION = "MoEInAppCampaignCustomAction";
27
55
  const MOE_INAPP_SELF_HANDLE = "MoEInAppCampaignSelfHandled";
56
+ const MOE_PERMISSION_RESULT = "MoEPermissionResult";
28
57
 
29
58
  const eventBroadcastNames = [
30
59
  MOE_PUSH_CLICKED,
@@ -34,6 +63,7 @@ const eventBroadcastNames = [
34
63
  MOE_INAPP_DISMISSED,
35
64
  MOE_INAPP_CUSTOM_ACTION,
36
65
  MOE_INAPP_SELF_HANDLE,
66
+ MOE_PERMISSION_RESULT
37
67
  ];
38
68
 
39
69
  // JS Event Names
@@ -44,6 +74,10 @@ const INAPP_CLICKED = "inAppCampaignClicked";
44
74
  const INAPP_DISMISSED = "inAppCampaignDismissed";
45
75
  const INAPP_CUTOM_ACTION = "inAppCampaignCustomAction";
46
76
  const INAPP_SELF_HANDLE = "inAppCampaignSelfHandled";
77
+ export const PERMISSION_RESULT = "permissionResult";
78
+
79
+ const PUSH_SERVICE_FCM = "FCM"
80
+ const PUSH_SERVICE_PUSH_KIT = "PUSH_KIT"
47
81
 
48
82
  const _eventNames = [
49
83
  PUSH_CLICKED,
@@ -53,10 +87,12 @@ const _eventNames = [
53
87
  INAPP_DISMISSED,
54
88
  INAPP_CUTOM_ACTION,
55
89
  INAPP_SELF_HANDLE,
90
+ PERMISSION_RESULT
56
91
  ];
57
92
 
58
93
  var _eventTypeHandler = new Map();
59
- var MoeEventEmitter;
94
+ var MoeEventEmitter: { addListener: (arg0: any, arg1: (notification: any) => void) => void; };
95
+ var moeAppId = "";
60
96
 
61
97
  if (MoEReactBridge) {
62
98
  MoeEventEmitter = new NativeEventEmitter(MoEReactBridge);
@@ -65,8 +101,8 @@ if (MoEReactBridge) {
65
101
  }
66
102
  }
67
103
 
68
- function handleEventBroadcast(type, broadcast) {
69
- MoeEventEmitter.addListener(broadcast, (notification) => {
104
+ function handleEventBroadcast(type: string | String, broadcast: string) {
105
+ MoeEventEmitter.addListener(broadcast, (notification: any) => {
70
106
  executeHandler(_eventTypeHandler.get(type), notification, type);
71
107
  });
72
108
  }
@@ -84,22 +120,23 @@ function showError(message: String) {
84
120
  }
85
121
 
86
122
  var ReactMoE = {
87
- setEventListener: function (type, handler) {
123
+ setEventListener: function (type: any, handler: any) {
88
124
  if (!MoEReactBridge) return;
89
125
  _eventTypeHandler.set(type, handler);
90
126
  },
91
127
 
92
- removeEventListener: function (type) {
128
+ removeEventListener: function (type: any) {
93
129
  if (!MoEReactBridge) return;
94
130
  _eventTypeHandler.delete(type);
95
131
  },
96
132
 
97
- initialize: function () {
133
+ initialize: function (appId:string) {
134
+ moeAppId = appId;
98
135
  commonValidationCheck();
99
136
  if (Platform.OS == PLATFORM_ANDROID) {
100
- MoERNAndroid.initialize();
137
+ MoERNAndroid.initialize(getAppIdJson(appId));
101
138
  } else if (Platform.OS == PLATFORM_IOS) {
102
- MoERNiOS.initialize();
139
+ MoERNiOS.initialize(getAppIdJson(appId));
103
140
  }
104
141
  },
105
142
 
@@ -113,9 +150,7 @@ var ReactMoE = {
113
150
  setAppStatus: function (status: MoEAppStatus) {
114
151
  commonValidationCheck();
115
152
  console.log("Will track whether it is a fresh install or update.");
116
- let payload = {
117
- appStatus: MoEHelper.appStatusToString(status),
118
- };
153
+ let payload = getAppStatusJson(MoEHelper.appStatusToString(status),moeAppId);
119
154
  if (Platform.OS == PLATFORM_ANDROID) {
120
155
  MoERNAndroid.setAppStatus(payload);
121
156
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -130,22 +165,19 @@ var ReactMoE = {
130
165
  */
131
166
  trackEvent: function (eventName: String, properties: MoEProperties) {
132
167
  commonValidationCheck();
133
-
134
- if(properties == null) {
168
+
169
+ if (properties == null) {
135
170
  properties = new MoEProperties()
136
171
  }
137
-
172
+
138
173
  if (!(properties instanceof MoEProperties)) {
139
174
  showError("trackEvent: properties must of MoEProperties type");
140
175
  return;
141
176
  }
142
177
 
143
- console.log("trackEvent with properties", properties);
144
- //...(spread operator)it will append all the contents of the object/array into the target element
145
- let payload = {
146
- ...properties.toJSON(),
147
- eventName,
148
- };
178
+ console.log("trackEvent with properties", properties);
179
+ let payload= getMoEPropertiesJson(properties, eventName, moeAppId);
180
+
149
181
  if (Platform.OS == PLATFORM_ANDROID) {
150
182
  MoERNAndroid.trackEvent(payload);
151
183
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -160,11 +192,7 @@ var ReactMoE = {
160
192
  setUserUniqueID: function (uniqueId: string) {
161
193
  commonValidationCheck();
162
194
  console.log("Will set unique ID: " + uniqueId);
163
- const payload = MoEHelper.createUserAttributeParam(
164
- "USER_ATTRIBUTE_UNIQUE_ID",
165
- uniqueId,
166
- GENERAL
167
- );
195
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_UNIQUE_ID,uniqueId,GENERAL,moeAppId)
168
196
  if (Platform.OS == PLATFORM_ANDROID) {
169
197
  MoERNAndroid.setUserAttribute(payload);
170
198
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -179,9 +207,7 @@ var ReactMoE = {
179
207
  setAlias: function (alias: string) {
180
208
  commonValidationCheck();
181
209
  console.log("Will set alias: " + alias);
182
- let payload = {
183
- alias: alias,
184
- };
210
+ let payload = getAliasJson(alias,moeAppId);
185
211
  if (Platform.OS == PLATFORM_ANDROID) {
186
212
  MoERNAndroid.setAlias(payload);
187
213
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -196,11 +222,8 @@ var ReactMoE = {
196
222
  setUserName: function (userName: string) {
197
223
  commonValidationCheck();
198
224
  console.log("Will set username: " + userName);
199
- const payload = MoEHelper.createUserAttributeParam(
200
- "USER_ATTRIBUTE_USER_NAME",
201
- userName,
202
- GENERAL
203
- );
225
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_NAME,userName,GENERAL,moeAppId)
226
+
204
227
  if (Platform.OS == PLATFORM_ANDROID) {
205
228
  MoERNAndroid.setUserAttribute(payload);
206
229
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -215,11 +238,8 @@ var ReactMoE = {
215
238
  setUserFirstName: function (firstName: string) {
216
239
  commonValidationCheck();
217
240
  console.log("Will set first name: " + firstName);
218
- const payload = MoEHelper.createUserAttributeParam(
219
- "USER_ATTRIBUTE_USER_FIRST_NAME",
220
- firstName,
221
- GENERAL
222
- );
241
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_FIRST_NAME,firstName,GENERAL,moeAppId)
242
+
223
243
  if (Platform.OS == PLATFORM_ANDROID) {
224
244
  MoERNAndroid.setUserAttribute(payload);
225
245
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -234,11 +254,8 @@ var ReactMoE = {
234
254
  setUserLastName: function (lastName: string) {
235
255
  commonValidationCheck();
236
256
  console.log("Will set last name: " + lastName);
237
- const payload = MoEHelper.createUserAttributeParam(
238
- "USER_ATTRIBUTE_USER_LAST_NAME",
239
- lastName,
240
- GENERAL
241
- );
257
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_LAST_NAME,lastName,GENERAL,moeAppId)
258
+
242
259
  if (Platform.OS == PLATFORM_ANDROID) {
243
260
  MoERNAndroid.setUserAttribute(payload);
244
261
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -253,11 +270,8 @@ var ReactMoE = {
253
270
  setUserEmailID: function (emailId: string) {
254
271
  commonValidationCheck();
255
272
  console.log("Will set email-id " + emailId);
256
- const payload = MoEHelper.createUserAttributeParam(
257
- "USER_ATTRIBUTE_USER_EMAIL",
258
- emailId,
259
- GENERAL
260
- );
273
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_EMAIL,emailId,GENERAL,moeAppId)
274
+
261
275
  if (Platform.OS == PLATFORM_ANDROID) {
262
276
  MoERNAndroid.setUserAttribute(payload);
263
277
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -272,11 +286,8 @@ var ReactMoE = {
272
286
  setUserContactNumber: function (mobileNumber: string) {
273
287
  commonValidationCheck();
274
288
  console.log("Will set Mobile Number: " + mobileNumber);
275
- const payload = MoEHelper.createUserAttributeParam(
276
- "USER_ATTRIBUTE_USER_MOBILE",
277
- mobileNumber,
278
- GENERAL
279
- );
289
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_MOBILE,mobileNumber,GENERAL,moeAppId)
290
+
280
291
  if (Platform.OS == PLATFORM_ANDROID) {
281
292
  MoERNAndroid.setUserAttribute(payload);
282
293
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -291,11 +302,8 @@ var ReactMoE = {
291
302
  setUserBirthday: function (birthday: string) {
292
303
  commonValidationCheck();
293
304
  console.log("Will set birthday: " + birthday);
294
- const payload = MoEHelper.createUserAttributeParam(
295
- "USER_ATTRIBUTE_USER_BDAY",
296
- birthday,
297
- "timestamp"
298
- );
305
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_BDAY,birthday,TIMESTAMP,moeAppId)
306
+
299
307
  if (Platform.OS == PLATFORM_ANDROID) {
300
308
  MoERNAndroid.setUserAttribute(payload);
301
309
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -307,14 +315,12 @@ var ReactMoE = {
307
315
  * Sets the gender of the user.
308
316
  * @param gender gender to be set
309
317
  */
310
- setUserGender: function (gender) {
318
+ setUserGender: function (gender: Object) {
311
319
  commonValidationCheck();
312
320
  console.log("Will set gender: " + gender);
313
- const payload = MoEHelper.createUserAttributeParam(
314
- "USER_ATTRIBUTE_USER_GENDER",
315
- gender,
316
- GENERAL
317
- );
321
+
322
+ const payload = getUserAttributeJson(USER_ATTRIBUTE_USER_GENDER,gender,GENERAL,moeAppId)
323
+
318
324
  if (Platform.OS == PLATFORM_ANDROID) {
319
325
  MoERNAndroid.setUserAttribute(payload);
320
326
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -332,11 +338,8 @@ var ReactMoE = {
332
338
  showError("setUserLocation: location must of type MoEGeoLocation");
333
339
  return;
334
340
  }
335
- const payload = MoEHelper.createUserLocationAttributeParam(
336
- "USER_ATTRIBUTE_USER_LOCATION",
337
- location.latitude,
338
- location.longitude
339
- );
341
+ const payload = getUserLocAttributeJson(USER_ATTRIBUTE_USER_LOCATION,location.latitude,location.longitude,moeAppId)
342
+
340
343
  if (Platform.OS == PLATFORM_ANDROID) {
341
344
  MoERNAndroid.setUserAttribute(payload);
342
345
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -349,19 +352,16 @@ var ReactMoE = {
349
352
  * @param userAttributeName attribute name
350
353
  * @param userAttributeValue attribute value
351
354
  */
352
- setUserAttribute: function (userAttributeName: string, userAttributeValue) {
355
+ setUserAttribute: function (userAttributeName: string, userAttributeValue: Object) {
353
356
  commonValidationCheck();
354
357
  console.log(
355
358
  "Will track user attribute [attributeName]: " +
356
- userAttributeName +
357
- " attributeValue: " +
358
- userAttributeValue
359
- );
360
- const payload = MoEHelper.createUserAttributeParam(
361
- userAttributeName,
362
- userAttributeValue,
363
- GENERAL
359
+ userAttributeName +
360
+ " attributeValue: " +
361
+ userAttributeValue
364
362
  );
363
+ const payload = getUserAttributeJson(userAttributeName,userAttributeValue,GENERAL,moeAppId)
364
+
365
365
  if (Platform.OS == PLATFORM_ANDROID) {
366
366
  MoERNAndroid.setUserAttribute(payload);
367
367
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -379,11 +379,8 @@ var ReactMoE = {
379
379
  date: String
380
380
  ) {
381
381
  commonValidationCheck();
382
- const payload = MoEHelper.createUserAttributeParam(
383
- attributeName,
384
- date,
385
- "timestamp"
386
- );
382
+ const payload = getUserAttributeJson(attributeName,date,TIMESTAMP,moeAppId)
383
+
387
384
  if (Platform.OS == PLATFORM_ANDROID) {
388
385
  MoERNAndroid.setUserAttribute(payload);
389
386
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -407,11 +404,8 @@ var ReactMoE = {
407
404
  );
408
405
  return;
409
406
  }
410
- const payload = MoEHelper.createUserLocationAttributeParam(
411
- userAttributeName,
412
- location.latitude,
413
- location.longitude
414
- );
407
+ const payload = getUserLocAttributeJson(userAttributeName,location.latitude,location.longitude,moeAppId)
408
+
415
409
  if (Platform.OS == PLATFORM_ANDROID) {
416
410
  MoERNAndroid.setUserAttribute(payload);
417
411
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -426,9 +420,9 @@ var ReactMoE = {
426
420
  commonValidationCheck();
427
421
  console.log("Will logout user");
428
422
  if (Platform.OS == PLATFORM_ANDROID) {
429
- MoERNAndroid.logout();
423
+ MoERNAndroid.logout(getAppIdJson(moeAppId));
430
424
  } else if (Platform.OS == PLATFORM_IOS) {
431
- MoERNiOS.logout();
425
+ MoERNiOS.logout(getAppIdJson(moeAppId));
432
426
  }
433
427
  },
434
428
 
@@ -439,9 +433,9 @@ var ReactMoE = {
439
433
  commonValidationCheck();
440
434
  console.log("Will try to show in-app.");
441
435
  if (Platform.OS == PLATFORM_ANDROID) {
442
- MoERNAndroid.showInApp();
436
+ MoERNAndroid.showInApp(getAppIdJson(moeAppId));
443
437
  } else if (Platform.OS == PLATFORM_IOS) {
444
- MoERNiOS.showInApp();
438
+ MoERNiOS.showInApp(getAppIdJson(moeAppId));
445
439
  }
446
440
  },
447
441
 
@@ -451,25 +445,25 @@ var ReactMoE = {
451
445
  getSelfHandledInApp: function () {
452
446
  commonValidationCheck();
453
447
  if (Platform.OS == PLATFORM_ANDROID) {
454
- MoERNAndroid.getSelfHandledInApp();
448
+ MoERNAndroid.getSelfHandledInApp(getAppIdJson(moeAppId));
455
449
  } else if (Platform.OS == PLATFORM_IOS) {
456
- MoERNiOS.getSelfHandledInApp();
450
+ MoERNiOS.getSelfHandledInApp(getAppIdJson(moeAppId));
457
451
  }
458
452
  },
459
453
 
460
454
  /**
461
455
  * Call this method when you show the self handled in-app so we can update impressions.
462
- * @param {MoEInAppCampaign}campInfo : campaign information object
456
+ * @param {MoESelfHandledCampaignData}campInfo : campaign information object
463
457
  */
464
- selfHandledShown: function (inAppCampaign: MoEInAppCampaign) {
458
+ selfHandledShown: function (inAppCampaign: MoESelfHandledCampaignData) {
465
459
  commonValidationCheck();
466
- if (!(inAppCampaign instanceof MoEInAppCampaign)) {
460
+ if (!(inAppCampaign instanceof MoESelfHandledCampaignData)) {
467
461
  showError(
468
- "selfHandledShown: inAppCampaign must of MoEInAppCampaign type"
462
+ "selfHandledShown: inAppCampaign must of MoESelfHandledCampaignData type"
469
463
  );
470
464
  return;
471
465
  }
472
- let campaignJson = inAppCampaign.toJSON();
466
+ let campaignJson = getSelfHandledJson(inAppCampaign,"impression",moeAppId);
473
467
  if (Platform.OS == PLATFORM_ANDROID) {
474
468
  MoERNAndroid.selfHandledShown(campaignJson);
475
469
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -477,39 +471,19 @@ var ReactMoE = {
477
471
  }
478
472
  },
479
473
 
480
- /**
481
- * Call this method to track when self handled in app primary widget is clicked.
482
- * @param {MoEInAppCampaign}campInfo : campaign information object
483
- */
484
- selfHandledPrimaryClicked: function (inAppCampaign: MoEInAppCampaign) {
485
- commonValidationCheck();
486
- if (!(inAppCampaign instanceof MoEInAppCampaign)) {
487
- showError(
488
- "selfHandledClicked: inAppCampaign must of MoEInAppCampaign type"
489
- );
490
- return;
491
- }
492
- let campaignJson = inAppCampaign.toJSON();
493
- if (Platform.OS == PLATFORM_ANDROID) {
494
- MoERNAndroid.selfHandledPrimaryClicked(campaignJson);
495
- } else if (Platform.OS == PLATFORM_IOS) {
496
- MoERNiOS.selfHandledPrimaryClicked(campaignJson);
497
- }
498
- },
499
-
500
474
  /**
501
475
  * Call this method to track when self handled in app widget(other than Primary Widget) is clicked.
502
- * @param {MoEInAppCampaign}campInfo : campaign information object
476
+ * @param {MoESelfHandledCampaignData}campInfo : campaign information object
503
477
  */
504
- selfHandledClicked: function (inAppCampaign: MoEInAppCampaign) {
478
+ selfHandledClicked: function (moEClickData: MoESelfHandledCampaignData) {
505
479
  commonValidationCheck();
506
- if (!(inAppCampaign instanceof MoEInAppCampaign)) {
480
+ if (!(moEClickData instanceof MoESelfHandledCampaignData)) {
507
481
  showError(
508
- "selfHandledClicked: inAppCampaign must of MoEInAppCampaign type"
482
+ "selfHandledClicked: inAppCampaign must of MoEClickData type"
509
483
  );
510
484
  return;
511
485
  }
512
- let campaignJson = inAppCampaign.toJSON();
486
+ let campaignJson = getSelfHandledJson(moEClickData,"click",moeAppId);
513
487
  if (Platform.OS == PLATFORM_ANDROID) {
514
488
  MoERNAndroid.selfHandledClicked(campaignJson);
515
489
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -519,17 +493,17 @@ var ReactMoE = {
519
493
 
520
494
  /**
521
495
  * Call this method to track dismiss actions on the inApp.
522
- * @param {MoEInAppCampaign}campInfo : campaign information object
496
+ * @param {MoESelfHandledCampaignData}campInfo : campaign information object
523
497
  */
524
- selfHandledDismissed: function (inAppCampaign: MoEInAppCampaign) {
498
+ selfHandledDismissed: function (inAppCampaign: MoESelfHandledCampaignData) {
525
499
  commonValidationCheck();
526
- if (!(inAppCampaign instanceof MoEInAppCampaign)) {
500
+ if (!(inAppCampaign instanceof MoESelfHandledCampaignData)) {
527
501
  showError(
528
- "selfHandledDismissed: inAppCampaign must of MoEInAppCampaign type"
502
+ "selfHandledDismissed: inAppCampaign must of MoESelfHandledCampaignData type"
529
503
  );
530
504
  return;
531
505
  }
532
- let campaignJson = inAppCampaign.toJSON();
506
+ let campaignJson = getSelfHandledJson(inAppCampaign,"dismissed",moeAppId);
533
507
  if (Platform.OS == PLATFORM_ANDROID) {
534
508
  MoERNAndroid.selfHandledDismissed(campaignJson);
535
509
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -549,9 +523,7 @@ var ReactMoE = {
549
523
  );
550
524
  return;
551
525
  }
552
- let payload = {
553
- contexts: contexts,
554
- };
526
+ let payload = getInAppContextJson(contexts,moeAppId);
555
527
  if (Platform.OS == PLATFORM_ANDROID) {
556
528
  MoERNAndroid.setAppContext(payload);
557
529
  } else if (Platform.OS == PLATFORM_IOS) {
@@ -565,9 +537,9 @@ var ReactMoE = {
565
537
  resetCurrentContext: function () {
566
538
  commonValidationCheck();
567
539
  if (Platform.OS == PLATFORM_ANDROID) {
568
- MoERNAndroid.resetAppContext();
540
+ MoERNAndroid.resetAppContext(getAppIdJson(moeAppId));
569
541
  } else if (Platform.OS == PLATFORM_IOS) {
570
- MoERNiOS.resetAppContext();
542
+ MoERNiOS.resetAppContext(getAppIdJson(moeAppId));
571
543
  }
572
544
  },
573
545
 
@@ -580,8 +552,10 @@ var ReactMoE = {
580
552
  passFcmPushToken: function (pushToken: string) {
581
553
  commonValidationCheck();
582
554
  console.log("Will process push token");
555
+ let payload = getMoEPushTokenJson(pushToken,PUSH_SERVICE_FCM,PLATFORM_ANDROID,moeAppId);
556
+
583
557
  if (Platform.OS == PLATFORM_ANDROID) {
584
- MoERNAndroid.passFcmPushToken(pushToken);
558
+ MoERNAndroid.passFcmPushToken(payload);
585
559
  } else {
586
560
  console.log("This api is not supported on iOS platform.");
587
561
  }
@@ -595,23 +569,15 @@ var ReactMoE = {
595
569
  passFcmPushPayload: function (pushPayload: object) {
596
570
  commonValidationCheck();
597
571
  console.log("Will process push payload.");
572
+ let payload = getMoEPushCampaignJson(pushPayload,PUSH_SERVICE_FCM,moeAppId)
573
+
598
574
  if (Platform.OS == PLATFORM_ANDROID) {
599
- MoERNAndroid.passFcmPushPayload(pushPayload);
575
+ MoERNAndroid.passFcmPushPayload(payload);
600
576
  } else {
601
577
  console.log("This api is not supported on iOS platform.");
602
578
  }
603
579
  },
604
580
 
605
- enableSDKLogs: function () {
606
- commonValidationCheck();
607
- console.log("Enabling SDK logs");
608
- if (Platform.OS == PLATFORM_ANDROID) {
609
- MoERNAndroid.enableSDKLogs();
610
- } else if (Platform.OS == PLATFORM_IOS) {
611
- MoERNiOS.enableSDKLogs();
612
- }
613
- },
614
-
615
581
  /**
616
582
  * Call this method to register for push notification in iOS
617
583
  */
@@ -634,7 +600,7 @@ var ReactMoE = {
634
600
  if (Platform.OS == PLATFORM_ANDROID) {
635
601
  console.log("This api is not supported on android platform.");
636
602
  } else if (Platform.OS == PLATFORM_IOS) {
637
- MoERNiOS.disableInbox();
603
+ MoERNiOS.disableInbox(getAppIdJson(moeAppId));
638
604
  }
639
605
  },
640
606
 
@@ -645,74 +611,62 @@ var ReactMoE = {
645
611
  if (Platform.OS == PLATFORM_ANDROID) {
646
612
  //Android code
647
613
  } else if (Platform.OS == PLATFORM_IOS) {
648
- MoERNiOS.startGeofenceMonitoring();
614
+ MoERNiOS.startGeofenceMonitoring(getAppIdJson(moeAppId));
649
615
  }
650
616
  },
651
617
 
652
618
  optOutDataTracking: function (shouldOptOutDataTracking: boolean) {
653
619
  console.log("Will opt out data tracking");
620
+ let payload = getOptOutTrackingJson("data",shouldOptOutDataTracking,moeAppId);
654
621
  if (Platform.OS == PLATFORM_ANDROID) {
655
- MoERNAndroid.optOutDataTracking(shouldOptOutDataTracking);
656
- } else if (Platform.OS == PLATFORM_IOS) {
657
- MoERNiOS.optOutDataTracking(shouldOptOutDataTracking);
658
- }
659
- },
660
-
661
- optOutPushNotification: function (shouldOptOutPushNotification: boolean) {
662
- console.log("Will opt out push notifications");
663
- if (Platform.OS == PLATFORM_ANDROID) {
664
- MoERNAndroid.optOutPushNotification(shouldOptOutPushNotification);
665
- } else if (Platform.OS == PLATFORM_IOS) {
666
- MoERNiOS.optOutPushNotification(shouldOptOutPushNotification);
667
- }
668
- },
669
-
670
- optOutInAppNotification: function (shouldOptOutInApp: boolean) {
671
- console.log("Will opt out in-app notifications");
672
- if (Platform.OS == PLATFORM_ANDROID) {
673
- MoERNAndroid.optOutInAppNotification(shouldOptOutInApp);
622
+ MoERNAndroid.optOutDataTracking(payload);
674
623
  } else if (Platform.OS == PLATFORM_IOS) {
675
- MoERNiOS.optOutInAppNotification(shouldOptOutInApp);
624
+ MoERNiOS.optOutDataTracking(payload);
676
625
  }
677
626
  },
678
627
 
679
- /**
680
- * Pass the HMS PushKit push token to the MoEngage SDK.
681
- * Note: This API is only for Android platform and is a no-operation method for other plaforms.
682
- *
683
- * @param {String} pushToken
684
- */
685
- passPushKitPushToken: function (pushToken: string) {
628
+ /**
629
+ * Pass the HMS PushKit push token to the MoEngage SDK.
630
+ * Note: This API is only for Android platform and is a no-operation method for other plaforms.
631
+ *
632
+ * @param {String} pushToken
633
+ */
634
+ passPushKitPushToken: function (pushToken: string) {
686
635
  commonValidationCheck();
687
636
  console.log("Will process push-kit push token");
637
+ let payload = getMoEPushTokenJson(pushToken,PUSH_SERVICE_PUSH_KIT,PLATFORM_ANDROID,moeAppId);
638
+
688
639
  if (Platform.OS == PLATFORM_ANDROID) {
689
- MoERNAndroid.passPushKitPushToken(pushToken);
640
+ MoERNAndroid.passPushKitPushToken(payload);
690
641
  } else {
691
642
  console.log("This api is not supported on iOS platform.");
692
643
  }
693
644
  },
694
645
 
695
- enableSdk: function() {
646
+ enableSdk: function () {
696
647
  console.log("Will enable SDK");
697
- if(Platform.OS == PLATFORM_ANDROID) {
698
- MoERNAndroid.updateSdkState(true);
648
+ let payload = getSdkStateJson(true,moeAppId)
649
+ if (Platform.OS == PLATFORM_ANDROID) {
650
+ MoERNAndroid.updateSdkState(payload);
699
651
  } else if (Platform.OS == PLATFORM_IOS) {
700
- MoERNiOS.updateSdkState(true);
652
+ MoERNiOS.updateSdkState(payload);
701
653
  }
702
654
  },
703
655
 
704
- disableSdk: function() {
656
+ disableSdk: function () {
705
657
  console.log("Will disable SDK");
706
- if(Platform.OS == PLATFORM_ANDROID) {
707
- MoERNAndroid.updateSdkState(false);
658
+ let payload = getSdkStateJson(false,moeAppId)
659
+
660
+ if (Platform.OS == PLATFORM_ANDROID) {
661
+ MoERNAndroid.updateSdkState(payload);
708
662
  } else if (Platform.OS == PLATFORM_IOS) {
709
- MoERNiOS.updateSdkState(false);
663
+ MoERNiOS.updateSdkState(payload);
710
664
  }
711
665
  },
712
666
 
713
- onOrientationChanged: function() {
667
+ onOrientationChanged: function () {
714
668
  console.log("Will process screen rotation.");
715
- if(Platform.OS == PLATFORM_ANDROID) {
669
+ if (Platform.OS == PLATFORM_ANDROID) {
716
670
  MoERNAndroid.onOrientationChanged();
717
671
  }
718
672
  },
@@ -720,10 +674,12 @@ var ReactMoE = {
720
674
  /**
721
675
  * API to enable Advertising Id tracking for Android.
722
676
  */
723
- enableAdIdTracking: function() {
677
+ enableAdIdTracking: function () {
724
678
  console.log("Will enable advertising-id tracking");
725
- if(Platform.OS == PLATFORM_ANDROID) {
726
- MoERNAndroid.enableAdIdTracking();
679
+ let payload = getAdIdTrackingJson(true,moeAppId);
680
+
681
+ if (Platform.OS == PLATFORM_ANDROID) {
682
+ MoERNAndroid.enableAdIdTracking(payload);
727
683
  }
728
684
  },
729
685
 
@@ -733,20 +689,24 @@ var ReactMoE = {
733
689
  * By default Advertising Id tracking is disabled, call this method only if you have enabled
734
690
  * Advertising Id tracking at some point.
735
691
  */
736
- disableAdIdTracking: function() {
692
+ disableAdIdTracking: function () {
737
693
  console.log("Will disable advertising-id tracking");
738
- if(Platform.OS == PLATFORM_ANDROID) {
739
- MoERNAndroid.disableAdIdTracking();
694
+ let payload = getAdIdTrackingJson(false,moeAppId);
695
+
696
+ if (Platform.OS == PLATFORM_ANDROID) {
697
+ MoERNAndroid.disableAdIdTracking(payload);
740
698
  }
741
699
  },
742
700
 
743
701
  /**
744
702
  * API to enable Android Id tracking for Android.
745
703
  */
746
- enableAndroidIdTracking: function() {
704
+ enableAndroidIdTracking: function () {
747
705
  console.log("Will enable android-id tracking");
748
- if(Platform.OS == PLATFORM_ANDROID) {
749
- MoERNAndroid.enableAndroidIdTracking();
706
+ let payload = getAndroidIdTrackingJson(true,moeAppId);
707
+
708
+ if (Platform.OS == PLATFORM_ANDROID) {
709
+ MoERNAndroid.enableAndroidIdTracking(payload);
750
710
  }
751
711
  },
752
712
 
@@ -756,21 +716,49 @@ var ReactMoE = {
756
716
  * By default Android Id tracking is disabled, call this method only if you have enabled
757
717
  * Advertising Id tracking at some point.
758
718
  */
759
- disableAndroidIdTracking: function() {
719
+ disableAndroidIdTracking: function () {
760
720
  console.log("Will disable android-id tracking");
761
- if(Platform.OS == PLATFORM_ANDROID) {
762
- MoERNAndroid.disableAndroidIdTracking();
721
+ let payload = getAndroidIdTrackingJson(false,moeAppId);
722
+
723
+ if (Platform.OS == PLATFORM_ANDROID) {
724
+ MoERNAndroid.disableAndroidIdTracking(payload);
725
+ }
726
+ },
727
+
728
+ pushPermissionResponseAndroid: function (isGranted: boolean) {
729
+ console.log("Will track permission response");
730
+ if (Platform.OS == PLATFORM_ANDROID) {
731
+ MoERNAndroid.permissionResponse(isGranted, MoEngagePermissionType.PUSH)
732
+ }
733
+ },
734
+
735
+ setupNotificationChannelsAndroid: function () {
736
+ console.log("Will setup notification");
737
+ if (Platform.OS == PLATFORM_ANDROID) {
738
+ MoERNAndroid.setupNotificationChannels();
739
+ }
740
+ },
741
+
742
+ navigateToSettingsAndroid: function () {
743
+ console.log("Will navigate to settings");
744
+ if (Platform.OS == PLATFORM_ANDROID) {
745
+ MoERNAndroid.navigateToSettings();
746
+ }
747
+ },
748
+
749
+ requestPushPermissionAndroid: function () {
750
+ console.log("Will request push permission.");
751
+ if (Platform.OS == PLATFORM_ANDROID) {
752
+ MoERNAndroid.requestPushPermission();
763
753
  }
764
754
  }
765
-
766
755
 
767
756
  };
768
757
 
769
758
  export {
770
- MoEInAppCampaign,
771
759
  MoEInAppCustomAction,
772
760
  MoEInAppNavigation,
773
- MoEInAppSelfHandledCampaign,
761
+ MoESelfHandledCampaignData,
774
762
  MoEGeoLocation,
775
763
  MoEProperties,
776
764
  MoEAppStatus,