From c012610c270717f772d0837d23a33c2c329d9f77 Mon Sep 17 00:00:00 2001 From: UnnatiCP Date: Thu, 6 Nov 2025 09:56:38 +0530 Subject: [PATCH 1/6] frature/cp-9875-android-dynamic-deep-links-track-event-pass-dynamic-deep If the notification URL contains a deeplinkId parameter, pass the value of that deeplinkId as a parameter to the trackEvent API call. --- .../main/java/com/cleverpush/CleverPush.java | 5 +++ .../com/cleverpush/CleverPushPreferences.java | 2 + .../NotificationOpenedProcessor.java | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/cleverpush/src/main/java/com/cleverpush/CleverPush.java b/cleverpush/src/main/java/com/cleverpush/CleverPush.java index 489449a4..96af1f51 100644 --- a/cleverpush/src/main/java/com/cleverpush/CleverPush.java +++ b/cleverpush/src/main/java/com/cleverpush/CleverPush.java @@ -2957,10 +2957,15 @@ public void trackEvent(String eventName, Map properties) { SharedPreferences sharedPreferences = getSharedPreferences(getContext()); String lastClickedNotificationId = sharedPreferences.getString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_ID, null); String lastClickedNotificationTime = sharedPreferences.getString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_TIME, null); + String lastClickedNotificationDeeplinkId = sharedPreferences.getString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID, null); + String lastClickedNotificationDeeplinkTime = sharedPreferences.getString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, null); if (lastClickedNotificationId != null && !lastClickedNotificationId.isEmpty() && isWithin60Minutes(lastClickedNotificationTime)) { jsonBody.put("notificationId", lastClickedNotificationId); } + if (lastClickedNotificationDeeplinkId != null && !lastClickedNotificationDeeplinkId.isEmpty() && isWithin60Minutes(lastClickedNotificationDeeplinkTime)) { + jsonBody.put("deeplinkId", lastClickedNotificationDeeplinkId); + } } catch (JSONException ex) { Logger.e(LOG_TAG, "Error creating trackEvent request parameter", ex); } diff --git a/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java b/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java index 88c023a4..449492e0 100644 --- a/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java +++ b/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java @@ -20,6 +20,8 @@ public class CleverPushPreferences { public static final String LAST_NOTIFICATION_ID = "CleverPush_LAST_NOTIFICATION_ID"; public static final String LAST_CLICKED_NOTIFICATION_ID = "CleverPush_LAST_CLICKED_NOTIFICATION_ID"; public static final String LAST_CLICKED_NOTIFICATION_TIME = "CleverPush_LAST_CLICKED_NOTIFICATION_TIME"; + public static final String LAST_CLICKED_NOTIFICATION_DEEPLINK_ID = "CleverPush_LAST_CLICKED_NOTIFICATION_DEEPLINK_ID"; + public static final String LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME = "CleverPush_LLAST_CLICKED_NOTIFICATION_DEEPLINK_TIME"; public static final String APP_OPENS = "CleverPush_APP_OPENS"; public static final String APP_REVIEW_SHOWN = "CleverPush_APP_REVIEW_SHOWN"; public static final String PENDING_TOPICS_DIALOG = "CleverPush_PENDING_TOPICS_DIALOG"; diff --git a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java index decd5f62..db2089cb 100644 --- a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java +++ b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java @@ -5,14 +5,19 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import androidx.core.app.NotificationManagerCompat; import com.cleverpush.util.Logger; +import com.cleverpush.util.SharedPreferencesManager; import com.google.gson.Gson; import java.net.URI; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -94,6 +99,25 @@ public static void processIntent(Context context, Intent intent) { } } + String notificationDeeplinkId = null; + String notificationUrl = notification.getUrl(); + + if (notificationUrl != null && !notificationUrl.isEmpty()) { + try { + Uri uri = Uri.parse(notificationUrl); + notificationDeeplinkId = uri.getQueryParameter("deeplinkId"); + } catch (Exception e) { + Logger.e("CleverPush", "Error parsing deeplinkId from notification URL: " + notificationUrl, e); + } + } + + if (notificationDeeplinkId != null && !notificationDeeplinkId.isEmpty()) { + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); + editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID, notificationDeeplinkId); + editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, getCurrentDateTime()); + editor.apply(); + } + try { boolean autoHandleDeepLink = notification.isAutoHandleDeepLink(); String deepLinkURL = result.getNotification().getUrl(); @@ -134,4 +158,20 @@ public static void setNotificationDeepLink(String deepLink, CleverPush cleverPus Logger.e(LOG_TAG, "Error while setting notification deep link: " + e.getMessage(), e); } } + + public static SharedPreferences getSharedPreferences(Context context) { + SharedPreferences sharedPreferences = context.getSharedPreferences(SharedPreferencesManager.SDK_PREFERENCES_NAME, Context.MODE_PRIVATE); + return sharedPreferences; + } + + public static String getCurrentDateTime() { + try { + Date time = Calendar.getInstance().getTime(); + SimpleDateFormat outputFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return outputFmt.format(time); + } catch (Exception e) { + Logger.e(LOG_TAG, "Error while getting current date and time", e); + return ""; + } + } } From f4341b29ed38ddb3cdde4555fcea10574da060b3 Mon Sep 17 00:00:00 2001 From: UnnatiCP Date: Thu, 6 Nov 2025 09:59:33 +0530 Subject: [PATCH 2/6] frature/cp-9875-android-dynamic-deep-links-track-event-pass-dynamic-deep --- .../src/main/java/com/cleverpush/CleverPushPreferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java b/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java index 449492e0..97ae416a 100644 --- a/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java +++ b/cleverpush/src/main/java/com/cleverpush/CleverPushPreferences.java @@ -21,7 +21,7 @@ public class CleverPushPreferences { public static final String LAST_CLICKED_NOTIFICATION_ID = "CleverPush_LAST_CLICKED_NOTIFICATION_ID"; public static final String LAST_CLICKED_NOTIFICATION_TIME = "CleverPush_LAST_CLICKED_NOTIFICATION_TIME"; public static final String LAST_CLICKED_NOTIFICATION_DEEPLINK_ID = "CleverPush_LAST_CLICKED_NOTIFICATION_DEEPLINK_ID"; - public static final String LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME = "CleverPush_LLAST_CLICKED_NOTIFICATION_DEEPLINK_TIME"; + public static final String LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME = "CleverPush_LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME"; public static final String APP_OPENS = "CleverPush_APP_OPENS"; public static final String APP_REVIEW_SHOWN = "CleverPush_APP_REVIEW_SHOWN"; public static final String PENDING_TOPICS_DIALOG = "CleverPush_PENDING_TOPICS_DIALOG"; From 356fba147f0954017984bdda880f69dcca8748bd Mon Sep 17 00:00:00 2001 From: UnnatiCP Date: Thu, 6 Nov 2025 10:03:58 +0530 Subject: [PATCH 3/6] frature/cp-9875-android-dynamic-deep-links-track-event-pass-dynamic-deep --- .../com/cleverpush/NotificationOpenedProcessor.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java index db2089cb..6f73073a 100644 --- a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java +++ b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java @@ -114,7 +114,7 @@ public static void processIntent(Context context, Intent intent) { if (notificationDeeplinkId != null && !notificationDeeplinkId.isEmpty()) { SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID, notificationDeeplinkId); - editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, getCurrentDateTime()); + editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, cleverPush.getCurrentDateTime()); editor.apply(); } @@ -164,14 +164,4 @@ public static SharedPreferences getSharedPreferences(Context context) { return sharedPreferences; } - public static String getCurrentDateTime() { - try { - Date time = Calendar.getInstance().getTime(); - SimpleDateFormat outputFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - return outputFmt.format(time); - } catch (Exception e) { - Logger.e(LOG_TAG, "Error while getting current date and time", e); - return ""; - } - } } From 02450446d25cec79e69254885217f303f9e4f5de Mon Sep 17 00:00:00 2001 From: UnnatiCP Date: Thu, 6 Nov 2025 10:07:17 +0530 Subject: [PATCH 4/6] frature/cp-9875-android-dynamic-deep-links-track-event-pass-dynamic-deep Removed unnecessary imports. --- .../main/java/com/cleverpush/NotificationOpenedProcessor.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java index 6f73073a..5f063de1 100644 --- a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java +++ b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java @@ -15,9 +15,6 @@ import com.google.gson.Gson; import java.net.URI; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Set; From b3bae08399105a74d175d388e8a1faef29bdbb3b Mon Sep 17 00:00:00 2001 From: UnnatiCP Date: Mon, 10 Nov 2025 16:43:06 +0530 Subject: [PATCH 5/6] frature/cp-9875-android-dynamic-deep-links-track-event-pass-dynamic-deep --- .../java/com/cleverpush/NotificationOpenedProcessor.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java index 5f063de1..1f2edbad 100644 --- a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java +++ b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java @@ -113,6 +113,12 @@ public static void processIntent(Context context, Intent intent) { editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID, notificationDeeplinkId); editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, cleverPush.getCurrentDateTime()); editor.apply(); + } else { + // Clear any previously stored deeplink when current notification has none + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); + editor.remove(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID); + editor.remove(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME); + editor.apply(); } try { From 93712ac91902453814a8153cf8c1208c5d92f7c5 Mon Sep 17 00:00:00 2001 From: UnnatiCP Date: Mon, 10 Nov 2025 17:06:13 +0530 Subject: [PATCH 6/6] frature/cp-9875-android-dynamic-deep-links-track-event-pass-dynamic-deep --- .../java/com/cleverpush/NotificationOpenedProcessor.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java index 1f2edbad..e93bb9dc 100644 --- a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java +++ b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java @@ -108,18 +108,16 @@ public static void processIntent(Context context, Intent intent) { } } + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); if (notificationDeeplinkId != null && !notificationDeeplinkId.isEmpty()) { - SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID, notificationDeeplinkId); editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, cleverPush.getCurrentDateTime()); - editor.apply(); } else { // Clear any previously stored deeplink when current notification has none - SharedPreferences.Editor editor = getSharedPreferences(context).edit(); editor.remove(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID); editor.remove(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME); - editor.apply(); } + editor.apply(); try { boolean autoHandleDeepLink = notification.isAutoHandleDeepLink();