Skip to content

Commit

Permalink
fix: missing opened metric on android 12 and above (customerio#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Apr 26, 2023
1 parent d2bce4d commit 1a61e0e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Customer.io SDK
def cioVersion = "[3.3,4.0)"
def cioVersion = "[3.4.2,4.0)"
implementation "io.customer.android:tracking:$cioVersion"
implementation "io.customer.android:messaging-push-fcm:$cioVersion"
implementation "io.customer.android:messaging-in-app:$cioVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,53 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
initialize(it)
}
}

Keys.Methods.IDENTIFY -> {
call.toNativeMethodCall(result) {
identify(it)
}
}

Keys.Methods.SCREEN -> {
call.toNativeMethodCall(result) {
screen(it)
}
}

Keys.Methods.TRACK -> {
call.toNativeMethodCall(result) {
track(it)
}
}

Keys.Methods.TRACK_METRIC -> {
call.toNativeMethodCall(result) {
trackMetric(it)
}
}

Keys.Methods.REGISTER_DEVICE_TOKEN -> {
call.toNativeMethodCall(result) {
registerDeviceToken(it)
}
}

Keys.Methods.SET_DEVICE_ATTRIBUTES -> {
call.toNativeMethodCall(result) {
setDeviceAttributes(it)
}
}

Keys.Methods.SET_PROFILE_ATTRIBUTES -> {
call.toNativeMethodCall(result) {
setProfileAttributes(it)
}
}

Keys.Methods.CLEAR_IDENTIFY -> {
clearIdentity()
}

else -> {
result.notImplemented()
}
Expand Down Expand Up @@ -214,7 +223,11 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
Keys.Environment.ENABLE_IN_APP
)

CustomerIO.Builder(
// Checks if SDK was initialized before, which means lifecycle callbacks are already
// registered as well
val isLifecycleCallbacksRegistered = kotlin.runCatching { CustomerIO.instance() }.isSuccess

val customerIO = CustomerIO.Builder(
siteId = siteId,
apiKey = apiKey,
region = Region.getRegion(region),
Expand All @@ -236,6 +249,17 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}
}.build()
logger.info("Customer.io instance initialized successfully")

// 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) {
activity?.get()?.let { activity ->
logger.info("Requesting delayed activity lifecycle events")
val lifecycleCallbacks = customerIO.diGraph.activityLifecycleCallbacks
lifecycleCallbacks.postDelayedEventsForNonNativeActivity(activity)
}
}
}

private fun configureModuleMessagingPushFCM(config: Map<String, Any?>?): ModuleMessagingPushFCM {
Expand Down
6 changes: 3 additions & 3 deletions ios/customer_io.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'customer_io'
s.version = '1.0.0'
s.version = '1.1.1'
s.summary = 'Customer.io plugin for Flutter'
s.homepage = 'https://customer.io/'
s.license = { :file => '../LICENSE' }
Expand All @@ -13,8 +13,8 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '13.0'
s.dependency "CustomerIOTracking", '~> 2.1.2'
s.dependency "CustomerIOMessagingInApp", '~> 2.1.2'
s.dependency "CustomerIOTracking", '~> 2.3.0'
s.dependency "CustomerIOMessagingInApp", '~> 2.3.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down
2 changes: 1 addition & 1 deletion lib/customer_io_plugin_version.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Don't modify this line - it's automatically updated
const version = "1.0.0";
const version = "1.1.1";

0 comments on commit 1a61e0e

Please sign in to comment.