Skip to content

Commit

Permalink
fix: improve android push click behavior (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 authored Nov 14, 2023
1 parent 8629e2d commit 62b9e61
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
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.7.0"
def cioVersion = "3.8.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 @@ -13,6 +13,7 @@ import io.customer.messaginginapp.type.InAppEventListener
import io.customer.messaginginapp.type.InAppMessage
import io.customer.messagingpush.MessagingPushModuleConfig
import io.customer.messagingpush.ModuleMessagingPushFCM
import io.customer.messagingpush.config.PushClickBehavior
import io.customer.sdk.CustomerIO
import io.customer.sdk.CustomerIOConfig
import io.customer.sdk.CustomerIOShared
Expand Down Expand Up @@ -280,6 +281,16 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
?.let { value ->
setAutoTrackPushEvents(autoTrackPushEvents = value)
}
config?.getProperty<String>(CustomerIOConfig.Companion.Keys.PUSH_CLICK_BEHAVIOR_ANDROID)
?.takeIfNotBlank()
?.let { value ->
val behavior = kotlin.runCatching {
enumValueOf<PushClickBehavior>(value)
}.getOrNull()
if (behavior != null) {
setPushClickBehavior(pushClickBehavior = behavior)
}
}
}.build(),
)
}
Expand Down
3 changes: 3 additions & 0 deletions lib/customer_io_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CustomerIOConfig {
bool autoTrackPushEvents;
int backgroundQueueMinNumberOfTasks;
double backgroundQueueSecondsDelay;
PushClickBehaviorAndroid pushClickBehaviorAndroid;

bool enableInApp;

Expand All @@ -29,6 +30,7 @@ class CustomerIOConfig {
this.autoTrackPushEvents = true,
this.backgroundQueueMinNumberOfTasks = 10,
this.backgroundQueueSecondsDelay = 30.0,
this.pushClickBehaviorAndroid = PushClickBehaviorAndroid.activityPreventRestart,
this.enableInApp = false,
this.version = ""});

Expand All @@ -44,6 +46,7 @@ class CustomerIOConfig {
'autoTrackPushEvents': autoTrackPushEvents,
'backgroundQueueMinNumberOfTasks': backgroundQueueMinNumberOfTasks,
'backgroundQueueSecondsDelay': backgroundQueueSecondsDelay,
'pushClickBehaviorAndroid': pushClickBehaviorAndroid.rawValue,
'enableInApp': enableInApp,
'version': version,
'source': "Flutter"
Expand Down
26 changes: 26 additions & 0 deletions lib/customer_io_enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,29 @@ enum Region { us, eu }

/// Enum to specify the type of metric for tracking
enum MetricEvent { delivered, opened, converted, clicked }

/// Enum to specify the click behavior of push notification for Android
enum PushClickBehaviorAndroid {
resetTaskStack(rawValue: 'RESET_TASK_STACK'),
activityPreventRestart(rawValue: 'ACTIVITY_PREVENT_RESTART'),
activityNoFlags(rawValue: 'ACTIVITY_NO_FLAGS');

factory PushClickBehaviorAndroid.fromValue(String value) {
switch (value) {
case 'RESET_TASK_STACK':
return PushClickBehaviorAndroid.resetTaskStack;
case 'ACTIVITY_PREVENT_RESTART':
return PushClickBehaviorAndroid.activityPreventRestart;
case 'ACTIVITY_NO_FLAGS':
return PushClickBehaviorAndroid.activityNoFlags;
default:
throw ArgumentError('Invalid value provided');
}
}

const PushClickBehaviorAndroid({
required this.rawValue,
});

final String rawValue;
}

0 comments on commit 62b9e61

Please sign in to comment.