从ios友盟统计说开去
来源:互联网 发布:淘宝买酒靠谱吗 编辑:程序博客网 时间:2024/06/07 06:09
友盟统计埋点,不应该和业务做强相关。
这是统计的思想.
不和业务做强相关,自然需要考虑将埋点埋在哪里。
需要统计的地方
1.控件的点击。
2.页面的使用次数,时间。
3.选项是否配置成功。
页面的进出时间
与
viewWillAppear 和 viewWillDisappear有关
分别代表进入页面和离开页面
那么怎么给每个页面做监听呢
先考虑写在基类控制器里 发送
NSStringFromClass([self class])
基类控制器写了可以满足大部分的需求
但是很多关键页面都重写了
viewWillAppear 和 viewWillDisappear
这两个方法,难道每个页面都要去写?
能不能每个页面先在这两个方法的时候,
先执行统计的代码,然后如果有其他方法
再执行其他的方法?
这里就想到了OC的Runtime的一个方法交换
可以在viewWillAppear
时候先做一次方法发送
然后再走业务本身的逻辑。
为了不影响原有的代码,
增加一个category
然后是具体代码了
#import <UIKit/UIKit.h>#import <objc/runtime.h>@interface UIViewController (swizzlingLogCurrentVC)@end
#import "UIViewController+swizzlingLogCurrentVC.h"#import "YYBCommonDefines.h"#import "UMMobClick/MobClick.h"@implementation UIViewController (swizzlingLogCurrentVC)+ (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ ReplaceMethod([self class], @selector(viewWillAppear:), @selector(yyb_viewWillAppear:)); ReplaceMethod([self class], @selector(viewDidDisappear:), @selector(yyb_viewDidDisappear:)); });}- (void)yyb_viewWillAppear:(BOOL)animated{ [self yyb_viewWillAppear:animated];// NSLog(@"%@ viewWillAppear",[self class]); [MobClick beginLogPageView:NSStringFromClass([self class])];}- (void)yyb_viewDidDisappear:(BOOL)animated { [self yyb_viewDidDisappear:animated];// NSLog(@"%@ viewDidDisappear",[self class]); [MobClick endLogPageView:NSStringFromClass([self class])];}@end
CG_INLINE voidReplaceMethod(Class _class, SEL _originSelector, SEL _newSelector) { Method oriMethod = class_getInstanceMethod(_class, _originSelector);//类的实例方法 Method newMethod = class_getInstanceMethod(_class, _newSelector); BOOL isAddedMethod = class_addMethod(_class, _originSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)); if (isAddedMethod) { class_replaceMethod(_class, _newSelector, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod)); } else { method_exchangeImplementations(oriMethod, newMethod); }}
把这段代码 加到基础类控制器,
这些东西就完成了。
同理
点击事件应该对
- (void)sendAction:(SEL)action to:(nullable id)target forEvent:(nullable UIEvent *)event;
这个方法进行方法交换。可以在这里做防止重复点击的代码
至于统计事件的成功率
只要在网络请求发送前和发送回应的时候做统计就好了
发送前 记录请求发送 请求回应code = 0 时 请求发送成功
这就是全部的思路了
其余就是技术上的实现而已。
这样可以少量的代码并不改变原有代码的结构下,
实现所有的埋点统计,非常有效。
阅读全文
0 0
- 从ios友盟统计说开去
- 从"文人相轻"说开去...
- 从“盗版”说开去
- 从PDF说开去
- 从时间说开去
- 【iOS开发】从Cocoa框架说开去--Fundation框架系列
- 从《加速VB》说开去
- 从一个故事说开去
- 从second life说开去
- 从printf说开去(一)
- 从printf说开去(二)
- 从printf说开去(三)
- 从printf说开去(四)
- 从printf说开去(五)
- 从DUMP函数说开去
- [Loader] 从startLoading()说开去..
- 从DUMP函数说开去
- 从软件开发说开去
- 自定义Toast,有图标,有文字,不会重复显示
- Qualcomm WLAN Driver qcacld-2.0源码分析
- 关于高德地图不显示的问题
- HDU1087(递增子序列最大和)
- Thread.yield( )方法
- 从ios友盟统计说开去
- mongoDB 分片(shard)
- 解决扫描目标时IP被拉黑的小技巧
- 论文笔记——CVPR 2017 Dilated Residual Networks
- Python并行编程——multiprocessing
- 前端Js中利用Ajax异步调用后台处理数据
- 使用 Spark MLlib 做 K-means 聚类分析
- iOS开发算法--汉诺塔
- volatile关键字解析