Capture Push Metrics
How it works
Customer.io supports device-side metrics that help you determine the efficacy of your push notifications: delivered
when a push notification is received by the app and opened
when a push notification is clicked.
If you already configured push notifications and your app does not use other push notification modules such as expo-notifications
or react-native-push-notification
, the SDK automatically tracks opened
and delivered
events for push notifications originating from Customer.io.
Otherwise, use one of the following methods to manually track push metrics:
Note - To avoid duplicate push metrics on Fly, set autoTrackPushEvents
as false
while configuring the package if using any of the above methods to manually track push metrics.
Record push metrics using Javascript methods
Known issue tracking opened
push metrics in app killed
state
We are aware of an issue where opened
push metrics are not tracked when the app is in killed
or closed
state.
Beginning with customerio-reactnative
version 3.1.0
, we introduced support for tracking push metrics using JavaScript methods, eliminating the need for adding any native code. These methods prove particularly valuable when utilizing other libraries such as expo-notifications
, react-native-push-notification
, and more.
To monitor the delivered
push metrics of a received push notification, use the CustomerIO.pushMessaging().trackNotificationReceived(<CUSTOMER.IO_PAYLOAD>)
method. When employing third-party libraries mentioned above, extract the Customer.io payload and pass it as the parameter.
CustomerIO.pushMessaging().trackNotificationReceived(<CUSTOMER.IO_PAYLOAD>)
For tracking opened
push metrics, utilize the CustomerIO.pushMessaging().trackNotificationResponseReceived(<CUSTOMER.IO_PAYLOAD>)
method and pass the Customer.io payload as the parameter. If using other third-party libraries as mentioned, extract the Customer.io payload and pass it as the parameter to this method.
CustomerIO.pushMessaging().trackNotificationResponseReceived(<CUSTOMER.IO_PAYLOAD>)
If you are using expo-notification
, you can extract the Customer.io payload by using
response.notification.request.trigger.payload
. This allows you to access the necessary payload information for further processing. Also, configure the plugin and set handleNotificationClick
to false
.
Checkout the following code snippet as an example for expo-notifications
:
// Listener called when a push notification is received
Notifications.addNotificationReceivedListener(notification => {
...
// Fetch Customer.io payload from the push notification
const payload = notification.request.trigger.payload
CustomerIO.pushMessaging().trackNotificationReceived(payload)
...
});
// Receives response when user interacts with the push notification
Notifications.addNotificationResponseReceivedListener(response => {
...
// Fetch Customer.io payload from the push notification response
const payload = response.notification.request.trigger.payload
CustomerIO.pushMessaging().trackNotificationResponseReceived(payload)
...
});
iOS: Record push metrics with native code
If you’re using Objective-C, the example in our push setup process already contains the code required to handle push metrics—substituting AppDelegate
for your push notification class.
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
let handled = MessagingPush.shared.userNotificationCenter(center, didReceive: response,
withCompletionHandler: completionHandler)
// If the Customer.io SDK does not handle the push, you need to handle it and call the
// completion handler. If the SDK handles it, it calls the completion handler for you.
if !handled {
completionHandler()
}
}
}
If delivered
events are important to you, we recommend that you follow the setup instructions for rich push notifications, even if you do not plan on sending rich push notifications as rich push tracks delivered
events more reliably.
Disabling automatic push tracking
Automatic push metric recording is enabled by default when you install the SDK. You can disable this behavior by passing a configuration option when you initialize the SDK. You cannot disable automatic push tracking (or change other configuration settings) after you initialize the SDK.
const data = new CustomerioConfig()
data.autoTrackPushEvents = false
const env = new CustomerIOEnv()
env.siteId = Env.siteId
env.apiKey = Env.apiKey
CustomerIO.initialize(env, data)