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..97ae416a 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_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"; diff --git a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java index decd5f62..e93bb9dc 100644 --- a/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java +++ b/cleverpush/src/main/java/com/cleverpush/NotificationOpenedProcessor.java @@ -5,11 +5,13 @@ 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; @@ -94,6 +96,29 @@ 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); + } + } + + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); + if (notificationDeeplinkId != null && !notificationDeeplinkId.isEmpty()) { + editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID, notificationDeeplinkId); + editor.putString(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME, cleverPush.getCurrentDateTime()); + } else { + // Clear any previously stored deeplink when current notification has none + editor.remove(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_ID); + editor.remove(CleverPushPreferences.LAST_CLICKED_NOTIFICATION_DEEPLINK_TIME); + } + editor.apply(); + try { boolean autoHandleDeepLink = notification.isAutoHandleDeepLink(); String deepLinkURL = result.getNotification().getUrl(); @@ -134,4 +159,10 @@ 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; + } + }