If you notice that your push notification open statistics (/pushStat) are not being tracked, it's often due to a conflict with your custom code. Pushwoosh SDKs for both iOS and Android automatically track push notification opens. However, if you are using custom logic to handle push notifications, you may need to adjust your implementation to ensure the Pushwoosh SDK's tracking mechanism isn't interrupted.
iOS
For iOS, the Pushwoosh SDK automatically sends the /pushStat request when a user taps a push notification. This is handled by an Apple callback.
The most common reason for this tracking to fail is that you have customized the UNUserNotificationCenter delegate. When you override the default push notification handling flow, it can prevent the SDK from executing its tracking logic.
To resolve this, you should use the Pushwoosh notificationCenterDelegateProxy property to add your custom delegate. This ensures that both your custom logic and the Pushwoosh SDK's logic are executed correctly.
Using DelegateProxy for Swift
To use your own UNNotificationCenterDelegate for things like local notifications, you must inform the Pushwoosh SDK. Add your delegate using the add() method of the notificationCenterDelegateProxy:
Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy.add(my_delegate)
Then, in your delegate, implement the UNUserNotificationCenterDelegate methods. This example shows how to handle your own notifications while ensuring Pushwoosh messages are still processed by the SDK.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if (!PWMessage.isPushwooshMessage(notification.request.content.userInfo)) {
// handle your notification
completionHandler(UNNotificationPresentationOptions.alert)
}
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if (!PWMessage.isPushwooshMessage(response.notification.request.content.userInfo)) {
// handle your notification
completionHandler()
}
}
Using DelegateProxy for Objective-C
The process is similar for Objective-C. Use the addNotificationCenterDelegate method to add your custom delegate to the proxy:
[Pushwoosh.sharedInstance.notificationCenterDelegateProxy addNotificationCenterDelegate:my_delegate];
Then, implement your delegate methods, handling your custom notifications without interfering with Pushwoosh messages:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
if (![PWMessage isPushwooshMessage:notification.request.content.userInfo]) {
// handle your message
completionHandler(UNNotificationPresentationOptionAlert);
}
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
if (![PWMessage isPushwooshMessage:response.notification.request.content.userInfo]) {
// handle your message
completionHandler();
}
}
You can find more details on how these methods work in the Basic Integration Guide.
Android
On the Android platform, delivery and open events (/messageDeliveryEvent and /pushStat) are also tracked automatically by the Pushwoosh Android SDK. The SDK uses PushStatNotificationOpenHandler for this purpose.
The likelihood of this tracking being overridden is much lower on Android than on iOS, as the implementation is less susceptible to conflicts with custom code. If you are experiencing issues, however, we recommend reviewing your notification handling logic to ensure it doesn't interfere with the SDK's default behavior.
Comments
0 comments
Article is closed for comments.