Configuring push notification interaction tracking

In AppMetrica you can configure tracking interactions with push notifications (such as show and dismiss) for iOS 10 and above.

  1. Collecting statistics
  2. Collecting push notification dismiss interactions

Collecting statistics

To collect interactions statistics for push notifications, follow these steps:

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];

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];

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: