From e2ac0cb716d3e12d49f4e5c835dbbd258cf13265 Mon Sep 17 00:00:00 2001 From: Rehan Date: Fri, 31 Mar 2023 14:45:02 +0500 Subject: [PATCH 1/6] fix: push opened metrics --- .../reactnative/sdk/CustomerIOReactNativeModule.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index 9d810656..ccd2d325 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -39,6 +39,7 @@ class CustomerIOReactNativeModule( configuration: ReadableMap? = null, packageConfiguration: ReadableMap? = null, ) { + val isFirstInitialization = isNotInitialized() if (isInstanceValid()) { logger.info("Customer.io instance already initialized, reinitializing") } @@ -56,6 +57,15 @@ class CustomerIOReactNativeModule( inAppEventListener = inAppMessagingModule, ) logger.info("Customer.io instance initialized successfully from app") + // Request lifecycle events for first initialization only as relaunching app + // in wrapper SDKs may result in reinitialization of SDK and lifecycle listener + // will already be attached in this case as they are registered to application object. + if (isFirstInitialization) { + currentActivity?.let { activity -> + val lifecycleCallbacks = customerIO.diGraph.activityLifecycleCallbacks + lifecycleCallbacks.postDelayedEventsForNonNativeActivity(activity) + } + } } catch (ex: Exception) { logger.error("Failed to initialize Customer.io instance from app, ${ex.message}") } From 321dd63334ec96d2356009505eefceaaf79cc995 Mon Sep 17 00:00:00 2001 From: Rehan Date: Fri, 31 Mar 2023 15:03:26 +0500 Subject: [PATCH 2/6] added logs --- .../customer/reactnative/sdk/CustomerIOReactNativeModule.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index ccd2d325..7f1355d8 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -39,8 +39,8 @@ class CustomerIOReactNativeModule( configuration: ReadableMap? = null, packageConfiguration: ReadableMap? = null, ) { - val isFirstInitialization = isNotInitialized() - if (isInstanceValid()) { + val isFirstInitialization = !isInstanceValid() + if (!isFirstInitialization) { logger.info("Customer.io instance already initialized, reinitializing") } @@ -62,6 +62,7 @@ class CustomerIOReactNativeModule( // will already be attached in this case as they are registered to application object. if (isFirstInitialization) { currentActivity?.let { activity -> + logger.info("Requesting delayed activity lifecycle events") val lifecycleCallbacks = customerIO.diGraph.activityLifecycleCallbacks lifecycleCallbacks.postDelayedEventsForNonNativeActivity(activity) } From d98158cee1e1c1f090778075013828678891699c Mon Sep 17 00:00:00 2001 From: Rehan Date: Tue, 4 Apr 2023 17:56:16 +0500 Subject: [PATCH 3/6] updated to snapshot build --- android/build.gradle | 1 + android/gradle.properties | 2 +- .../reactnative/sdk/CustomerIOReactNativeModule.kt | 13 +------------ 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index b1fc029e..a683e713 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -49,6 +49,7 @@ repositories { mavenCentral() google() maven { url 'https://maven.gist.build' } + maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } def found = false def defaultDir = null diff --git a/android/gradle.properties b/android/gradle.properties index cfb72067..c35a96a1 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -2,4 +2,4 @@ customerio.reactnative.kotlinVersion=1.7.21 customerio.reactnative.compileSdkVersion=30 customerio.reactnative.targetSdkVersion=30 customerio.reactnative.minSdkVersion=21 -customerio.reactnative.cioSDKVersionAndroid=[3.3,4.0) +customerio.reactnative.cioSDKVersionAndroid=fix-android-12-opened-metrics-SNAPSHOT diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index 7f1355d8..9d810656 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -39,8 +39,7 @@ class CustomerIOReactNativeModule( configuration: ReadableMap? = null, packageConfiguration: ReadableMap? = null, ) { - val isFirstInitialization = !isInstanceValid() - if (!isFirstInitialization) { + if (isInstanceValid()) { logger.info("Customer.io instance already initialized, reinitializing") } @@ -57,16 +56,6 @@ class CustomerIOReactNativeModule( inAppEventListener = inAppMessagingModule, ) logger.info("Customer.io instance initialized successfully from app") - // Request lifecycle events for first initialization only as relaunching app - // in wrapper SDKs may result in reinitialization of SDK and lifecycle listener - // will already be attached in this case as they are registered to application object. - if (isFirstInitialization) { - currentActivity?.let { activity -> - logger.info("Requesting delayed activity lifecycle events") - val lifecycleCallbacks = customerIO.diGraph.activityLifecycleCallbacks - lifecycleCallbacks.postDelayedEventsForNonNativeActivity(activity) - } - } } catch (ex: Exception) { logger.error("Failed to initialize Customer.io instance from app, ${ex.message}") } From a5b1c4fb5cdb273045eb3a661060919de4a114e3 Mon Sep 17 00:00:00 2001 From: Rehan Date: Wed, 5 Apr 2023 18:56:28 +0500 Subject: [PATCH 4/6] requested for delayed events --- .../sdk/CustomerIOReactNativeModule.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index 9d810656..8ca3a6cb 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -16,6 +16,14 @@ class CustomerIOReactNativeModule( get() = CustomerIOShared.instance().diStaticGraph.logger private lateinit var customerIO: CustomerIO + init { + // If SDK is already initialized from CIO service using context, initialize the local + // reference with SDK instance + kotlin.runCatching { + customerIO = CustomerIO.instance() + } + } + override fun getName(): String { return MODULE_NAME } @@ -39,6 +47,10 @@ class CustomerIOReactNativeModule( configuration: ReadableMap? = null, packageConfiguration: ReadableMap? = null, ) { + // Checks if SDK was initialized before, which means lifecycle callbacks are already + // registered as well + val isLifecycleCallbacksRegistered = ::customerIO.isInitialized + if (isInstanceValid()) { logger.info("Customer.io instance already initialized, reinitializing") } @@ -56,6 +68,16 @@ class CustomerIOReactNativeModule( inAppEventListener = inAppMessagingModule, ) logger.info("Customer.io instance initialized successfully from app") + // Request lifecycle events for first initialization only as relaunching app + // in wrapper SDKs may result in reinitialization of SDK and lifecycle listener + // will already be attached in this case as they are registered to application object. + if (!isLifecycleCallbacksRegistered) { + currentActivity?.let { activity -> + logger.info("Requesting delayed activity lifecycle events") + val lifecycleCallbacks = customerIO.diGraph.activityLifecycleCallbacks + lifecycleCallbacks.postDelayedEventsForNonNativeActivity(activity) + } + } } catch (ex: Exception) { logger.error("Failed to initialize Customer.io instance from app, ${ex.message}") } From faea9a10692123c26bb482b29e553d047ce72e07 Mon Sep 17 00:00:00 2001 From: Rehan Date: Thu, 13 Apr 2023 14:40:05 +0500 Subject: [PATCH 5/6] added comments --- .../reactnative/sdk/CustomerIOReactNativeModule.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt index 8ca3a6cb..57b874ef 100644 --- a/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt +++ b/android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativeModule.kt @@ -17,8 +17,13 @@ class CustomerIOReactNativeModule( private lateinit var customerIO: CustomerIO init { - // If SDK is already initialized from CIO service using context, initialize the local - // reference with SDK instance + // If the SDK was already initialized from CIO service using context, initialize the local + // reference with SDK instance so it represents the actual state of SDK. + // SDK instance may only be initialized before when a notification was received while the + // app was in terminated state. Capturing the same instance helps us identify the initial + // state of SDK initialization. + // If the SDK was not initialized before, `CustomerIO.instance()` will throw an exception + // and local variable will also not be initialized. kotlin.runCatching { customerIO = CustomerIO.instance() } From 4cc0a10753aa9d3c6423482c96cf5f901de9487a Mon Sep 17 00:00:00 2001 From: Rehan Date: Thu, 20 Apr 2023 23:24:24 +0500 Subject: [PATCH 6/6] update android sdk version --- android/build.gradle | 1 - android/gradle.properties | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a683e713..b1fc029e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -49,7 +49,6 @@ repositories { mavenCentral() google() maven { url 'https://maven.gist.build' } - maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } def found = false def defaultDir = null diff --git a/android/gradle.properties b/android/gradle.properties index c35a96a1..f890fdbc 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -2,4 +2,4 @@ customerio.reactnative.kotlinVersion=1.7.21 customerio.reactnative.compileSdkVersion=30 customerio.reactnative.targetSdkVersion=30 customerio.reactnative.minSdkVersion=21 -customerio.reactnative.cioSDKVersionAndroid=fix-android-12-opened-metrics-SNAPSHOT +customerio.reactnative.cioSDKVersionAndroid=[3.4.1,4.0)