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 rich push notifications, the SDK will automatically track opened
and delivered
events for push notifications originating from Customer.io.
Otherwise, you can:
- Record push metrics with
UserNotifications
. - Extract delivery ID and Delivery Token parameters directly.
iOS: capture push metrics using UserNotifications
If you’re using a version of iOS that supports UserNotifications
, you can track metrics using the UNNotificationContent
helper.
If you followed the guide for setting up push notifications (see step 3), then you’ll already have 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, it's up to you to handle it and call the
// completion handler. If the SDK did handle it, it called the completion handler for you.
if !handled {
completionHandler()
}
}
iOS: extract delivery ID and token
If you’re not using a version of iOS that supports UserNotifications
, you should send push metrics manually by extracting the CIO-Delivery-ID
and CIO-Delivery-Token
parameters from notifications.
guard let deliveryID: String = notificationContent.userInfo["CIO-Delivery-ID"] as? String,
let deviceToken: String = notificationContent.userInfo["CIO-Delivery-Token"] as? String else {
// Not a push notification delivered by Customer.io
return
}
MessagingPush.shared.trackMetric(deliveryID: deliveryID, event: .delivered, deviceToken: deviceToken)
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.
CustomerIO.initialize(
config: CustomerIOConfig(
siteId: "YourSiteId",
apiKey: "YourApiKey",
region: Region.us,
autoTrackPushEvents: false
),
)