Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cleverpush/src/main/java/com/cleverpush/CleverPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -2957,10 +2957,15 @@ public void trackEvent(String eventName, Map<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Comment thread
unnaticleverpush marked this conversation as resolved.
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();
Expand Down Expand Up @@ -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;
}

}
Loading