Configure Marketing Cloud Engagement
Runtime Toggles
Event Tracking
Track Inbox Message Opens on iOS
Track Push Notifications on iOS
Send Custom Campaign Details to Google Analytics 4
Handle URLs
Data Protection and Privacy
Changelog
To ensure proper tracking of push notifications in Marketing Cloud Engagement, call the SDK in your push notification handler method.
If you don’t call the SDK in the handler method, open counts for your push messaging campaigns aren’t tracked. Implement the notification response handler as shown in these examples.
For SDK version 10 and later, use this example.
1// The method is called on the delegate when the user responds to the
2// notification by opening the app, dismissing the notification, or choosing a
3// UNNotificationAction. Set the delegate before the app returns from
4// applicationDidFinishLaunching:.
5func userNotificationCenter(
6 _ center: UNUserNotificationCenter,
7 didReceive response: UNNotificationResponse,
8 withCompletionHandler completionHandler: @escaping () -> Void
9) {
10 // tell the SDK about the notification
11 PushFeature.requestSdk { pushFeature in
12 pushFeature?.setNotificationResponse(response)
13 }
14 completionHandler()
15}For SDK versions 8 and 9, use this example.
1// The method is called on the delegate when the user responds to the
2// notification by opening the app, dismissing the notification, or choosing a
3// UNNotificationAction. Set the delegate before the app returns from
4// applicationDidFinishLaunching:.
5func userNotificationCenter(
6 _ center: UNUserNotificationCenter,
7 didReceive response: UNNotificationResponse,
8 withCompletionHandler completionHandler: @escaping () -> Void
9) {
10 // tell the SDK about the notification
11 SFMCSdk.requestPushSdk { mp in
12 mp.setNotificationRequest(response.notification.request)
13 }
14 completionHandler()
15}For SDK version 7, use this example.
1// The method is called on the delegate when the user responds to the
2// notification by opening the app, dismissing the notification, or choosing a
3// UNNotificationAction. Set the delegate before the app returns from
4// applicationDidFinishLaunching:.
5func userNotificationCenter(
6 _ center: UNUserNotificationCenter,
7 didReceive response: UNNotificationResponse,
8 withCompletionHandler completionHandler: @escaping () -> Void
9) {
10 // tell the MarketingCloudSDK about the notification
11 MarketingCloudSDK.sharedInstance().sfmc_setNotificationRequest(
12 response.notification.request
13 )
14 completionHandler()
15}