Configuring push notification interactions tracking
In AppMetrica you can configure tracking interactions with push notifications (such as delivery and dismiss) for iOS 10 and above.
Collecting delivery statistics
To collect the statistics of delivered push notification, follow these steps:
Step 1. Create Notification Service Extension
- In Xcode, select.
- In theiOS extensions section, choose Notification Service Extension from the list and click Next.
- Enter the name of the extension in the Product Name field and click Finish.
Step 2. Create a shared App Groups group
- In the Xcode project settings, go to the Capabilities tab.
- Switch on the App Groups option for the created extension and for the application. To switch between an extension and an app, go to the project settings panel and click or the drop-down element .
- In the App Groups section use the + button to create a group. You will need the group name during further configuration.
- Select the group you created for the app and for the extension.
Step 3. Make changes in NotificationService
In the
NotificationService.m
file add the following code to the corresponding method:- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { ... [YMPYandexMetricaPush setExtensionAppGroup:appGroup]; ... [YMPYandexMetricaPush handleDidReceiveNotificationRequest:request]; ... }
Copied to clipboard
In the
NotificationService.swift
file add the following code to the corresponding method:func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { ... if let bestAttemptContent = bestAttemptContent { ... YMPYandexMetricaPush.setExtensionAppGroup(appGroup) ... YMPYandexMetricaPush.handleDidReceive(request) ... } }
Copied to clipboard
appGroup
— the name of the shared App Groups group.
Step 4. Configure handling of push notifications.
Add the following code to the corresponding implementation of the
UIApplicationDelegate
method:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Activating AppMetrica. ... [YMPYandexMetricaPush setExtensionAppGroup:appGroup]; ... [YMPYandexMetricaPush handleApplicationDidFinishLaunchingWithOptions:launchOptions]; ... }
Copied to clipboard
Add the following code to the corresponding implementation of the
AppDelegate
method:func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey :Any]? = nil) -> Bool { // Activating AppMetrica. ... YMPYandexMetricaPush.setExtensionAppGroup(appGroup) ... YMPYandexMetricaPush.handleApplicationDidFinishLaunching(options: launchOptions) ... }
Copied to clipboard
appGroup
— the name of the shared App Groups group.
Collecting push notification dismiss interactions
To collect the statistics of dismiss interactions of push notifications, set the following option for the
UNNotificationCategory
category:options:UNNotificationCategoryOptionCustomDismissAction
Copied to clipboard
options: UNNotificationCategory.customDismissAction
Copied to clipboard