Tracking Push Notification Taps
Before you begin, make sure you’ve completed these steps:
By the end of this guide, you should see the following result:The mobile push notification is sent from Maestra and displayed on your device. When the notification is tapped, a click event is recorded in Maestra customer profile.
To check that clicks are being detected, please use this guide.
1. Submitting push notification click counts
Example: Implementing the Method to Track the Push Click Event and Retrieve Push Data
Example: Invoking the Method
Add a call to Mindbox.onPushClicked in the activities you specified earlier in onMessageReceived.
Call Mindbox.onPushClicked from both onNewIntent and onCreate callbacks.
import cloud.mindbox.mobile_sdk.*
class MainActivity : AppCompatActivity() {
private fun processMindboxIntent(intent: Intent?) {
// Add Push Notification Tap here
intent?.let { Mindbox.onPushClicked(this, it) }
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
processMindboxIntent(intent)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
processMindboxIntent(intent)
// ...
}
// ...
}Mindbox.onPushClicked method returns true if the SDK identifies the intent and processes it properly. Otherwise, the method returns false.
You can use this to implement additional logic if needed.
Starting with SDK version 2.13.3, if you handle push notifications manually, you can also use the public method:
fun onPushClicked(context: Context, intent: Intent)To do this, use the following Intent extension methods:
Intent.putMindboxPushExtras(pushUniqKey: String)
Intent.putMindboxPushButtonExtras(pushUniqKey: String, pushButtonKey: String?)
If needed, you can retrieve the UniqKey after a push tap using these methods:
Intent.getMindboxUniqKeyFromPushIntent() — returns the push UniqKey
Intent.getMindboxUniqPushButtonKeyFromPushIntent() — returns the button UniqKey
Starting with version 2.14.5, extension methods for MindboxRemoteMessage are available to generate preconfigured PendingIntent for push notifications:
MindboxRemoteMessage.getPushContentIntent — to be used with setContentIntent in the notification constructor
MindboxRemoteMessage.getPushActionIntent — to create Action in notification
Adding Push Data (Without Action Buttons)
// When creating a push notification without buttons
val intent = Intent(context, MainActivity::class.java)
...
// put another data to intent
...
intent.putMindboxPushExtras(pushKey) // Add mindbox unique push key
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
notificationBuilder.setContentIntent(pendingIntent)Adding Push Data (With Action Buttons)
pushActions.take(MAX_ACTIONS_COUNT).forEach { pushAction ->
val intent = Intent(context, MainActivity::class.java)
intent.putMindboxPushButtonExtras(pushUniqKey, pushAction.uniqueKey) // Add unique push key and button key
val pendingIntent = PendingIntent.getActivity(
context,
Random.nextInt(), // Generate unique request code for each button
intent,
PendingIntent.FLAG_IMMUTABLE
)
notificationBuilder.addAction(
0, // Icon for the action
pushAction.text ?: "", // Button text
pendingIntent
)
}Creating a Custom Push Notification
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
val notificationId = Random.nextInt()
MindboxFirebase.convertToMindboxRemoteMessage(remoteMessage)?.let { mindboxRemoteMessage ->
val notification = NotificationCompat.Builder(applicationContext, "mindbox_c")
.setContentTitle(mindboxRemoteMessage.title)
.setContentText(mindboxRemoteMessage.description)
.setSmallIcon(R.mipmap.ic_launcher)
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
.setContentIntent(
mindboxRemoteMessage.getPushContentIntent(
context = applicationContext,
activity = MainActivity::class.java,
notificationId = notificationId
)
)
.apply {
mindboxRemoteMessage.pushActions.forEach {
addAction(
NotificationCompat.Action.Builder(
R.mipmap.ic_launcher,
it.text,
mindboxRemoteMessage.getPushActionIntent(
context = applicationContext,
activity = MainActivity::class.java,
notificationId = notificationId,
pushAction = it,
extras = null,
)
).build()
)
}
}.build()
NotificationManagerCompat.from(applicationContext)
.notify(notificationId, notification)
}
Example: Retrieving Data from an Intent
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
// Get the unique push key
val pushUniqKey = intent?.getMindboxUniqKeyFromPushIntent()
// Get the unique button key (can be null if clicked on notification body)
val buttonUniqKey = intent?.getMindboxUniqPushButtonKeyFromPushIntent()
}2. App navigation
A click invokes the Activity you specified during notification rendering. To process any other data from a push notification, use the getUrlFromPushIntent and getPayloadFromPushIntent methods.
val pushUrl = Mindbox.getUrlFromPushIntent(intent)
val payload = Mindbox.getPayloadFromPushIntent(intent)
Check your results:The mobile push notification is sent from Maestra and displayed on your device. When the notification is tapped, a click event is recorded in Maestra customer profile.
To check that clicks are being detected, please use this guide.
Updated 7 months ago

