react-native-moengage 7.4.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +57 -3
  2. package/README.md +29 -6
  3. package/ReactNativeMoEngage.podspec +3 -3
  4. package/android/build.gradle +11 -12
  5. package/android/gradle/wrapper/gradle-wrapper.properties +3 -3
  6. package/android/gradle.properties +0 -1
  7. package/android/src/main/java/com/moengage/react/EventEmitterImpl.kt +46 -21
  8. package/android/src/main/java/com/moengage/react/MoEInitializer.kt +44 -13
  9. package/android/src/main/java/com/moengage/react/MoEReactBridge.kt +87 -80
  10. package/android/src/main/java/com/moengage/react/MoEReactHelper.kt +2 -2
  11. package/android/src/main/java/com/moengage/react/MoEReactPackage.kt +0 -1
  12. package/android/src/main/java/com/moengage/react/PayloadGenerator.kt +32 -17
  13. package/iOS/MoEReactBridge/MoEReactBridge.h +1 -1
  14. package/iOS/MoEReactBridge/MoEReactBridge.m +34 -60
  15. package/iOS/MoEReactBridge/{MOReactInitializer.h → MoEngageInitializer.h} +11 -11
  16. package/iOS/MoEReactBridge/MoEngageInitializer.m +153 -0
  17. package/iOS/MoEReactBridge/{MoEReactConstants.h → MoEngageReactConstants.h} +12 -3
  18. package/iOS/MoEReactBridge/{MoEReactConstants.m → MoEngageReactConstants.m} +13 -7
  19. package/iOS/MoEReactBridge/MoEngageReactPluginInfo.h +2 -0
  20. package/iOS/MoEReactBridge.xcodeproj/project.pbxproj +6 -6
  21. package/package.json +8 -3
  22. package/src/index.ts +169 -190
  23. package/src/models/MoEAccountMeta.ts +8 -0
  24. package/src/models/MoEAction.ts +4 -0
  25. package/src/models/MoEActionType.ts +4 -0
  26. package/src/models/MoECampaignContext.ts +10 -0
  27. package/src/models/MoECampaignData.ts +14 -0
  28. package/src/models/MoEClickData.ts +18 -0
  29. package/src/models/MoEGeoLocation.ts +2 -10
  30. package/src/models/MoEInAppCustomAction.ts +8 -13
  31. package/src/models/MoEInAppData.ts +16 -0
  32. package/src/models/MoEInAppNavigation.ts +14 -24
  33. package/src/models/MoENavigationType.ts +4 -0
  34. package/src/models/MoEPlatform.ts +4 -0
  35. package/src/models/MoEProperties.ts +19 -15
  36. package/src/models/MoEPushCampaign.ts +6 -22
  37. package/src/models/MoEPushPayload.ts +14 -0
  38. package/src/models/MoEPushService.ts +4 -4
  39. package/src/models/MoEPushToken.ts +6 -15
  40. package/src/models/MoESelfHandledCampaign.ts +10 -0
  41. package/src/models/MoESelfHandledCampaignData.ts +18 -0
  42. package/src/moeParser/MoEInAppParser.ts +192 -0
  43. package/src/moeParser/MoEPushNotificationParser.ts +78 -0
  44. package/src/platform/MoERNAndroid.ts +48 -76
  45. package/src/platform/MoERNiOS.ts +27 -60
  46. package/src/utils/MoEConstants.ts +59 -0
  47. package/src/utils/MoEEventHandlerHelper.ts +38 -25
  48. package/src/utils/MoEJsonBuilder.ts +220 -0
  49. package/src/utils/MoEObjectToJson.ts +44 -0
  50. package/iOS/MoEReactBridge/MOReactInitializer.m +0 -172
  51. package/iOS/MoEReactBridge/MOReactPluginInfo.h +0 -2
  52. package/src/models/MoEInAppCampaign.ts +0 -46
  53. package/src/models/MoEInAppSelfHandledCampaign.ts +0 -34
@@ -1,150 +1,122 @@
1
+ import { getAdIdTrackingJson, getAndroidIdTrackingJson, getAppIdJson, getMoEPushCampaignJson, getMoEPushTokenJson, getOptOutTrackingJson, getSdkStateJson } from "../utils/MoEJsonBuilder";
2
+
1
3
  const MoEReactBridge = require("react-native").NativeModules.MoEReactBridge;
4
+ const PLATFORM_ANDROID = "android";
2
5
 
3
6
  export class MoERNAndroid {
4
- static initialize() {
5
- MoEReactBridge.initialize();
7
+ static initialize(payload: { [k: string]: any }) {
8
+ MoEReactBridge.initialize(JSON.stringify(payload));
6
9
  }
7
10
 
8
- static trackEvent(payload: Object){
11
+ static trackEvent(payload: { [k: string]: any }) {
9
12
  MoEReactBridge.trackEvent(JSON.stringify(payload))
10
13
  }
11
14
 
12
- static setAppStatus(payload: object) {
15
+ static setAppStatus(payload: { [k: string]: any }) {
13
16
  MoEReactBridge.setAppStatus(JSON.stringify(payload));
14
17
  }
15
18
 
16
- static setUserAttribute(payload: object) {
19
+ static setUserAttribute(payload: { [k: string]: any }) {
17
20
  MoEReactBridge.setUserAttribute(JSON.stringify(payload));
18
21
  }
19
22
 
20
- static setAlias(payload: object){
23
+ static setAlias(payload: { [k: string]: any }) {
21
24
  MoEReactBridge.setAlias(JSON.stringify(payload));
22
25
  }
23
26
 
24
- static logout() {
25
- MoEReactBridge.logout();
27
+ static logout(payload: { [k: string]: any }) {
28
+ MoEReactBridge.logout(JSON.stringify(payload));
26
29
  }
27
30
 
28
- static showInApp() {
29
- MoEReactBridge.showInApp();
31
+ static showInApp(payload: { [k: string]: any }) {
32
+ MoEReactBridge.showInApp(JSON.stringify(payload));
30
33
  }
31
34
 
32
- static getSelfHandledInApp() {
33
- MoEReactBridge.getSelfHandledInApp();
35
+ static getSelfHandledInApp(payload: { [k: string]: any }) {
36
+ MoEReactBridge.getSelfHandledInApp(JSON.stringify(payload));
34
37
  }
35
38
 
36
- static selfHandledShown(payload: object) {
37
- payload["type"] = "impression";
39
+ static selfHandledShown(payload: { [k: string]: any }) {
38
40
  MoERNAndroid.selfHandledCallback(payload);
39
41
  }
40
42
 
41
- static selfHandledClicked(payload: object) {
42
- payload["type"] = "click";
43
+ static selfHandledClicked(payload: { [k: string]: any }) {
43
44
  MoERNAndroid.selfHandledCallback(payload);
44
45
  }
45
46
 
46
- static selfHandledDismissed(payload: object) {
47
- payload["type"] = "dismissed";
47
+ static selfHandledDismissed(payload: { [k: string]: any }) {
48
48
  MoERNAndroid.selfHandledCallback(payload);
49
49
  }
50
50
 
51
- static selfHandledPrimaryClicked(payload: object){
52
- payload["type"] = "primary_clicked";
53
- MoERNAndroid.selfHandledCallback(payload);
54
- }
55
-
56
- private static selfHandledCallback(payload: object){
51
+ private static selfHandledCallback(payload: { [k: string]: any }) {
57
52
  MoEReactBridge.selfHandledCallback(JSON.stringify(payload));
58
53
  }
59
54
 
60
- static setAppContext(payload: object) {
55
+ static setAppContext(payload: { [k: string]: any }) {
61
56
  MoEReactBridge.setAppContext(JSON.stringify(payload));
62
57
  }
63
58
 
64
- static resetAppContext() {
65
- MoEReactBridge.resetAppContext();
59
+ static resetAppContext(payload: { [k: string]: any }) {
60
+ MoEReactBridge.resetAppContext(JSON.stringify(payload));
66
61
  }
67
62
 
68
- static passFcmPushToken(pushToken: string) {
69
- let payload = {
70
- token: pushToken,
71
- service: PUSH_SERVICE_FCM
72
- };
63
+ static passFcmPushToken(payload: { [k: string]: any }) {
73
64
  MoERNAndroid.passPushToken(payload)
74
65
  }
75
66
 
76
- static passFcmPushPayload(pushPayload: object) {
77
- let payload = {
78
- payload: pushPayload,
79
- service: PUSH_SERVICE_FCM
80
- };
81
- MoERNAndroid.passPushPayload(payload)
67
+ static passFcmPushPayload(pushPayload: { [k: string]: any }) {
68
+ MoERNAndroid.passPushPayload(pushPayload)
82
69
  }
83
70
 
84
- private static passPushToken(payload: object){
71
+ private static passPushToken(payload: { [k: string]: any }) {
85
72
  MoEReactBridge.passPushToken(JSON.stringify(payload));
86
73
  }
87
74
 
88
- private static passPushPayload(payload: object){
75
+ private static passPushPayload(payload: { [k: string]: any }) {
89
76
  MoEReactBridge.passPushPayload(JSON.stringify(payload));
90
77
  }
91
78
 
92
- static enableSDKLogs() {
93
- MoEReactBridge.enableLogs();
94
- }
95
-
96
- static optOutDataTracking(shouldOptOutDataTracking: boolean){
97
- let payload = {
98
- type: "data",
99
- state: shouldOptOutDataTracking
100
- };
101
- MoERNAndroid.optOutTracking(payload)
102
- }
103
-
104
- static optOutPushNotification(shouldOptOutPushNotification: boolean){
105
- let payload = {
106
- type: "push",
107
- state: shouldOptOutPushNotification
108
- };
109
- MoERNAndroid.optOutTracking(payload)
110
- }
111
-
112
- static optOutInAppNotification(shouldOptOutInApp: boolean){
113
- let payload = {
114
- type: "inapp",
115
- state: shouldOptOutInApp
116
- };
79
+ static optOutDataTracking(payload: { [k: string]: any }) {
117
80
  MoERNAndroid.optOutTracking(payload)
118
81
  }
119
82
 
120
- private static optOutTracking(payload: object){
83
+ private static optOutTracking(payload: { [k: string]: any }) {
121
84
  MoEReactBridge.optOutTracking(JSON.stringify(payload));
122
85
  }
123
86
 
124
- static validateSDKVersion(){
87
+ static validateSDKVersion() {
125
88
  MoEReactBridge.validateSdkVersion().catch((error: Error) => {
126
89
  console.error(error.message);
127
90
  });
128
91
  }
129
92
 
130
- static passPushKitPushToken(pushToken: string) {
131
- let payload = {
132
- token: pushToken,
133
- service: PUSH_SERVICE_PUSH_KIT
134
- };
93
+ static passPushKitPushToken(payload: { [k: string]: any }) {
135
94
  MoERNAndroid.passPushToken(payload)
136
95
  }
137
96
 
138
- static updateSdkState(state: boolean) {
139
- let payload = {
140
- isSdkEnabled: state
141
- };
97
+ static updateSdkState(payload: { [k: string]: any }) {
142
98
  MoEReactBridge.updateSdkState(JSON.stringify(payload));
143
99
  }
144
100
 
145
101
  static onOrientationChanged() {
146
102
  MoEReactBridge.onOrientationChanged()
147
103
  }
104
+
105
+ static enableAdIdTracking(payload: { [k: string]: any }) {
106
+ MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
107
+ }
108
+
109
+ static disableAdIdTracking(payload: { [k: string]: any }) {
110
+ MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
111
+ }
112
+
113
+ static enableAndroidIdTracking(payload: { [k: string]: any }) {
114
+ MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
115
+ }
116
+
117
+ static disableAndroidIdTracking(payload: { [k: string]: any }) {
118
+ MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
119
+ }
148
120
  }
149
121
 
150
122
  const PUSH_SERVICE_FCM = "FCM"
@@ -1,76 +1,66 @@
1
+ import { getAppIdJson, getOptOutTrackingJson } from "../utils/MoEJsonBuilder";
2
+
1
3
  const MoEReactBridge = require("react-native").NativeModules.MoEReactBridge;
2
4
 
3
5
  export class MoERNiOS {
4
- static initialize() {
5
- MoEReactBridge.initialize();
6
+ static initialize(payload: { [k: string]: any }) {
7
+ MoEReactBridge.initialize(payload);
6
8
  }
7
9
 
8
- static setAppStatus(payload: Object) {
10
+ static setAppStatus(payload: { [k: string]: any }) {
9
11
  MoEReactBridge.setAppStatus(payload);
10
12
  }
11
13
 
12
- static trackEvent(payload: Object) {
14
+ static trackEvent(payload: { [k: string]: any }) {
13
15
  MoEReactBridge.trackEventWithProperties(payload);
14
16
  }
15
17
 
16
- static setUserAttribute(payload: Object) {
18
+ static setUserAttribute(payload: { [k: string]: any }) {
17
19
  MoEReactBridge.setUserAttribute(payload);
18
20
  }
19
21
 
20
- static setAlias(payload: Object) {
22
+ static setAlias(payload: { [k: string]: any }) {
21
23
  MoEReactBridge.setAlias(payload);
22
24
  }
23
25
 
24
- static logout() {
25
- MoEReactBridge.logout();
26
- }
27
-
28
- static showInApp() {
29
- MoEReactBridge.showInApp();
26
+ static logout(payload: { [k: string]: any }) {
27
+ MoEReactBridge.logout(payload);
30
28
  }
31
29
 
32
- static getSelfHandledInApp() {
33
- MoEReactBridge.getSelfHandledInApp();
30
+ static showInApp(payload: { [k: string]: any }) {
31
+ MoEReactBridge.showInApp(payload);
34
32
  }
35
33
 
36
- static selfHandledShown(payload: Object) {
37
- payload["type"] = "impression";
38
- MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
34
+ static getSelfHandledInApp(payload: { [k: string]: any }) {
35
+ MoEReactBridge.getSelfHandledInApp(payload);
39
36
  }
40
37
 
41
- static selfHandledPrimaryClicked(payload: Object) {
42
- payload["type"] = "primary_clicked";
38
+ static selfHandledShown(payload: { [k: string]: any }) {
43
39
  MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
44
40
  }
45
41
 
46
- static selfHandledClicked(payload: Object) {
47
- payload["type"] = "click";
42
+ static selfHandledClicked(payload: { [k: string]: any }) {
48
43
  MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
49
44
  }
50
45
 
51
- static selfHandledDismissed(payload: Object) {
52
- payload["type"] = "dismissed";
46
+ static selfHandledDismissed(payload: { [k: string]: any }) {
53
47
  MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
54
48
  }
55
49
 
56
- static setAppContext(payload: Object) {
50
+ static setAppContext(payload: { [k: string]: any }) {
57
51
  MoEReactBridge.setAppContext(payload);
58
52
  }
59
53
 
60
- static resetAppContext() {
61
- MoEReactBridge.resetAppContext();
54
+ static resetAppContext(payload: { [k: string]: any }) {
55
+ MoEReactBridge.resetAppContext(payload);
62
56
  }
63
57
 
64
58
  static registerForPush() {
65
59
  MoEReactBridge.registerForPushNotification();
66
60
  }
67
61
 
68
- static disableInbox() {
69
- MoEReactBridge.disableInbox();
70
- }
71
-
72
- static enableSDKLogs() {
73
- MoEReactBridge.enableSDKLogs();
62
+ static disableInbox(payload: { [k: string]: any }) {
63
+ MoEReactBridge.disableInbox(payload);
74
64
  }
75
65
 
76
66
  static validateSDKVersion() {
@@ -79,42 +69,19 @@ export class MoERNiOS {
79
69
  });
80
70
  }
81
71
 
82
- static startGeofenceMonitoring() {
83
- MoEReactBridge.startGeofenceMonitoring();
84
- }
85
-
86
- static optOutDataTracking(shouldOptOutDataTracking: boolean){
87
- let payload = {
88
- type: "data",
89
- state: shouldOptOutDataTracking
90
- };
91
- MoERNiOS.optOutTracking(payload)
92
- }
93
-
94
- static optOutPushNotification(shouldOptOutPushNotification: boolean){
95
- let payload = {
96
- type: "push",
97
- state: shouldOptOutPushNotification
98
- };
99
- MoERNiOS.optOutTracking(payload)
72
+ static startGeofenceMonitoring(payload: { [k: string]: any }) {
73
+ MoEReactBridge.startGeofenceMonitoring(payload);
100
74
  }
101
75
 
102
- static optOutInAppNotification(shouldOptOutInApp: boolean){
103
- let payload = {
104
- type: "inapp",
105
- state: shouldOptOutInApp
106
- };
76
+ static optOutDataTracking(payload: { [k: string]: any }){
107
77
  MoERNiOS.optOutTracking(payload)
108
78
  }
109
79
 
110
- private static optOutTracking(payload: object){
80
+ private static optOutTracking(payload: { [k: string]: any }){
111
81
  MoEReactBridge.optOutTracking(payload);
112
82
  }
113
83
 
114
- static updateSdkState(state: boolean) {
115
- let payload = {
116
- isSdkEnabled: state
117
- };
84
+ static updateSdkState(payload: { [k: string]: any }) {
118
85
  MoEReactBridge.updateSDKState(payload);
119
86
  }
120
87
  }
@@ -0,0 +1,59 @@
1
+ export const MOE_PLATFORM = 'platform'
2
+ export const MOE_PAYLOAD = 'payload'
3
+ export const MOE_DATA = 'data'
4
+ export const ACCOUNT_META = 'accountMeta'
5
+ export const APP_ID = 'appId'
6
+
7
+ //LOCATION ATTRIBUTE
8
+ export const MOE_LOCATION = 'location'
9
+
10
+ //INAPP CAMPAIGN
11
+ export const MOE_CAMPAIGN_ID = 'campaignId'
12
+ export const MOE_CAMPAIGN_NAME = 'campaignName'
13
+ export const MOE_CAMPAIGN_CONTEXT = 'campaignContext'
14
+ export const MOE_CUSTOM_ACTION = 'customAction'
15
+ export const MOE_SELF_HANDLED = 'selfHandled'
16
+ export const MOE_NAVIGATION = 'navigation'
17
+ export const MOE_WIDGET_ID = 'widgetId'
18
+ export const FORMATTED_CAMPAIGN_ID = 'cid'
19
+ export const ATTRIBUTES = 'attributes'
20
+
21
+ //IN APP CUSTOM ACTION
22
+ export const MOE_KEY_VALUE_PAIR = 'kvPair'
23
+
24
+ //IN APP SELF HANDLED
25
+ export const MOE_DISMISSINTERVAL = 'dismissInterval'
26
+ export const MOE_IS_CANCELLABLE = 'isCancellable'
27
+
28
+ //IN APP NAVIGATION
29
+ export const MOE_NAVIGATION_TYPE = 'navigationType'
30
+ export const ACTION_TYPE = 'actionType'
31
+ export const MOE_NAVIGATION_VALUE = 'value'
32
+
33
+ //PUSH TOKEN
34
+ export const MOE_PUSH_SERVICE = 'pushService'
35
+ export const MOE_TOKEN = 'token'
36
+
37
+ //PUSH CAMPAIGN
38
+ export const MOE_CLICKED_ACTION = 'clickedAction'
39
+ export const MOE_IS_DEFAULT_ACTION = 'isDefaultAction'
40
+
41
+ //INVALID OBJECT ERROR MESSAGES
42
+ export const MOE_IN_APP_OBJECT_ERROR = 'MoEInAppCampaign is an invalid object'
43
+ export const MOE_CUSTOM_ACTION_OBJ_ERROR = 'MoEInAppCustomAction is an invalid object'
44
+ export const MOE_SELF_HANDLED_OBJ_ERROR = 'MoEInAppSelfHandledCampaign is an invalid object'
45
+ export const MOE_NAVIGATION_OBJ_ERROR = 'MoEInAppNavigation is an invalid object'
46
+ export const MOE_PUSH_CAMPAIGN_OBJ_ERROR = 'MoEPushCampaign is an invalid object'
47
+ export const MOE_PUSH_TOKEN_OBJ_ERROR = 'MoEPushToken is an invalid object'
48
+ //USER ATTRIBUTES
49
+ export const USER_ATTRIBUTE_UNIQUE_ID = 'USER_ATTRIBUTE_UNIQUE_ID';
50
+ export const USER_ATTRIBUTE_USER_NAME = 'USER_ATTRIBUTE_USER_NAME';
51
+ export const USER_ATTRIBUTE_USER_FIRST_NAME = 'USER_ATTRIBUTE_USER_FIRST_NAME';
52
+ export const USER_ATTRIBUTE_USER_LAST_NAME = 'USER_ATTRIBUTE_USER_LAST_NAME';
53
+ export const USER_ATTRIBUTE_USER_EMAIL = 'USER_ATTRIBUTE_USER_EMAIL';
54
+ export const USER_ATTRIBUTE_USER_MOBILE = 'USER_ATTRIBUTE_USER_MOBILE';
55
+ export const USER_ATTRIBUTE_USER_BDAY = 'USER_ATTRIBUTE_USER_BDAY';
56
+ export const USER_ATTRIBUTE_USER_GENDER = 'USER_ATTRIBUTE_USER_GENDER';
57
+ export const USER_ATTRIBUTE_USER_LOCATION = 'USER_ATTRIBUTE_USER_LOCATION';
58
+
59
+
@@ -1,34 +1,47 @@
1
- import MoEInAppCampaign from "../models/MoEInAppCampaign";
2
- import MoEPushCampaign from "../models/MoEPushCampaign";
3
- import MoEPushToken from "../models/MoEPushToken";
4
- import { isValidObject, isValidString } from "../utils/MoEHelper";
5
-
6
- const inAppEventNames: Array<String> = [
7
- "inAppCampaignShown",
8
- "inAppCampaignClicked",
9
- "inAppCampaignDismissed",
10
- "inAppCampaignCustomAction",
11
- "inAppCampaignSelfHandled",
12
- ];
1
+ import { isValidObject } from "../utils/MoEHelper";
2
+ import { getCustomActionObj, getMoEInAppData, getNavigationObj, getMoESelfHandledCampaignData } from "../moeParser/MoEInAppParser";
3
+ import { getMoEPushPayload, getMoEPushToken } from "../moeParser/MoEPushNotificationParser";
4
+ import { MOE_DATA,ACCOUNT_META, MOE_PAYLOAD } from "./MoEConstants";
13
5
 
14
6
  export function executeHandler(
15
7
  handler: Function,
16
- notification: Object,
8
+ notification: any,
17
9
  type: String
18
10
  ) {
19
- if (handler && isValidObject(notification) && type) {
20
- const payload = notification["payload"];
21
- if (isValidString(payload)) {
22
- const json = JSON.parse(payload);
23
- if (isValidObject(json)) {
24
- if (inAppEventNames.includes(type)) {
25
- handler(new MoEInAppCampaign(json));
26
- } else if (type == "pushClicked") {
27
- handler(new MoEPushCampaign(json));
28
- } else if (type == "pushTokenGenerated") {
29
- handler(new MoEPushToken(json));
11
+ if (handler && type) {
12
+ const payload = notification[MOE_PAYLOAD];
13
+ const notificationPayload = JSON.parse(payload);
14
+ if (isValidObject(notificationPayload)) {
15
+ if (type == "pushTokenGenerated") {
16
+ var pushTokenObject = getMoEPushToken(notificationPayload);
17
+ pushTokenObject != undefined ? handler(pushTokenObject) : null;
18
+ }
19
+ else{
20
+ const accountMeta = notificationPayload[ACCOUNT_META];
21
+ if (accountMeta != undefined && isValidObject(accountMeta)) {
22
+ const payload = notificationPayload[MOE_DATA];
23
+ if (type == "inAppCampaignShown"||type == "inAppCampaignDismissed") {
24
+ var inAppObject = getMoEInAppData(payload,accountMeta);
25
+ inAppObject != undefined ? handler(inAppObject) : null;
26
+ }
27
+ else if (type == "inAppCampaignSelfHandled") {
28
+ var selfHandled = getMoESelfHandledCampaignData(payload,accountMeta);
29
+ selfHandled != undefined ? handler(selfHandled) : null;
30
+ }
31
+ else if(type == "inAppCampaignCustomAction"){
32
+ var cutomAction = getCustomActionObj(payload,accountMeta);
33
+ cutomAction != undefined ? handler(cutomAction) : null;
34
+ }
35
+ else if(type == "inAppCampaignClicked"){
36
+ var navigationAction = getNavigationObj(payload,accountMeta);
37
+ navigationAction != undefined ? handler(navigationAction) : null;
30
38
  }
39
+ else if (type == "pushClicked") {
40
+ var pushCampaignObject = getMoEPushPayload(payload,accountMeta);
41
+ pushCampaignObject != undefined ? handler(pushCampaignObject) : null;
42
+ }
31
43
  }
32
- }
44
+
45
+ }}
33
46
  }
34
47
  }
@@ -0,0 +1,220 @@
1
+ import MoEClickData from "../models/MoEClickData";
2
+ import MoEInAppData from "../models/MoEInAppData";
3
+ import MoEProperties from "../models/MoEProperties";
4
+ import MoESelfHandledCampaignData from "../models/MoESelfHandledCampaignData";
5
+ import { MOE_LOCATION } from "./MoEConstants";
6
+ import { MoEPropertiesToJson} from "./MoEObjectToJson";
7
+
8
+ export function getInAppCampaignJson(moEInAppData: MoEInAppData, type: string, appId: String) {
9
+ var json: { [k: string]: any } = {
10
+ accountMeta: {
11
+ appId: appId
12
+ },
13
+ data: {
14
+ type: type,
15
+ campaignName: moEInAppData.campaignData.campaignName,
16
+ campaignId: moEInAppData.campaignData.campaignId,
17
+ campaignContext: moEInAppData.campaignData.context,
18
+ platform: moEInAppData.platform
19
+ }
20
+ }
21
+ return json;
22
+ }
23
+
24
+ export function getSelfHandledJson(moESelfHandledCampaignData: MoESelfHandledCampaignData, type: string, appId: String) {
25
+ var json: { [k: string]: any } = {
26
+ accountMeta: {
27
+ appId: appId
28
+ },
29
+ data: {
30
+ type: type,
31
+ campaignName: moESelfHandledCampaignData.campaignData.campaignName,
32
+ campaignId: moESelfHandledCampaignData.campaignData.campaignId,
33
+ campaignContext: moESelfHandledCampaignData.campaignData.context.attributes,
34
+ selfHandled: moESelfHandledCampaignData.campaign,
35
+ platform: moESelfHandledCampaignData.platform
36
+ }
37
+ }
38
+ console.log("getSelfHandledJson(): payload json: ", json)
39
+ return json;
40
+ }
41
+
42
+ export function getInAppClickDataJson(moEClickData: MoEClickData, type: string, appId: String) {
43
+ var json: { [k: string]: any } = {
44
+ accountMeta: {
45
+ appId: appId
46
+ },
47
+ data: {
48
+ type: type,
49
+ campaignName: moEClickData.campaignData.campaignName,
50
+ campaignId: moEClickData.campaignData.campaignId,
51
+ campaignContext: moEClickData.campaignData.context,
52
+ platform: moEClickData.platform
53
+ }
54
+ }
55
+ return json;
56
+ }
57
+
58
+ export function getMoEPropertiesJson(moEProperties: MoEProperties, eventName: String, appId: String) {
59
+ var json: { [k: string]: any } = {
60
+ accountMeta: {
61
+ appId: appId
62
+ },
63
+ data: {
64
+ ...MoEPropertiesToJson(moEProperties),
65
+ eventName,
66
+ }
67
+ }
68
+ return json;
69
+ }
70
+
71
+ export function getMoEPushCampaignJson(pushPayload: object, service: string, appId: String) {
72
+ var json: { [k: string]: any } = {
73
+ accountMeta: {
74
+ appId: appId
75
+ },
76
+ data: {
77
+ payload: pushPayload,
78
+ service:service
79
+ }
80
+ }
81
+ return json;
82
+ }
83
+
84
+ export function getMoEPushTokenJson(pushToken: string, pushService: string, platform: string, appId: String) {
85
+ var json: { [k: string]: any} = {
86
+ accountMeta: {
87
+ appId: appId
88
+ },
89
+ data: {
90
+ token: pushToken,
91
+ service: pushService,
92
+ platform: platform
93
+
94
+ }
95
+ }
96
+ return json;
97
+ }
98
+
99
+ export function getAliasJson(alias: String, appId: String) {
100
+ var json: { [k: string]: any } = {
101
+ accountMeta: {
102
+ appId: appId
103
+ },
104
+ data:
105
+ { alias: alias }
106
+ }
107
+ return json;
108
+ }
109
+ export function getAppStatusJson(appStatus: String, appId: String) {
110
+ var json: { [k: string]: any } = {
111
+ accountMeta: {
112
+ appId: appId
113
+ },
114
+ data: {
115
+ appStatus: appStatus
116
+ }
117
+ }
118
+ return json;
119
+ }
120
+
121
+ export function getUserAttributeJson(name: String, value: String | object, type: String, appId: String) {
122
+ var json: { [k: string]: any } = {
123
+ accountMeta: {
124
+ appId: appId
125
+ },
126
+ data: {
127
+ attributeName: name,
128
+ attributeValue: value,
129
+ type: type,
130
+ }
131
+ }
132
+ return json;
133
+ }
134
+ export function getUserLocAttributeJson(name: String, latitude: Number, longitude: Number, appId: String) {
135
+ var json: { [k: string]: any } = {
136
+ accountMeta: {
137
+ appId: appId
138
+ },
139
+ data: {
140
+ attributeName: name,
141
+ type: MOE_LOCATION,
142
+ locationAttribute: {
143
+ latitude: latitude,
144
+ longitude: longitude,
145
+ }
146
+ }
147
+ }
148
+ return json;
149
+ }
150
+
151
+ export function getInAppContextJson(contexts: Array<String>, appId: String) {
152
+ var json: { [k: string]: any } = {
153
+ accountMeta: {
154
+ appId: appId
155
+ },
156
+ data: {
157
+ contexts: contexts
158
+ }
159
+ }
160
+ return json;
161
+ }
162
+
163
+ export function getSdkStateJson(isSdkEnabled: Boolean, appId: String) {
164
+ var json: { [k: string]: any } = {
165
+ accountMeta: {
166
+ appId: appId
167
+ },
168
+ data: {
169
+ isSdkEnabled: isSdkEnabled,
170
+
171
+ }
172
+ }
173
+ return json;
174
+ }
175
+
176
+ export function getAdIdTrackingJson(isAdIdTrackingEnabled: Boolean, appId: String) {
177
+ var json: { [k: string]: any } = {
178
+ accountMeta: {
179
+ appId: appId
180
+ },
181
+ data: {
182
+ isAdIdTrackingEnabled: isAdIdTrackingEnabled,
183
+ }
184
+ }
185
+ return json;
186
+ }
187
+
188
+ export function getAndroidIdTrackingJson(isAndroidIdTrackingEnabled: Boolean, appId: String) {
189
+ var json: { [k: string]: any } = {
190
+ accountMeta: {
191
+ appId: appId
192
+ },
193
+ data: {
194
+ isAndroidIdTrackingEnabled: isAndroidIdTrackingEnabled
195
+ }
196
+ }
197
+ return json;
198
+ }
199
+
200
+ export function getAppIdJson(appId: String) {
201
+ var json: { [k: string]: any } = {
202
+ accountMeta: {
203
+ appId: appId
204
+ }
205
+ }
206
+ return json;
207
+ }
208
+
209
+ export function getOptOutTrackingJson(type: string, state: boolean, appId: string) {
210
+ var json: { [k: string]: any } = {
211
+ accountMeta: {
212
+ appId: appId
213
+ },
214
+ data: {
215
+ type: type,
216
+ state: state
217
+ }
218
+ }
219
+ return json;
220
+ }