页面埋点的事件比较多 只做了一个时间埋点
.h里
@property(nonatomic, strong)NSDate * taskStartDate;// 任务开始时间
@property(nonatomic, strong)NSDate * taskEndDate;// 任务结束时间
@property (nonatomic, assign) long hkStatisticsTotoalTime;
@property (nonatomic, strong) NSTimer *hkStatisticsTimer;
@property (nonatomic, copy) NSString *hkStatisticsClassVc;
@property (nonatomic, copy) NSString *hkStatisticsStartTimeStr;
@property (nonatomic, copy) NSString *hkStatisticsStopTimeStr;
@property (nonatomic, copy) NSString *hkStatisticsMsecondStr;
.m里
//进入页面所有的操作
- (void)nativeEnterAllInfo{
[self nativeStartTime];
NSString *hkStatisticsClassVc = [NSString stringWithUTF8String:object_getClassName(self)];
self.hkStatisticsClassVc = hkStatisticsClassVc;
}
//进入页面的时间
- (void)nativeStartTime{
self.taskStartDate = [NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss:SSS"];
NSString *hkStatisticsStartTimeStr = [dateformatter stringFromDate:self.taskStartDate];
self.hkStatisticsStartTimeStr = hkStatisticsStartTimeStr;
}
//离开页面所有的操作, 拿到的信息发给服务器
1.上传阿里云日志服务, 2通过接口发给自己的服务器
- (void)nativeExitAllInfo{
[self nativeEndTime];
NSLog(@"当前页面进入的时间:%@",self.hkStatisticsStartTimeStr);
NSLog(@"当前页面退出的时间:%@",self.hkStatisticsStopTimeStr);
NSLog(@"当前页面停留总的时长:%@",self.hkStatisticsMsecondStr);
NSLog(@"当前页面的类名是:%@",self.hkStatisticsClassVc);
}
//离开页面的时间
- (void)nativeEndTime{
self.taskEndDate= [NSDate date];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss:SSS"];
NSString *hkStatisticsStopTimeStr = [dateformatter stringFromDate:self.taskEndDate];
self.hkStatisticsStopTimeStr = hkStatisticsStopTimeStr;
NSTimeInterval totalTime= [self.taskEndDate timeIntervalSinceDate:self.taskStartDate];
NSTimeInterval brTime= [self.bActiveDate timeIntervalSinceDate:self.rActiveDate];
NSTimeInterval lastTime = totalTime - brTime;
NSString * millisecond=[NSString stringWithFormat:@"%.3f",(double)totalTime];
NSString * hkStatisticsMsecondStr = [NSString stringWithFormat:@"%g",[millisecond doubleValue]* 1000];
self.hkStatisticsMsecondStr = hkStatisticsMsecondStr;
}
网友评论