收到push时和点击push时加埋点需求
(目前用的个推+神策,程序最低兼容iOS10)
收到push时加埋点事件pushShow和点击push时加埋点事件pushClick需求,分四种情况
A.APP退到后台时,点击push
B.APP运行时,点击push
C.APP运行时,收到push
D.APP退到后台时,收到push
E.APP杀死,收到push
F.APP杀死,点击push
针对A、B、F,会执行以下方法,加埋点pushClick即可
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{} |
针对C,会执行个推的透传消息,在下面的方法里写个本地通知
- (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId{} |
然后执行以下方法,加埋点pushShow即可
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(nonnull UNNotification *)notification withCompletionHandler:(nonnull void (^)(UNNotificationPresentationOptions))completionHandler{} |
针对D、E,挺麻烦的,慢慢看吧
1)提醒这个方法不会走
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{} |
2)提醒这个方法不会走
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(nonnull UNNotification *)notification withCompletionHandler:(nonnull void (^)(UNNotificationPresentationOptions))completionHandler{} |
3)提醒这个方法不会走
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler |
只能另想办法了,走的苹果的apns。
第一步,添加 NotificationService (切记推送内容格式里含"mutable-content": 1, 才能走通知扩展,后台必须给返回这个字段),添加方式请看:
个推文档 http://docs.getui.com/getui/mobile/ios/xcode/
https://www.jianshu.com/p/26b96b991eaf
最容易忽视的点,遇到问题卡半天,请看:
https://www.jianshu.com/p/12aa81d1f859
第二步,想要走以下的方法,需要进行以下操作才能调试:使用Xcode “Debug”下的“Attach to Process By PID or NAME”再真机调试
或者在以下方法里新增本地通知,便于测试是否收到push,有时候不会走里面的断点。
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler{} |
测试本地通知的代码如下:
#pragma mark todo 以下本地推送为测试效果代码 断点不会走。 更换为埋点代码 UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.body = @"自定义查找删除"; content.userInfo = @{@"hello":@"word"}; content.sound = [UNNotificationSound defaultSound]; content.badge = @(100); content.title = @"自定义处理"; UNNotificationRequest *aNewRequest = [UNNotificationRequest requestWithIdentifier:@"Notif" content:content trigger:nil]; [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:aNewRequest withCompletionHandler:^(NSError * _Nullable error) { }]; #pragma mark todo 以上本地推送为测试效果代码 断点不会走。 更换为埋点代码 |
第三步,在以上方法里新增神策埋点代码,加埋点pushShow即可,需要按照以下文档
https://cf.sensorsdata.cn/pages/viewpage.action?pageId=7547239
第四步,开发者证书需要支持App Groups服务,应用和扩展的Groups ID需要与证书、神策存取的一致。
切记:上传App Store限制,避免审核被拒绝
使用了 Notification Service Extension 的项目在制作待上传至 AppStore 的 IPA 包时,编译设备需要选择 Generic iOS Device
,然后再进行 Product -> Archive
操作。只有选择 Generic iOS Device
才能打包编译出带有 Notification Service Extension 且适配全机型设备的 IPA 包
总结:
点击push的埋点,APP不区分杀死、退到后台、运行中,都在didReceiveNotificationResponse中埋点pushClick;
收到push的埋点,APP进程杀死、退到后台,走的苹果apns,都在NotificationService的didReceiveNotificationRequest中埋点pushShow;
收到push的埋点,APP运行中,走的个推的透传,在willPresentNotification中埋点pushShow;
收到push、点击push,神策不会立即上传,会保存到本地,下次打开APP才会上传。然后再等几分钟 ,去后台查看是否埋点成功,神策的机制是这样的。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性