Skip to main content

Push Notification Tracking

Track push notification delivery and engagement with built-in support for Apple Push Notification service (APNs).

Register Device Token

Forward the APNs device token to B2Metric to track device registrations:

func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
// Register token with B2Metric
B2MetricAnalytics.shared.registerDeviceToken(deviceToken)
}

This logs a push_token event automatically.

Track Notification Opens

Track when a user opens a push notification:

func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]
) {
// Track push notification open
B2MetricAnalytics.shared.trackPushOpened(userInfo: userInfo)
}

This logs a push_opened event automatically with the notification payload as properties.

Push Notification Events

push_token

Logged when registerDeviceToken(_:) is called. This helps you track which devices have successfully registered for push notifications.

push_opened

Logged when trackPushOpened(userInfo:) is called. This tracks when users interact with your push notifications. All custom data from your APNs payload is automatically included as event properties.

Example with custom data:

// APNs payload
{
"aps": { "alert": "New offer available!" },
"campaign_id": "campaign-123",
"product_id": "SKU-789",
"discount": "20"
}
// Track push opened
B2MetricAnalytics.shared.trackPushOpened(userInfo: userInfo)

// Resulting push_opened event includes all custom fields:
// { "campaign_id": "campaign-123", "product_id": "SKU-789", "discount": "20" }