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 File → New → Target.
- 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. Внесите изменения в NotificationService
In the NotificationService.m
file add the following code to the corresponding method:
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request
withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler
{
...
[AMPAppMetricaPush setExtensionAppGroup:appGroup];
...
[AMPAppMetricaPush handleDidReceiveNotificationRequest:request];
...
}
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 {
...
AMPAppMetricaPush.setExtensionAppGroup(appGroup)
...
AMPAppMetricaPush.handleDidReceive(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.
...
[AMPAppMetricaPush setExtensionAppGroup:appGroup];
...
[AMPAppMetricaPush handleApplicationDidFinishLaunchingWithOptions:launchOptions];
...
}
Add the following code to the corresponding implementation of the AppDelegate
method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey :Any]? = nil) -> Bool
{
// Activating AppMetrica.
...
AppMetricaPush.setExtensionAppGroup(appGroup)
...
AppMetricaPush.handleApplicationDidFinishLaunching(options: 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:
options:UNNotificationCategoryOptionCustomDismissAction
options: UNNotificationCategory.customDismissAction
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.