react-native-moengage 8.2.0 → 8.4.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 16-02-2023
2
+
3
+ ## 8.4.0
4
+ - iOS
5
+ - MoEngage-iOS-SDK version updated to `~>9.4.0`.
6
+
7
+ # 09-02-2023
8
+
9
+ ## 8.3.0
10
+ - Android
11
+ - Android 13 push notification Opt-in with rationale via In-Apps
12
+ - Device Id enable / disable support
13
+ - BugFix
14
+ - Adding PushClick Callback Redirection Support if Application is in Foreground/Background State
15
+
1
16
  # 16-01-2023
2
17
 
3
18
  ## 8.2.0
@@ -15,8 +15,8 @@ Pod::Spec.new do |s|
15
15
  s.platform = :ios, "10.0"
16
16
  s.source_files = 'iOS/MoEReactBridge/**/*.{h,m}'
17
17
  s.dependency 'React'
18
- s.dependency 'MoEngagePluginBase','>= 4.0.0','< 4.1.0'
19
- s.dependency 'MoEngageRichNotification','>= 7.2.0','< 7.3.0'
18
+ s.dependency 'MoEngagePluginBase','>= 4.1.0','< 4.2.0'
19
+ s.dependency 'MoEngageRichNotification','>= 7.4.0','< 7.5.0'
20
20
 
21
21
  s.prepare_command = <<-CMD
22
22
  echo // Generated file, do not edit > iOS/MoEReactBridge/MoEngageReactPluginInfo.h
@@ -20,9 +20,9 @@ rootProject.allprojects {
20
20
 
21
21
  ext {
22
22
  //dependency version
23
- moengageCoreVersion = "12.4.00"
24
- moengageInAppVersion = "6.4.0"
25
- basePluginVersion = "3.1.0"
23
+ moengageCoreVersion = "12.6.00"
24
+ moengageInAppVersion = "6.5.0"
25
+ basePluginVersion = "3.2.0"
26
26
  //build versions
27
27
  minimumVersion = 21
28
28
  targetVersion = 31
@@ -2,10 +2,12 @@ package com.moengage.react
2
2
 
3
3
  import com.facebook.react.bridge.ReactContext
4
4
  import com.facebook.react.bridge.WritableMap
5
+ import com.facebook.react.common.LifecycleState
5
6
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
7
  import com.moengage.core.LogLevel
7
8
  import com.moengage.core.internal.logger.Logger
8
9
  import com.moengage.plugin.base.internal.EventEmitter
10
+ import com.moengage.plugin.base.internal.instanceMetaFromJson
9
11
  import com.moengage.plugin.base.internal.model.events.Event
10
12
  import com.moengage.plugin.base.internal.model.events.EventType
11
13
  import com.moengage.plugin.base.internal.model.events.inapp.InAppActionEvent
@@ -14,6 +16,7 @@ import com.moengage.plugin.base.internal.model.events.inapp.InAppSelfHandledEven
14
16
  import com.moengage.plugin.base.internal.model.events.push.PermissionEvent
15
17
  import com.moengage.plugin.base.internal.model.events.push.PushClickedEvent
16
18
  import com.moengage.plugin.base.internal.model.events.push.TokenEvent
19
+ import org.json.JSONObject
17
20
 
18
21
 
19
22
  /**
@@ -66,6 +69,13 @@ class EventEmitterImpl(private val reactContext: ReactContext) : EventEmitter {
66
69
  Logger.print { "$tag emitPushClicked() : $event" }
67
70
  val eventName = eventMapping[event.eventType] ?: return
68
71
  val payload = PayloadGenerator().pushPayloadToWriteableMap(event.payload)
72
+ if (GlobalCache.lifecycleAwarePushCallbackEnabled
73
+ && reactContext.lifecycleState != LifecycleState.RESUMED
74
+ ) {
75
+ Logger.print { "$tag emitPushClicked() : ${reactContext.lifecycleState}" }
76
+ GlobalCache.addPushClickedEventToCache(payload)
77
+ return
78
+ }
69
79
  emit(eventName, payload)
70
80
  }
71
81
 
@@ -91,6 +101,16 @@ class EventEmitterImpl(private val reactContext: ReactContext) : EventEmitter {
91
101
  val payload = PayloadGenerator().permissionResultToWriteableMap(event.result)
92
102
  emit(eventName, payload)
93
103
  }
104
+
105
+ internal fun emitPendingEvents() {
106
+ if (GlobalCache.lifecycleAwarePushCallbackEnabled) {
107
+ val cachedPushClickedEvent = GlobalCache.getPushClickedCachedEvent() ?: return
108
+ val eventName = eventMapping[EventType.PUSH_CLICKED] ?: return
109
+ GlobalCache.removePushClickedEventFromCache()
110
+
111
+ emit(eventName, cachedPushClickedEvent)
112
+ }
113
+ }
94
114
  }
95
115
 
96
116
  val eventMapping = mapOf<EventType, String>(
@@ -0,0 +1,25 @@
1
+ package com.moengage.react
2
+
3
+ import com.facebook.react.bridge.WritableMap
4
+
5
+ object GlobalCache {
6
+
7
+ var lifecycleAwarePushCallbackEnabled = false
8
+ internal set
9
+
10
+ private var pushClickedCachedEvent: WritableMap? = null
11
+
12
+ fun getPushClickedCachedEvent(): WritableMap? {
13
+ return pushClickedCachedEvent
14
+ }
15
+
16
+ internal fun addPushClickedEventToCache(
17
+ pushClickedEvent: WritableMap
18
+ ) {
19
+ this.pushClickedCachedEvent = pushClickedEvent
20
+ }
21
+
22
+ internal fun removePushClickedEventFromCache() {
23
+ pushClickedCachedEvent = null
24
+ }
25
+ }
@@ -40,9 +40,15 @@ object MoEInitializer {
40
40
  initializeDefaultInstance(context, builder, sdkState)
41
41
  }
42
42
 
43
- fun initializeDefaultInstance(context: Context, builder: MoEngage.Builder) {
43
+ @JvmOverloads
44
+ fun initializeDefaultInstance(
45
+ context: Context,
46
+ builder: MoEngage.Builder,
47
+ lifecycleAwarePushCallbackEnabled: Boolean = false
48
+ ) {
44
49
  try {
45
50
  Logger.print { "$tag initialize() : Will try to initialize the sdk." }
51
+ GlobalCache.lifecycleAwarePushCallbackEnabled = lifecycleAwarePushCallbackEnabled
46
52
  PluginInitializer.initialize(
47
53
  builder,
48
54
  IntegrationMeta(INTEGRATION_TYPE, BuildConfig.MOENGAGE_REACT_LIBRARY_VERSION)
@@ -52,9 +58,16 @@ object MoEInitializer {
52
58
  }
53
59
  }
54
60
 
55
- fun initializeDefaultInstance(context: Context, builder: MoEngage.Builder, sdkState: SdkState) {
61
+ @JvmOverloads
62
+ fun initializeDefaultInstance(
63
+ context: Context,
64
+ builder: MoEngage.Builder,
65
+ sdkState: SdkState,
66
+ lifecycleAwarePushCallbackEnabled: Boolean = false
67
+ ) {
56
68
  try {
57
69
  Logger.print { "$tag initialize() : Initialising MoEngage SDK." }
70
+ GlobalCache.lifecycleAwarePushCallbackEnabled = lifecycleAwarePushCallbackEnabled
58
71
  PluginInitializer.initialize(
59
72
  builder,
60
73
  IntegrationMeta(INTEGRATION_TYPE, BuildConfig.MOENGAGE_REACT_LIBRARY_VERSION),
@@ -6,8 +6,8 @@ import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.bridge.ReactContextBaseJavaModule
7
7
  import com.facebook.react.bridge.ReactMethod
8
8
  import com.moengage.core.LogLevel
9
- import com.moengage.core.internal.LIB_VERSION
10
9
  import com.moengage.core.internal.logger.Logger
10
+ import com.moengage.core.internal.utils.getSdkVersion
11
11
  import com.moengage.plugin.base.internal.PluginHelper
12
12
  import com.moengage.plugin.base.internal.setEventEmitter
13
13
 
@@ -21,6 +21,7 @@ class MoEReactBridge(private val reactContext: ReactApplicationContext) :
21
21
 
22
22
  private val context: Context = reactContext.applicationContext
23
23
  private val pluginHelper = PluginHelper()
24
+ private val moeSdkVersion = getSdkVersion()
24
25
 
25
26
  override fun getName(): String {
26
27
  return "MoEReactBridge"
@@ -151,7 +152,9 @@ class MoEReactBridge(private val reactContext: ReactApplicationContext) :
151
152
  try {
152
153
  Logger.print { "$tag initialize() : " }
153
154
  pluginHelper.initialise(payload)
154
- setEventEmitter(EventEmitterImpl(reactContext))
155
+ val eventEmitterImpl = EventEmitterImpl(reactContext)
156
+ eventEmitterImpl.emitPendingEvents()
157
+ setEventEmitter(eventEmitterImpl)
155
158
  } catch (t: Throwable) {
156
159
  Logger.print(LogLevel.ERROR, t) { "$tag initialize() : " }
157
160
  }
@@ -179,7 +182,7 @@ class MoEReactBridge(private val reactContext: ReactApplicationContext) :
179
182
  @ReactMethod
180
183
  fun validateSdkVersion(promise: Promise) {
181
184
  Logger.print { "$tag validateSdkVersion() : Validating Version" }
182
- if (LIB_VERSION > 13000) {
185
+ if (moeSdkVersion > 13000) {
183
186
  Logger.print(LogLevel.ERROR) { "$tag validateSdkVersion() : invalid version" }
184
187
  promise.reject("error", "Use SDK version 12.x.xx")
185
188
  } else {
@@ -254,4 +257,14 @@ class MoEReactBridge(private val reactContext: ReactApplicationContext) :
254
257
  Logger.print(LogLevel.ERROR, t) { "$tag permissionResponse() :" }
255
258
  }
256
259
  }
260
+
261
+ @ReactMethod
262
+ fun updatePushPermissionRequestCount(payload: String) {
263
+ try {
264
+ Logger.print { "$tag updatePushPermissionRequestCount() : Payload: $payload" }
265
+ pluginHelper.updatePushPermissionRequestCount(context, payload)
266
+ } catch (t: Throwable) {
267
+ Logger.print(LogLevel.ERROR, t) { "$tag updatePushPermissionRequestCount() :" }
268
+ }
269
+ }
257
270
  }
@@ -9,6 +9,7 @@
9
9
  #import "MoEngageReactPluginInfo.h"
10
10
  #import "MoEngageReactConstants.h"
11
11
  #import "MoEReactBridge.h"
12
+ #import "MoEngageReactUtils.h"
12
13
  #import <MoEngageSDK/MoEngageSDK.h>
13
14
  #import <MoEngageObjCUtils/MoEngageObjCUtils.h>
14
15
  @import MoEngagePluginBase;
@@ -100,19 +101,19 @@
100
101
  }
101
102
 
102
103
  if ([moeDict objectForKey:kDisablePeriodicFlush] != nil && [moeDict objectForKey:kDisablePeriodicFlush] != [NSNull null]) {
103
- sdkConfig.analyticsDisablePeriodicFlush = [moeDict getBooleanForKey:kDisablePeriodicFlush];
104
+ sdkConfig.analyticsDisablePeriodicFlush = [MoEngageReactUtils getBooleanForKey:kDisablePeriodicFlush dict:moeDict];
104
105
  }
105
106
 
106
107
  if ([moeDict objectForKey:kPeriodicFlushDuration] != nil && [moeDict objectForKey:kPeriodicFlushDuration] != [NSNull null]) {
107
- sdkConfig.analyticsPeriodicFlushDuration = [moeDict getIntegerForKey:kPeriodicFlushDuration];
108
+ sdkConfig.analyticsPeriodicFlushDuration = [MoEngageReactUtils getIntegerForKey:kPeriodicFlushDuration dict:moeDict];
108
109
  }
109
110
 
110
111
  if ([moeDict objectForKey:kEncryptNetworkRequests] != nil && [moeDict objectForKey:kEncryptNetworkRequests] != [NSNull null]) {
111
- sdkConfig.encryptNetworkRequests = [moeDict getBooleanForKey:kDisablePeriodicFlush];
112
+ sdkConfig.encryptNetworkRequests = [MoEngageReactUtils getBooleanForKey:kEncryptNetworkRequests dict:moeDict];
112
113
  }
113
114
 
114
115
  if ([moeDict objectForKey:kEnableLogs] != nil && [moeDict objectForKey:kEnableLogs] != [NSNull null]) {
115
- sdkConfig.enableLogs = [moeDict getBooleanForKey:kEnableLogs];
116
+ sdkConfig.enableLogs = [MoEngageReactUtils getBooleanForKey:kEnableLogs dict:moeDict];
116
117
  }
117
118
  }
118
119
 
@@ -0,0 +1,14 @@
1
+ //
2
+ // MoEngageReactUtils.h
3
+ // Pods
4
+ //
5
+ // Created by Rakshitha on 14/02/23.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <UIKit/UIKit.h>
10
+
11
+ @interface MoEngageReactUtils : NSObject
12
+ +(NSInteger)getIntegerForKey:(NSString *)key dict:(NSDictionary*)dict;
13
+ +(BOOL)getBooleanForKey:(NSString *)key dict:(NSDictionary*)dict;
14
+ @end
@@ -0,0 +1,40 @@
1
+ //
2
+ // MoEngageReactUtils.m
3
+ // CocoaAsyncSocket
4
+ //
5
+ // Created by Rakshitha on 14/02/23.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import "MoEngageReactUtils.h"
10
+
11
+ @implementation MoEngageReactUtils
12
+ +(NSInteger)getIntegerForKey:(NSString *)key dict:(NSDictionary*)dict {
13
+
14
+ NSString *value = [self stringForkey:key dict:dict];
15
+ if (value == NULL) {
16
+ return -1;
17
+ }
18
+ return [value integerValue];
19
+ }
20
+
21
+ +(NSString * __nullable)stringForkey:(NSString *)key dict:(NSDictionary*)dict {
22
+ if (key == NULL || key.length == 0) {
23
+ return NULL;
24
+ }
25
+ id value = [dict objectForKey:key];
26
+ if (value) {
27
+ return [NSString stringWithFormat:@"%@", value];
28
+ }
29
+ return NULL;
30
+ }
31
+
32
+ +(BOOL)getBooleanForKey:(NSString *)key dict:(NSDictionary*)dict {
33
+
34
+ NSString *value = [self stringForkey:key dict:dict];
35
+ if (value == NULL) {
36
+ return NO;
37
+ }
38
+ return [value boolValue];
39
+ }
40
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-moengage",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
4
4
  "description": "MoEngage is a mobile marketing automation company. This react-native SDK helps you track events, trigger smart notifications and in-apps, provides a drop-in Inbox Controller for notifications.",
5
5
  "main": "src/index.ts",
6
6
  "keywords": [
package/src/index.ts CHANGED
@@ -24,7 +24,9 @@ import {
24
24
  getSdkStateJson,
25
25
  getSelfHandledJson,
26
26
  getUserAttributeJson,
27
- getUserLocAttributeJson
27
+ getUserLocAttributeJson,
28
+ getPushPermissionRequestCountJson,
29
+ getDeviceIdTrackingJson
28
30
  } from "./utils/MoEJsonBuilder";
29
31
  import {
30
32
  USER_ATTRIBUTE_UNIQUE_ID,
@@ -751,6 +753,47 @@ var ReactMoE = {
751
753
  if (Platform.OS == PLATFORM_ANDROID) {
752
754
  MoERNAndroid.requestPushPermission();
753
755
  }
756
+ },
757
+
758
+ /**
759
+ * API to update push permission request count. The count will be incremented on every call.
760
+ * Note: This API is only for Android platform and is a no-operation method for other plaforms.
761
+ *
762
+ * @param {number} count - number of times push permission requested
763
+ */
764
+ updatePushPermissionRequestCountAndroid: function (count: number) {
765
+ console.log("Will increment push permission request count");
766
+ let payload = getPushPermissionRequestCountJson(count, moeAppId);
767
+
768
+ if (Platform.OS == PLATFORM_ANDROID) {
769
+ MoERNAndroid.updatePushPermissionRequestCount(payload);
770
+ }
771
+ },
772
+
773
+ /**
774
+ * API to enable Device Id tracking for Android.
775
+ *
776
+ * Note: By default Device Id tracking is enabled
777
+ */
778
+ enableDeviceIdTracking: function () {
779
+ console.log("Will enable device id tracking");
780
+ let payload = getDeviceIdTrackingJson(true, moeAppId);
781
+
782
+ if (Platform.OS == PLATFORM_ANDROID) {
783
+ MoERNAndroid.enableDeviceIdTracking(payload);
784
+ }
785
+ },
786
+
787
+ /**
788
+ * API to disable Device Id tracking for Android.
789
+ */
790
+ disableDeviceIdTracking: function () {
791
+ console.log("Will disable device id tracking");
792
+ let payload = getDeviceIdTrackingJson(false, moeAppId);
793
+
794
+ if (Platform.OS == PLATFORM_ANDROID) {
795
+ MoERNAndroid.disableDeviceIdTracking(payload);
796
+ }
754
797
  }
755
798
 
756
799
  };
@@ -143,6 +143,18 @@ export class MoERNAndroid {
143
143
  static requestPushPermission() {
144
144
  MoEReactBridge.requestPushPermission();
145
145
  }
146
+
147
+ static updatePushPermissionRequestCount(payload: { [k: string]: any }) {
148
+ MoEReactBridge.updatePushPermissionRequestCount(JSON.stringify(payload));
149
+ }
150
+
151
+ static enableDeviceIdTracking(payload: { [k: string]: any }) {
152
+ MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
153
+ }
154
+
155
+ static disableDeviceIdTracking(payload: { [k: string]: any }) {
156
+ MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
157
+ }
146
158
  }
147
159
 
148
160
  const PUSH_SERVICE_FCM = "FCM"
@@ -226,4 +226,28 @@ export function getPermissionResponseJson(isGranted: boolean, permissionType: Mo
226
226
  type: permissionType.toLowerCase()
227
227
  }
228
228
  return json;
229
+ }
230
+
231
+ export function getPushPermissionRequestCountJson(count: number, appId: String) {
232
+ var json: { [k: string]: any } = {
233
+ accountMeta: {
234
+ appId: appId
235
+ },
236
+ data: {
237
+ pushOptinInAttemptCount: count
238
+ }
239
+ }
240
+ return json;
241
+ }
242
+
243
+ export function getDeviceIdTrackingJson(isDeviceIdTrackingEnabled: Boolean, appId: String) {
244
+ var json: { [k: string]: any } = {
245
+ accountMeta: {
246
+ appId: appId
247
+ },
248
+ data: {
249
+ isDeviceIdTrackingEnabled: isDeviceIdTrackingEnabled
250
+ }
251
+ }
252
+ return json;
229
253
  }
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Bucket
3
- uuid = "A9D2CCE5-E1E4-46E2-8FD6-8A880E005343"
4
- type = "1"
5
- version = "2.0">
6
- <Breakpoints>
7
- <BreakpointProxy
8
- BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
9
- <BreakpointContent
10
- uuid = "B5C2799E-B498-4B55-9AB4-16D905914902"
11
- shouldBeEnabled = "Yes"
12
- ignoreCount = "0"
13
- continueAfterRunningActions = "No"
14
- filePath = "MoEReactBridge/MOReactInitializer.m"
15
- startingColumnNumber = "9223372036854775807"
16
- endingColumnNumber = "9223372036854775807"
17
- startingLineNumber = "34"
18
- endingLineNumber = "34"
19
- landmarkName = "-intializeSDKWithLaunchOptions:"
20
- landmarkType = "7">
21
- </BreakpointContent>
22
- </BreakpointProxy>
23
- </Breakpoints>
24
- </Bucket>