Skip to main content

Report Push Notification Data

For APNs push notifications, data on notifications reaching devices and being clicked requires active reporting from the client-side to obtain statistics. Starting from SDK version 5.1.4, RC iOS SDK provides interfaces for reporting this data.

tip

The push notification statistics feature is only available for launched applications in the production environment. For applications using global data centers, please complete the configuration based on the SDK version to ensure data is reported to the correct data center.

Reporting Push Notification Delivery Data

Use the recordReceivedRemoteNotificationEvent: interface to report push notification delivery data. This capability is supported on iOS 10 and above. Currently, only delivery data for one-to-one chat and group chat conversation types can be reported. Ultra group push and push-only notification delivery data are not supported.

/*!
Records the event of receiving a remote push notification

@param userInfo The content of the remote push notification

@discussion This method is used to track the delivery rate of RC push services.
To track push service delivery rates, you need to implement a notification extension in your app. In the NotificationService's -didReceiveNotificationRequest: withContentHandler: method,
first initialize the appkey, then call this method and pass the push content userInfo.

@discussion If there's a separate statistics service address, you also need to set the independent statistics service address after initialization.

Example:

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];

NSDictionary *userInfo = self.bestAttemptContent.userInfo;
[[RCCoreClient sharedCoreClient] initWithAppKey:RONGCLOUD_IM_APPKEY];
if (RONGCLOUD_STATS_SERVER.length > 0) {
[[RCCoreClient sharedCoreClient] setStatisticServer:RONGCLOUD_STATS_SERVER];
}
[[RCCoreClient sharedCoreClient] recordReceivedRemoteNotificationEvent:userInfo];

self.contentHandler(self.bestAttemptContent);
}

@remarks Advanced feature
*/
- (void)recordReceivedRemoteNotificationEvent:(NSDictionary *)userInfo;

Reporting Push Notification Click Data

Use the recordRemoteNotificationEvent interface to report remote push notification click data.

/*!
Records the click event of a remote push notification

@param userInfo The content of the remote push notification

@discussion This method is used to track the click-through rate of RC push services.
To track push service click-through rates, simply call this method in AppDelegate's -application:didReceiveRemoteNotification: and pass the launchOptions.

@remarks Advanced feature
*/
- (void)recordRemoteNotificationEvent:(NSDictionary *)userInfo;

Reporting Local Notification Click Events

Use the recordLocalNotificationResponseEvent interface to report local notification click data.

/// Records the click event of a local notification
///
/// - Parameter userInfo: The content of the local notification
///
/// This method is used to track the click-through rate of local notifications.
///

/// For terminated apps, get local notification content through AppDelegate's -application:didFinishLaunchingWithOptions:;
/// Example:
/// - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/// NSDictionary *userInfo;
/// if (@available(iOS 10.0, *)) {
/// userInfo = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
/// } else {
/// UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
/// userInfo = localNotification.userInfo;
/// }
/// if (userInfo) {
/// [[RCCoreClient sharedCoreClient] recordLocalNotificationResponseEvent:userInfo];
/// }
/// return YES;
/// }
///
/// When the app is in background or foreground, clicking the notification
/// For iOS versions below 10, get remote push content through AppDelegate's -application:didReceiveLocalNotification:,
/// - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
/// [[RCCoreClient sharedCoreClient] recordLocalNotificationResponseEvent:notification.userInfo];
/// }
///
/// For iOS 10 and above, only implement UNUserNotificationCenterDelegate's method -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: in AppDelegate to get response.notification.request.content.userInfo,
/// Example:
/// - (void)userNotificationCenter:(UNUserNotificationCenter *)center
/// didReceiveNotificationResponse:(UNNotificationResponse *)response
/// withCompletionHandler:(void (^)(void))completionHandler {
/// // No need for app layer to distinguish between local notifications and remote pushes, recordLocalNotificationResponseEvent internally determines to only track local ones
/// [[RCCoreClient sharedCoreClient] recordLocalNotificationResponseEvent:response.notification.request.content.userInfo];
/// completionHandler();
/// }
///
/// - Since: 5.14.0
- (void)recordLocalNotificationResponseEvent:(NSDictionary *)userInfo;