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.

  1. Collecting delivery statistics
  2. Collecting push notification dismiss interactions

Collecting delivery statistics

Step 1. Create Notification Service Extension

  1. In Xcode, select File → New → Target.
  2. In theiOS extensions section, choose Notification Service Extension from the list and click Next.
  3. Enter the name of the extension in the Product Name field and click Finish.

Step 2. Create a shared App Groups group

  1. In the Xcode project settings, go to the Capabilities tab.
  2. 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 .
  3. In the App Groups section use the + button to create a group. You will need the group name during further configuration.
  4. 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

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

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

If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.