Push Notification Tracking - Android

The Core module can help you track of application launch by a click on push notification message. This tracking can be configured for automatic or manual tracking.

Tracking push notification events automatically

The Core module provides multiple ways for configuring the app to track the push notification events automatically:

  1. Creating a notification by using ORANotification class.

  2. Passing the required key value pair to obtain extra information using Android push notification.

Requirements

To enable automatic tracking of push notification events you should set the PUSH_AUTO_ENABLED configuration to true in the oracle.json file.

Add following line to your oracle.json file.

"ora_dc_push_auto_enabled" : "true"

To enable push notification tracking programmatically, use the following approach:

ORACoreDataContainer container = new ORACoreDataContainer(this);
container.putValue(ORABaseConfigSettings.PUSH_AUTO_ENABLED, "true");

Creating a notification by using ORANotification class.

Example using ORANotification

Build your notification event using ORANotification class, which will add the required key to event data automatically.

final ORANotification builder = new ORANotification(this, "Channel ID")
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Notification title")
.setContentText("This is a test notification")
final Intent resultIntent = new Intent(context, NotificationActivity.class);
builder.setORAContentIntent(0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Passing the required key value pair to intent extra information using Android push notification.

Example using Android Notification

Build your notification event using Android NotificationCompat.Builder class and pass the required "ora_notification" key to intent extra params.

final NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, "ChanelId")
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Intent resultIntent = new Intent(this, ResultActivity.class);
//without below line notification can not be tracked
resultIntent.putExtra("ora_notification", "yourValue");
...
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
...
int mNotificationId = 001;
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());

Or you can create your own "Chanel ID" for the devices with target API 27 (Android 8 Oreo) or above.