使用推送通知支持再参与跟踪
Singular支持推送通知跟踪,以衡量iOS应用程序的再参与度。通过整合苹果推送通知服务(APNs)和 Singular SDK,您可以跟踪用户与推送通知的交互,并准确归因。
请遵循以下实施指南,确保在您的 iOS 应用程序中正确跟踪推送通知。
为什么推送通知跟踪很重要?
推送通知对用户重新参与至关重要,但如果没有适当的跟踪,其影响就不明确。Singular 可确保通知互动的正确归属,使您能够优化营销活动并衡量用户留存率。
实施指南
步骤 1:注册推送通知
确保您的应用程序使用UNUserNotificationCenter 正确注册推送通知。
举例说明:
import UserNotifications
// Set the current instance as the delegate for the UNUserNotificationCenter to handle notifications
UNUserNotificationCenter.current().delegate = self
// Define the notification authorization options (alert, badge, sound)
let pushAuthOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
// Request notification authorization from the user
UNUserNotificationCenter.current().requestAuthorization(options: pushAuthOptions) { granted, error in
// If an error occurs during authorization, print the error description
if let error = error {
print("registerForPushNotifications : failure - \(error.localizedDescription)")
}
// If the user granted permission for notifications, register for remote notifications
if granted {
// Ensure that the registration for remote notifications is done on the main thread
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
- (void) registerForPushNotifications:(UIApplication *)application {
// Set delegate to self
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// Define the push notification options
UNAuthorizationOptions pushAuthOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
// Request push notification authorization
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:pushAuthOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (error) {
NSLog(@"registerForPushNotifications : failure - %@", error.localizedDescription);
}
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
});
}
}];
}
此步骤可确保您的应用已设置为接收和处理推送通知。
第 2 步:处理推送通知并向 Singular 传递数据
收到推送通知后,必须对其进行处理并发送到 Singular 进行跟踪。
举例说明:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
// Pass the notification data to Singular for tracking.
Singular.handlePushNotification(response.notification.request.content.userInfo)
// Call the completion handler to indicate processing is complete.
completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
// Extract the push notification payload (user info).
NSDictionary *userInfo = response.notification.request.content.userInfo;
// Log the userInfo dictionary for debugging purposes.
NSLog(@"didReceiveNotificationResponse userInfo = %@", userInfo);
// Pass the notification data to Singular for tracking.
[Singular handlePushNotification:userInfo];
// Call the completion handler to indicate processing is complete.
completionHandler();
}
第 3 步:将推送通知有效载荷与 Singular SDK 集成
确保已正确配置 Singular SDK 以处理推送通知。
示例:
// Assuming config is an optional object, make sure it's not nil before using it
config?.pushNotificationLinkPath = [
["path", "to", "link"],["sng_link"]
]
// Start the Singular SDK with the given configuration (ensure config is valid)
Singular.start(config)
// Assuming config is already initialized and valid
config.pushNotificationLinkPath = @[
@[@"path", @"to", @"link"],
["sng_link"]
];
// Start the Singular SDK with the given configuration
[Singular start:config];
通过此步骤,Singular 可以正确跟踪推送通知的交互,并对其进行相应归属。
验证指南
Singular SDK API 调用可确保推送通知有效载荷链接在启动会话调用中的singular_link保留参数下正确传递。
举例说明
https://skan.singular.net:443/api/v1/start?dnt=-1&update_time=0&c=wwan&singular_link_resolve_required=false&rt=plist&lag=0.00&is=false&event_index=10&d=iPhone14,7&skan_has_framework=true&sdk=Singular/12.7.1&skan_conversion_value_mode=managed&mo=iPhone14,7&skan_update_counter=1&i=com.singular.SwiftScene&config_version=0&k=IDFV&cr=1&skan_total_admon_revenue_by_currency={}&install_time=1740577866&n=SwiftScene&av=1.0&skan_skadnetwork_enabled=true&p=iOS&idfv=D159BFDC-D061-479B-AB24-0CE00C1FA2AA&att_authorization_status=0&device_type=phone&s=F90C41BF-99EC-48FC-ABF8-2781FF5A2799&skan_first_call_to_skadnetwork_timestamp=1740577882&u=D159BFDC-D061-479B-AB24-0CE00C1FA2AA&skan_last_call_to_skadnetwork_timestamp=1740577882&singular_install_id=554DBBE4-9842-46A8-9F9D-24B8A9BF83E3&v=18.2.1&singular_link=https://sl.sng.link/Cclbu/2a7n_dl=com.singular.flutterApplication1&_smtype=3&singular_link_resolve_timeout=0&pu=1&a=sdk<>key&skan_total_revenue_by_currency={}&h=8aee646bc4b796a5f8908ef8af677ba0fde70aa9</>
您也可以使用Singular SDK 控制台来验证Deeplink URL 下的推送通知跟踪链接,如下所示。
通过验证,您可以确认 Singular SDK 正确跟踪了推送通知的参与情况。
注意:
- 请注意,与singularLinksHandler 代码不同的是,Singular SDK 不为该功能提供推送有效载荷回调。应用程序开发人员有责任读取推送通知数据并实施深度链接逻辑,将用户重定向到应用程序中的特定产品页面。在此解决方案中,Singular 会在用户点击通知时检索推送通知有效载荷,并将此有效载荷包含在由Singular.start() 触发的 SDK 启动会话事件中。然后,Singular 后端将对该数据进行处理,以确定推送通知触摸点/点击的属性,并将其注册用于重新参与跟踪。
-
我们有一套安全机制,只允许推送通知有效载荷中传递的自定义键值对中的Singular 链接域。具体来说,只允许使用 "奇异管理链接 "页面中预定义的sng.link域。
例如
https://prod_test.sng.link/B0s2a/51oi?_dl=singular%3A%2F%2Fmain
如果要在不同的域(如电子邮件服务提供商的ESP 域)中封装Singular 链接,则必须在设置中添加以下选项,明确配置域:请参考以下配置示例:config.espDomains = @[@"sl.esp.link"];
-
如果需要根据单个推送通知中的用户操作触发不同的深层链接,可以使用单个 Singular 跟踪链接并动态修改重定向。
示例
突发新闻推送通知可能会提供多个深层链接选项:
与其创建多个跟踪链接,不如配置一个单一跟踪链接,并根据用户选择动态调整重定向。
阅读最新新闻→热门话题
热门话题→newsapp://article?id=12345
体育→newsapp://trending
newsapp://sports
按照这些步骤,您的 iOS 应用程序现在已配置为使用 Singular 跟踪推送通知。这将改进参与跟踪,优化再参与营销活动,并提高归因的准确性。