Authored by 于良

Merge branch 'develop' of http://git.yoho.cn/mobile/YH_EventReport into develop

... ... @@ -18,6 +18,8 @@
29D3B9761F739D2F00B07F47 /* YH_EventCollector+UIAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 29D3B9751F739D2F00B07F47 /* YH_EventCollector+UIAlertView.m */; };
29D3B9791F739D8300B07F47 /* YH_EventCollector+PowerfulBannerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 29D3B9781F739D8300B07F47 /* YH_EventCollector+PowerfulBannerView.m */; };
29D3B97C1F73A81E00B07F47 /* YH_EventCollector+UIActionSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = 29D3B97B1F73A81E00B07F47 /* YH_EventCollector+UIActionSheet.m */; };
52540FAD1F8F6BAD001907B3 /* YH_CrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 52540FA91F8F6BAD001907B3 /* YH_CrashReporter.m */; };
52540FAE1F8F6BAD001907B3 /* YH_CrashDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 52540FAC1F8F6BAD001907B3 /* YH_CrashDataManager.m */; };
29FB39AA1F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 29FB39A91F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m */; };
29FB39AD1F7C9D73000E3B27 /* UILabel+GestureAutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 29FB39AC1F7C9D73000E3B27 /* UILabel+GestureAutoTrack.m */; };
5255C2B91F5D25F400A8FC5F /* UICollectionView+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 5255C2A61F5D25F400A8FC5F /* UICollectionView+AutoTrack.m */; };
... ... @@ -114,6 +116,10 @@
29D3B9781F739D8300B07F47 /* YH_EventCollector+PowerfulBannerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "YH_EventCollector+PowerfulBannerView.m"; sourceTree = "<group>"; };
29D3B97A1F73A81E00B07F47 /* YH_EventCollector+UIActionSheet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YH_EventCollector+UIActionSheet.h"; sourceTree = "<group>"; };
29D3B97B1F73A81E00B07F47 /* YH_EventCollector+UIActionSheet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "YH_EventCollector+UIActionSheet.m"; sourceTree = "<group>"; };
52540FA91F8F6BAD001907B3 /* YH_CrashReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_CrashReporter.m; sourceTree = "<group>"; };
52540FAA1F8F6BAD001907B3 /* YH_CrashDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_CrashDataManager.h; sourceTree = "<group>"; };
52540FAB1F8F6BAD001907B3 /* YH_CrashReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_CrashReporter.h; sourceTree = "<group>"; };
52540FAC1F8F6BAD001907B3 /* YH_CrashDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_CrashDataManager.m; sourceTree = "<group>"; };
29FB39A81F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIImageView+GestureAutoTrack.h"; sourceTree = "<group>"; };
29FB39A91F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+GestureAutoTrack.m"; sourceTree = "<group>"; };
29FB39AB1F7C9D73000E3B27 /* UILabel+GestureAutoTrack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UILabel+GestureAutoTrack.h"; sourceTree = "<group>"; };
... ... @@ -280,12 +286,24 @@
path = PowerfulBannerView;
sourceTree = "<group>";
};
5223D9CE1F8F50FF00EB698F /* YH_CrashReporter */ = {
isa = PBXGroup;
children = (
52540FAA1F8F6BAD001907B3 /* YH_CrashDataManager.h */,
52540FAC1F8F6BAD001907B3 /* YH_CrashDataManager.m */,
52540FAB1F8F6BAD001907B3 /* YH_CrashReporter.h */,
52540FA91F8F6BAD001907B3 /* YH_CrashReporter.m */,
);
path = YH_CrashReporter;
sourceTree = "<group>";
};
5255C2A31F5D25F400A8FC5F /* YHEventReport */ = {
isa = PBXGroup;
children = (
5255C2B71F5D25F400A8FC5F /* YHEventReport.h */,
5255C2B81F5D25F400A8FC5F /* YHEventReport.m */,
5255C2A41F5D25F400A8FC5F /* YH_AOP */,
5223D9CE1F8F50FF00EB698F /* YH_CrashReporter */,
5255C2C21F5D265000A8FC5F /* YH_EventCollector */,
5255C2AB1F5D25F400A8FC5F /* YH_EventCache */,
5255C2B21F5D25F400A8FC5F /* YH_EventDataSession */,
... ... @@ -717,6 +735,7 @@
B1D774AE1F62A37E00BA89C3 /* UIImageView+HighlightedWebCache.m in Sources */,
B14C0C991F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m in Sources */,
B1D774A91F62A37E00BA89C3 /* SDWebImagePrefetcher.m in Sources */,
52540FAD1F8F6BAD001907B3 /* YH_CrashReporter.m in Sources */,
29FB39AA1F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m in Sources */,
29D3B9791F739D8300B07F47 /* YH_EventCollector+PowerfulBannerView.m in Sources */,
B1D774A71F62A37E00BA89C3 /* SDWebImageDownloaderOperation.m in Sources */,
... ... @@ -742,6 +761,7 @@
B1D774AF1F62A37E00BA89C3 /* UIImageView+WebCache.m in Sources */,
B1D774A81F62A37E00BA89C3 /* SDWebImageManager.m in Sources */,
B13B6C0C1F710BA600C18812 /* UITabBarItem+Yoho.m in Sources */,
52540FAE1F8F6BAD001907B3 /* YH_CrashDataManager.m in Sources */,
B1D774A21F62A37E00BA89C3 /* SDImageCache.m in Sources */,
B1C418CD1F5FFBAA005E0729 /* YH_PerformanceAppInfo.m in Sources */,
5255C2BC1F5D25F400A8FC5F /* YH_EventCacheFile.m in Sources */,
... ...
... ... @@ -14,27 +14,39 @@
/**
* @property
*
* @abstract
* 两次数据发送的时间间隔,单位毫秒
* 返回初始化好的单例
*
* @discussion
* 默认值为 10 * 1000 毫秒.
* @return 返回的单例
*/
@property (atomic) UInt64 flushInterval;
+ (YHEventReport *)sharedInstance;
-(void)setup;
/**
* @property
* @abstract
* 开启点击事件上报
*
*/
-(void)startClickEventTrack;
/**
* @abstract
* 本地缓存的最大事件数目,当累积日志量达到阈值时发送数据
* 开启性能数据上报
*
* @discussion
* 默认值为 10.
*/
@property (atomic) UInt64 flushBulkSize;
-(void)startPerformanceTrack;
#pragma mark - 开关
/**
* 上报埋点ID和参数
*/
- (void)reportWithPointType:(YHPointType)type pointName:(YHEventReportPointName)name parameters:(NSDictionary *)param;
/**
... ... @@ -82,59 +94,84 @@
@property (atomic,getter=isHttpPerformanceTrackEnable) BOOL httpPerformanceTrackEnable;
/**
* @property
*
* @abstract
* 设置本地缓存最大空间
* 是否开启app埋点数据上报
*
* @discussion
* 默认为 50 * 1024 * 1024
*
* @param maxCacheSize 本地缓存最大容量空间
* 默认值为 关.
*/
- (void)setMaxCacheSize:(UInt64)maxCacheSize;
@property (atomic,getter=isAppReportEnable) BOOL appReportEnable;
/**
* @property
*
* @abstract
* 设置网络发送策略
* 是否开启app crash数据上报
*
* @discussion
* 默认联网状态下都会尝试上传
*
* @param networkType YHEventReportNetworkType
* 默认值为 关.
*/
- (void)setUploadNetworkPolicy:(YHEventReportNetworkType)networkType;
@property (atomic,getter=isAppCrashReportEnable) BOOL appCrashReportEnable;
#pragma mark - 配置
/**
* @property
*
* @abstract
* 设置上传的时间间隔
* 两次数据发送的时间间隔,单位毫秒
*
* @discussion
* 默认值为 10 * 1000 毫秒.
*/
- (void)setUploadInterval:(NSTimeInterval)timeInterval;
@property (atomic) UInt64 flushInterval;
/**
* @property
*
* @abstract
* 返回初始化好的单例
* 本地缓存的最大事件数目,当累积日志量达到阈值时发送数据
*
* @return 返回的单例
* @discussion
* 默认值为 10.
*/
+ (YHEventReport *)sharedInstance;
@property (atomic) UInt64 flushBulkSize;
/**
* @abstract
* 开启点击事件上报
* 设置本地缓存最大空间
*
* @discussion
* 默认为 50 * 1024 * 1024
*
* @param maxCacheSize 本地缓存最大容量空间
*/
-(void)startClickEventTrack;
- (void)setMaxCacheSize:(UInt64)maxCacheSize;
/**
* @abstract
* 开启性能数据上报
* 设置网络发送策略
*
* @discussion
* 默认联网状态下都会尝试上传
*
* @param networkType YHEventReportNetworkType
*/
-(void)startPerformanceTrack;
- (void)setUploadNetworkPolicy:(YHEventReportNetworkType)networkType;
/**
* @abstract
* 设置上传的时间间隔
*
*/
- (void)setUploadInterval:(NSTimeInterval)timeInterval;
/**
* @abstract
... ... @@ -168,6 +205,29 @@
/**
* @abstract
* 是否开启debug模式,默认关闭
*
*/
-(void)setDebugMode:(BOOL)debugMode;
/**
* @abstract
* 获取用户的UD
* @return 用户id
*/
- (NSString *)uid;
/**
* @abstract
* 获取渠道号
* @return 渠道号
*/
- (NSString *)channelId;
#pragma mark - Getter
/**
* @abstract
* 是否忽略该类View的track
*
*/
... ... @@ -214,26 +274,5 @@
- (BOOL)isPerformanceTrackEnabled;
/**
* @abstract
* 获取用户的UD
* @return 用户id
*/
- (NSString *)uid;
/**
* @abstract
* 获取渠道号
* @return 渠道号
*/
- (NSString *)channelId;
/**
* @abstract
* 是否开启debug模式,默认关闭
*
*/
-(void)setDebugMode:(BOOL)debugMode;
@end
... ...
... ... @@ -22,6 +22,10 @@
#import "UIControl+AutoTrack.h"
#import "UITapGestureRecognizer+AutoTrack.h"
#import "NSURLConnection+AutoTrack.h"
#import "YH_EventCacheManager.h"
#import "YH_CrashDataManager.h"
#import "YH_EventDataFactory.h"
#import "YH_CrashReporter.h"
#define kYHEventReportIgnoredViewController @"YHEventReportQueue"
... ... @@ -35,6 +39,7 @@
@property(nonatomic,strong)NSArray *ignorePerformanceViewControllerArray;
@property(nonatomic,strong)NSArray *ignoreClickViewControllerArray;
@property (nonatomic,strong)YH_CrashDataManager *crashDataMgr;
@end
... ... @@ -103,6 +108,13 @@ static NSArray *kYHEventReportIgnoredViewControllerArray;
return self;
}
-(void)setup{
if (self.isAppReportEnable && self.isAppCrashReportEnable) {
[self uploadLocalErrorData];
[YH_CrashReporter sharedInstance];
}
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
... ... @@ -142,7 +154,6 @@ static NSArray *kYHEventReportIgnoredViewControllerArray;
/**
* @abstract
* 开启性能数据上报
*
*/
-(void)startPerformanceTrack{
self.performanceTrackEnabled = YES;
... ... @@ -150,11 +161,68 @@ static NSArray *kYHEventReportIgnoredViewControllerArray;
[UITabBar startTrack];
[UIControl startTrack];
[UITapGestureRecognizer startTrack];
[NSURLConnection startTrack];
//[NSURLConnection startTrack];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIWebView startTrack];
//[SDWebImageManager startTrack];
[SDWebImageManager startTrack];
});
}
- (void)reportWithPointType:(YHPointType)type pointName:(YHEventReportPointName)name parameters:(NSDictionary *)param{
//如果是exception类型,先保存,待下次启动后,上传;其他事件,则直接上传.
if (!self.isAppReportEnable) {
return;
}
if (type == YHPT_EXCEPTION) {
if (!self.isAppCrashReportEnable) {
return;
}
NSMutableDictionary *postMDict = [NSMutableDictionary dictionary];
[postMDict setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT];
[postMDict setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
[postMDict setObject:param forKey:YOHOAppReportKeyPARAM];
if (![self.crashDataMgr saveData:postMDict]) {
YHLog(@"save error data to file failed.");
}
}else{
[[YH_EventCacheManager sharedInstance] pushCustomData:IsNilOrNull(param)?@{}:param pointType:type pointName:name];
}
}
#pragma mark - Exception handle methods
// 发送本地存储的Exception数据
- (void)uploadLocalErrorData
{
@synchronized(self){
NSArray *errorDataArray = [self.crashDataMgr getLocalErrorData];
if (!IsNilOrNull(errorDataArray)) {
[self postErrorWithParametersArray:errorDataArray];
}
}
}
- (void)postErrorWithParametersArray:(NSArray *)parametersArray
{
if (IsArrEmpty(parametersArray)) {
return;
}
WS(weakSelf);
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (NSDictionary *param in parametersArray) {
if (IsDictionaryClass(param)) {
return;
}
[[YH_EventCacheManager sharedInstance] pushCrashData:param];
}
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.crashDataMgr removeLocalFile];
});
});
}
... ...
... ... @@ -12,6 +12,6 @@
@property(nonatomic,copy)NSString *yh_webImageId;//唯一ID
//+(void)startTrack;
+(void)startTrack;
@end
... ...
... ... @@ -42,7 +42,7 @@ static const void *yher_actionHandlerBlock = &yher_actionHandlerBlock;
return objc_getAssociatedObject(self, @selector(yh_webImageId));
}
+(void)load
+(void)startTrack
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
... ...
//
// YH_CrashDataManager.h
// YH_Mall
//
// Created by John Tai on 12/8/2017.
// Copyright © 2017 YOHO. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface YH_CrashDataManager : NSObject
//获取本地存储的Exception数据
-(NSArray *)getLocalErrorData;
//将错误信息持久化到本地
-(BOOL)saveData:(NSDictionary*)data;
// 删除本地持久化文件
- (void)removeLocalFile;
@end
... ...
//
// YH_CrashDataManager.m
// YH_Mall
//
// Created by John Tai on 12/8/2017.
// Copyright © 2017 YOHO. All rights reserved.
//
#import "YH_CrashDataManager.h"
#import "YHEventReportMacros.h"
@interface YH_CrashDataManager()
/**
* 日志文件存储路径
*/
@property (strong, nonatomic) NSString *eventFilePath;
/**
* 日志文件名称
*/
@property (strong, nonatomic) NSString *eventFileName;
/**
* 文件管理服务
*/
@property (strong, nonatomic) NSFileManager *fileManager;
@end
@implementation YH_CrashDataManager
-(instancetype)init{
self = [super init];
if (self) {
}
return self;
}
//保存错误信息
-(BOOL)saveData:(NSDictionary*)data{
if (![self canPersisting] ||!data) {
return FALSE;
}
NSMutableArray *localErrorDataArray = [NSMutableArray arrayWithArray:[self getLocalErrorData]];
[localErrorDataArray addObject:data];
return [localErrorDataArray writeToFile:self.eventFileName atomically:YES];
}
- (BOOL)canPersisting
{
if (![self.fileManager fileExistsAtPath:self.eventFilePath]) {
return [self.fileManager createDirectoryAtPath:self.eventFilePath withIntermediateDirectories:YES attributes:nil error:nil];
}
return YES;
}
//获取本地存储的Exception数据
-(NSArray *)getLocalErrorData{
return [NSArray arrayWithContentsOfFile:self.eventFileName];
}
// 删除本地持久化文件
- (void)removeLocalFile
{
if ([self.fileManager fileExistsAtPath:self.eventFileName]) {
NSError *error;
if ([self.fileManager removeItemAtPath:self.eventFileName error:&error]) {
NSLog(@"成功删除本地日志文件。");
} else {
NSLog(@"删除本地日志文件失败:%@", error.localizedDescription);
}
}
}
#pragma mark - Getters
- (NSFileManager *)fileManager
{
if (!_fileManager) {
_fileManager = [NSFileManager defaultManager];
}
return _fileManager;
}
- (NSString *)eventFilePath
{
if (!_eventFilePath || [_eventFilePath isEqualToString:@""]) {
_eventFilePath = YOHOPathLogSystem;
}
return _eventFilePath;
}
- (NSString *)eventFileName
{
if (!_eventFileName || [_eventFileName isEqualToString:@""]) {
_eventFileName = [self.eventFilePath stringByAppendingPathComponent:YOHOAppReportLogSystemName];
}
return _eventFileName;
}
@end
... ...
//
// YH_CrashReporter.h
// YH_Mall
//
// Created by John Tai on 11/8/2017.
// Copyright © 2017 YOHO. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface YH_CrashReporter : NSObject
+ (YH_CrashReporter *)sharedInstance;
- (NSString *)callstackString;
- (void)handleSignal:(NSDictionary *)userInfo;
- (void)handleNSException:(NSDictionary *)userInfo;
-(NSString *)getStringFromArray:(NSArray *)array;
@end
... ...
//
// YH_CrashReporter.m
// YH_Mall
//
// Created by John Tai on 11/8/2017.
// Copyright © 2017 YOHO. All rights reserved.
//
#import "YH_CrashReporter.h"
//#import "YHError.h"
#include <signal.h>
#include <execinfo.h>
#import "YHEventReportMacros.h"
#import "YHLog.h"
#import "YHEventReport.h"
#pragma mark - C Fuctions
void yh_sighandler(int signal)
{
const char* names[NSIG];
names[SIGABRT] = "SIGABRT";
names[SIGBUS] = "SIGBUS";
names[SIGFPE] = "SIGFPE";
names[SIGILL] = "SIGILL";
names[SIGPIPE] = "SIGPIPE";
names[SIGSEGV] = "SIGSEGV";
YH_CrashReporter *crash = [[YH_CrashReporter alloc] init];
NSString *str = [crash callstackString];
NSDictionary *userInfo = @{
YOHOAppReportCrashCallstack : str,
YOHOAppReportCrashSignal : @(signal),
YOHOAppReportCrashSignalName : [NSString stringWithUTF8String:names[signal]],
};
[crash performSelectorOnMainThread:@selector(handleSignal:) withObject:userInfo waitUntilDone:YES];
}
void yh_uncaughtCrashExceptionHandler(NSException *exception)
{
YH_CrashReporter *crash = [[YH_CrashReporter alloc] init];
NSArray *arr = [exception callStackSymbols];
NSString *str = [crash getStringFromArray:arr];
NSDictionary *userInfo = @{
YOHOAppReportCrashCallstack : str,
YOHOAppReportCrashExceptionName : exception.name,
YOHOAppReportCrashExceptionReason : exception.reason,
};
[crash performSelectorOnMainThread:@selector(handleNSException:) withObject:userInfo waitUntilDone:YES];
}
@implementation YH_CrashReporter
+ (YH_CrashReporter *)sharedInstance
{
static YH_CrashReporter *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[YH_CrashReporter alloc] init];
});
return sharedInstance;
}
#pragma mark - Lifetime methods
- (id)init
{
self = [super init];
if (self) {
signal(SIGABRT, yh_sighandler);
signal(SIGBUS, yh_sighandler);
signal(SIGFPE, yh_sighandler);
signal(SIGILL, yh_sighandler);
signal(SIGPIPE, yh_sighandler);
signal(SIGSEGV, yh_sighandler);
NSSetUncaughtExceptionHandler(&yh_uncaughtCrashExceptionHandler);
}
return self;
}
#pragma mark - methods
- (NSString *)callstackString
{
void *callstack[128];
const int numFrams = backtrace(callstack, 128);
char **symbols = backtrace_symbols(callstack, numFrams);
NSString *callStackString = @"";
for (int i = 0; i < numFrams; i++) {
NSString *symbolStr = [NSString stringWithUTF8String:symbols[i]];
callStackString = [callStackString stringByAppendingString:symbolStr];
callStackString = [callStackString stringByAppendingString:@" \n"];
}
free(symbols);
return callStackString;
}
- (void)handleSignal:(NSDictionary*)userInfo
{
YHLog(@"crash============:\n%@", userInfo);
if (!userInfo || ![userInfo isKindOfClass:[NSDictionary class]]) {
return;
}
[[YHEventReport sharedInstance] reportWithPointType:YHPT_EXCEPTION pointName:YHPN_CRASH parameters:userInfo];
[self killApp];
}
- (void)handleNSException:(NSDictionary*)userInfo
{
YHLog(@"crash============:\n%@", userInfo);
if (!userInfo || ![userInfo isKindOfClass:[NSDictionary class]]) {
return;
}
[[YHEventReport sharedInstance] reportWithPointType:YHPT_EXCEPTION pointName:YHPN_CRASH parameters:userInfo];
[self killApp];
}
- (void)killApp
{
NSSetUncaughtExceptionHandler(NULL);
signal(SIGABRT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGFPE, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
kill(getpid(), SIGKILL);
}
#pragma mark - tools
-(NSString *)getStringFromArray:(NSArray *)array{
NSString * result = @"";
if (!array) {
return result;
}
result = [[array valueForKey:@"description"] componentsJoinedByString:@""];
return result;
}
@end
... ...
... ... @@ -34,6 +34,19 @@
*/
- (void)pushPerformanceData:(NSDictionary*)data pointName:(YHEventReportPointName)name;
/**
* @abstract
* 上传原AppReport数据,即手动添加的埋点数据
*
*/
- (void)pushCustomData:(NSDictionary*)data pointType:(YHPointType)type pointName:(YHEventReportPointName)name;
/**
* @abstract
* 上传crash数据
*/
- (void)pushCrashData:(NSDictionary*)data;
- (void) startUploadMode:(YHEventReportStrategy)mode timeInterval:(long)timeIntervals;
@end
... ...
... ... @@ -16,6 +16,7 @@
#import <UserNotifications/UserNotifications.h>
#import "YH_AnalyticEventData.h"
#import "YHLog.h"
#import "YH_EventDataFactory.h"
@interface YH_EventCacheManager()
... ... @@ -87,7 +88,6 @@
return self;
}
- (void)dealloc
{
[self.timer invalidate];
... ... @@ -150,14 +150,14 @@
- (void)pushEventData:(NSDictionary*)data
{
[self pushData:[[YH_AnalyticEventData sharedInstance] analyticEventParameters:data] dataType:YHEventReportDataTypeNormalEvent];
[self pushData:[[YH_AnalyticEventData sharedInstance] analyticEventParameters:data] dataType:YHEventReportDataTypeClickEvent];
}
- (void)pushPerformanceData:(NSDictionary*)data pointName:(YHEventReportPointName)name
{
NSMutableDictionary *performanceDic = [[NSMutableDictionary alloc]initWithCapacity:0];
[performanceDic setObject:@"PERFORMANCE" forKey:YOHOAppReportKeyPT];
[performanceDic setObject:[self getPointName:name] forKey:YOHOAppReportKeyPN];
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.performanceAppInfo]mutableCopy];
... ... @@ -174,10 +174,42 @@
[self pushData:eventDic dataType:YHEventReportDataTypePerformance];
}
- (void)pushCustomData:(NSDictionary*)data pointType:(YHPointType)type pointName:(YHEventReportPointName)name{
NSMutableDictionary *performanceDic = [NSMutableDictionary dictionary];
[performanceDic setObject:[YH_EventDataFactory getPointType:type] forKey:YOHOAppReportKeyPT];
[performanceDic setObject:[YH_EventDataFactory getPointName:name] forKey:YOHOAppReportKeyPN];
NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.performanceAppInfo]mutableCopy];
if (!IsDictionaryClass(eventDic)) {
return;
}
if (IsDictionaryClass(performanceDic)) {
[eventDic addEntriesFromDictionary:performanceDic];
}
if (IsDictionaryClass(eventDic)) {
[eventDic setObject:data forKey:YOHOAppReportKeyPARAM];
}
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
}
- (void)pushCrashData:(NSDictionary*)data{
NSMutableDictionary *eventDic = [[YH_EventDataFactory factoryEventAppInfo:self.performanceAppInfo]mutableCopy];
if (!IsDictionaryClass(eventDic) ||!IsDictionaryClass(data)) {
return;
}
[eventDic addEntriesFromDictionary:data];
[self pushData:[eventDic copy] dataType:YHEventReportDataTypeCustom];
}
#pragma mark - private
- (void)pushData:(NSDictionary*)data dataType:(YHEventReportDataType)type
{
if (type == YHEventReportDataTypeNormalEvent) {
if (type == YHEventReportDataTypeClickEvent) {
[self.eventDataSession uploadEventData:data tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
}];
}else {
... ... @@ -195,9 +227,7 @@
- (void) startUploadMode:(YHEventReportStrategy)mode timeInterval:(long)timeIntervals;
{
_mode = mode;
self.timeInterval = timeIntervals;
if (mode == YHEventReportStrategyInterval) {
if (self.timer == nil) {
//定时上传
... ... @@ -222,61 +252,11 @@
if (IsArrayClass(ary)) {
[performanceAryDic setObject:dataArray forKey:@"list"];
}
[performanceAryDic setObject:[self getDataType:type] forKey:@"type"];
[performanceAryDic setObject:[YH_EventDataFactory getDataType:type] forKey:@"type"];
return performanceAryDic;
}
-(NSString *)getPointName:(YHEventReportPointName)pointName{
NSString *str = @"";
switch (pointName) {
case YHPN_VIEWCONTROLLER:
str = @"PAGE";
break;
case YHPN_WEBVIEW:
str = @"WEBVIEW";
break;
case YHPN_IMAGEVIEW:
str = @"IMAGE";
break;
case YHPN_BUTTON:
str = @"BUTTON";
break;
case YHPN_GESTURERECOGNIZER:
str = @"GESTURERECOGNIZER";
break;
default:
break;
}
return str;
}
-(NSString *)getDataType:(YHEventReportTrackDataType)type{
NSString *str = @"";
switch (type) {
case YHEventReportTrackDataTypeStart:
str = @"start";
break;
case YHEventReportTrackDataTypeDestory:
str = @"destory";
break;
case YHEventReportTrackDataTypeStop:
str = @"stop";
break;
case YHEventReportTrackDataTypeHeartbeat:
str = @"hb";
break;
case YHEventReportTrackDataTypeNONE:
str = @"realTime";
break;
default:
break;
}
return str;
}
- (void)refreshPushStatus
{
... ... @@ -308,8 +288,7 @@
- (void)handleMemoryWarning
{
if (self.mode == YHEventReportStrategyInterval) {
@synchronized (self) {
//[self.eventCacheArray removeAllObjects];
@synchronized (self.performanceCacheArray) {
[self.performanceCacheArray removeAllObjects];
}
}
... ... @@ -317,26 +296,14 @@
- (void)handleDidFinishLaunch
{
if (self.mode == YHEventReportStrategyInterval) {
@synchronized (self.performanceCacheArray) {
NSMutableArray *data = [[NSMutableArray alloc]initWithCapacity:0];
[data setArray:self.performanceCacheArray];
[self.performanceCacheArray removeAllObjects];
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:data type:YHEventReportTrackDataTypeStart] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
}];
}
[self uploadPerformanceDataWithType:YHEventReportTrackDataTypeStart];
}
}
- (void)handleTerminate
{
if (self.mode == YHEventReportStrategyInterval) {
@synchronized (self.performanceCacheArray) {
NSMutableArray *data = [[NSMutableArray alloc]initWithCapacity:0];
[data setArray:self.performanceCacheArray];
[self.performanceCacheArray removeAllObjects];
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:data type:YHEventReportTrackDataTypeDestory] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
}];
}
[self uploadPerformanceDataWithType:YHEventReportTrackDataTypeDestory];
}
}
... ... @@ -344,27 +311,25 @@
{
[self.performanceAppInfo resetSessionID];
if (self.mode == YHEventReportStrategyInterval) {
@synchronized (self.performanceCacheArray) {
NSMutableArray *data = [[NSMutableArray alloc]initWithCapacity:0];
[data setArray:self.performanceCacheArray];
[self.performanceCacheArray removeAllObjects];
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:data type:YHEventReportTrackDataTypeStop] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
}];
}
[self uploadPerformanceDataWithType:YHEventReportTrackDataTypeStop];
}
}
#pragma mark - timer
- (void)timerAction
{
[self uploadPerformanceDataWithType:YHEventReportTrackDataTypeHeartbeat];
}
#pragma mark - upload performance data
-(void)uploadPerformanceDataWithType:(YHEventReportTrackDataType)type{
@synchronized (self.performanceCacheArray) {
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:[self.performanceCacheArray copy] type:type] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
}];
}
@synchronized (self.performanceCacheArray) {
NSMutableArray *data = [[NSMutableArray alloc]initWithCapacity:0];
[data setArray:self.performanceCacheArray];
[self.performanceCacheArray removeAllObjects];
//if ([data count] > 0) {
[self.eventDataSession uploadPerformanceData:[self getPerformanceFormatData:data type:YHEventReportTrackDataTypeHeartbeat] tag:nil result:^(BOOL isSuc, id tag, NSError *error) {
}];
//}
}
}
... ...
... ... @@ -12,6 +12,7 @@
#import "YHLog.h"
#import "NSData+YHERGZip.h"
#import "NSString+ER_URL.h"
#import "YHEventReport.h"
#define kYOHOEventReportURL @"http://analysis.yohobuy.com/yas_mobile"//@"http://172.16.10.128:8081/eventreport"
... ... @@ -50,6 +51,11 @@
- (void)uploadEventData:(id)parameters tag:(id)tag result:(void (^)(BOOL isSuc,id tag, NSError *error))result
{
#if !TARGET_IPHONE_SIMULATOR
if (![YHEventReport sharedInstance].isClickEventTrackEnabled) {
return;
}
if (!self.canUpload) {
return;
}
... ... @@ -73,10 +79,16 @@
}];
[task resume];
#endif
}
- (void)uploadPerformanceData:(id)parameters tag:(id)tag result:(void (^)(BOOL isSuc,id tag, NSError *error))result
{
#if !TARGET_IPHONE_SIMULATOR
if (![YHEventReport sharedInstance].isPerformanceTrackEnabled) {
return;
}
if (!self.canUpload) {
return;
}
... ... @@ -99,6 +111,7 @@
}];
[task resume];
#endif
}
#pragma mark - private
... ... @@ -108,8 +121,11 @@
return nil;
}
NSError *error;
if (![NSJSONSerialization isValidJSONObject:param]) {
return nil;
}
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:param options:0 error:&error];
if (error) {
return nil;
... ...
... ... @@ -30,12 +30,14 @@ typedef NS_ENUM(NSInteger, YHEventReportStrategy) {
* @abstract
* YHEventReportDataType 上报数据类型。
* YHEventReportDataTypeNormalEvent - 点击数据
* YHEventReportDataTypeClickEvent - 点击数据
* YHEventReportDataTypePerformance - 性能数据
* YHEventReportDataTypeCustom - 业务数据(手动添加的埋点,统计前后台切换、cdn切换、双中心切换、业务数据等)
*/
typedef NS_ENUM(NSInteger, YHEventReportDataType) {
YHEventReportDataTypeNormalEvent,
YHEventReportDataTypeClickEvent,
YHEventReportDataTypePerformance,
YHEventReportDataTypeCustom,
};
/**
... ... @@ -91,6 +93,31 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) {
YHPN_WEBVIEW,//UIWebView 加载时间 // @"WEBVIEW"
YHPN_IMAGEVIEW,//Image (SDWebImage) 加载时间 // @"IMAGE"
YHPN_BUTTON,//Button 响应时间 // @"BUTTON"
YHPN_TIMEOUT, //网络事件 -网络超时
YHPN_CODE_ERR , //网络事件- 有错误码返回的错误
YHPN_H5_FEATURE_META_FAILED, //feature.yoho.cn的H5页面meta校验失败
YHPN_RN_EXCEPTION, //App异常- RN自定义错误
YHPN_CRASH , //App异常- App崩溃
YHPN_CUSTOM_EXCEPTION, //App异常- 自定义异常
YHPN_CDN_CHOOSE, //CDN- cdn选择,启动时上报当前的CDN, 发生CDN切换时再上报切换的CDN
YHPN_CENTER_CHOOSE, //CENTER- 中心选择,启动时上报当前的中心, 发生中心切换时再上报切换的中心
YHPN_APP_PATCHLOAD, //APP补丁- 如果当前客户端在运行过程中使用了某个补丁则上报该事件
YHPN_RN_PATCHLOAD, //RN补丁- 如果当前客户端在运行过程中使用了某个补丁则上报该事件
YHPN_START, //启动
YHPN_RESUME, //进入
YHPN_STOP,//不可见状态
YHPN_DESTROY, //被杀掉
YHPN_PUSH_ACTIVE,//被PUSH拉起, 此状态不影响RESUME的上报
YHPN_T3_ACTIVE,//被3D TOUCH拉起, 此状态不影响RESUME的上报
YHPN_UL_ACTIVE,//被universal link拉起,此状态不影响RESUME的上报
YHPN_APP_ACTIVE,//被第三方APP拉起, 此状态不影响RESUME的上报
YHPN_BUSINESS_USER_LOGIN,//用户登录相关业务错误
YHPN_BUSINESS_USER_REGIST,//用户注册相关业务错误
YHPN_BUSINESS_USER_REPASSWORD,//用户找回密码相关业务错误
YHPN_BUSINESS_ORDER_ADDSHOPPINGCARD,//加入购物车相关业务错误
YHPN_BUSINESS_ORDER_ACCOUNT,//结算订单相关业务错误
YHPN_BUSINESS_ORDER_CONFIRM,//确认订单相关业务错误
YHPN_BUSINESS_ORDER_PAY,//支付相关业务错误
YHPN_GESTURERECOGNIZER //UITapGestureRecognizer响应时间// @"GESTURERECOGNIZER"
};
... ... @@ -104,6 +131,21 @@ typedef NS_ENUM(NSInteger, YHEventLoadStatus) {
YHEventLoadStatusFailed, //加载失败
};
typedef NS_ENUM(NSInteger,YHAPPKey){
YOHOBUY,
};
typedef NS_ENUM(NSInteger, YHPointType) {
YHPT_NETWORK,
YHPT_EXCEPTION,
YHPT_CDN,
YHPT_CENTER,
YHPT_PATCH,
YHPT_LIFECYCLE,
YHPT_BUSINESS,
YHPT_PERFORMANCE,
};
#define YHEventReportDebugModeEnableKey @"YHEventReportDebugModeEnableKey"
... ... @@ -239,4 +281,52 @@ typedef NS_ENUM(NSInteger, YHEventLoadStatus) {
#define YOHOAppReportKeyStyle_C @"YB_AUTO_TRACK"
#define YOHOAppReportErrors @"errors" //错误
#define YOHOAppReportParam @"param" //参数
// 中断和异常参数
#define YOHOAppReportCrashCallstack @"st" // 异常堆栈
#define YOHOAppReportCrashSignal @"sig" // 中断信号量
#define YOHOAppReportCrashSignalName @"sign" // 中断信号名称
#define YOHOAppReportCrashExceptionName @"exn" // 异常名称
#define YOHOAppReportCrashExceptionReason @"exr" // 异常原因
#define YOHOAppReportLogSystemName @"AppReportLogSystem" // 日志文件名称
#define kPathCaches [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define YOHOPathLogSystem [kPathCaches stringByAppendingPathComponent:@"YHLogSystem"] // 日志保存路径
// 运营商
#define kCarrierCodeChinaUnknown @"0" // 未知
#define kCarrierCodeChinaMobile @"1" // 中国移动
#define kCarrierCodeChinaTelecom @"2" // 中国电信
#define kCarrierCodeChinaUnicom @"3" // 中国联通
#define kCarrierCodeChinaTietong @"4" // 中国铁通
//上报参数的key
#define YOHOAppReportKeyAK @"ak"
#define YOHOAppReportKeyUDID @"udid"
#define YOHOAppReportKeyCH @"ch"
#define YOHOAppReportKeyOS @"os"
#define YOHOAppReportKeyOSV @"osv"
#define YOHOAppReportKeyDM @"dm"
#define YOHOAppReportKeyPS @"ps"
#define YOHOAppReportKeyAV @"av"
#define YOHOAppReportKeyAB @"ab"
#define YOHOAppReportKeyCA @"ca"
#define YOHOAppReportKeyNET @"net"
#define YOHOAppReportKeyTS @"ts"
#define YOHOAppReportKeyUID @"uid"
#define YOHOAppReportKeySID @"sid"
#define YOHOAppReportKeyPT @"pt"
#define YOHOAppReportKeyPN @"pn"
#define YOHOAppReportKeyPARAM @"param"
#define YOHOAppReportDefaultAPPKey @"yohobuy_ios"
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self
#endif /* YHEventReportMacros_h */
... ...
... ... @@ -23,6 +23,12 @@
+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer ElapsedTime:(NSTimeInterval)elapsedTime;
+ (NSDictionary *)factoryEventAppInfo:(YH_PerformanceAppInfo*)appInfo;
+(NSDictionary *)factoryEventAppInfo:(YH_PerformanceAppInfo*)appInfo;
+(NSString *)getPointName:(YHEventReportPointName)pointName;
+(NSString *)getPointType:(YHPointType)pointType;
+(NSString *)getDataType:(YHEventReportTrackDataType)type;
@end
... ...
... ... @@ -104,4 +104,163 @@
return commonInfo;
}
+(NSString *)getPointName:(YHEventReportPointName)pointName{
NSString *str = @"";
switch (pointName) {
case YHPN_VIEWCONTROLLER:
str = @"PAGE";
break;
case YHPN_WEBVIEW:
str = @"WEBVIEW";
break;
case YHPN_IMAGEVIEW:
str = @"IMAGE";
break;
case YHPN_BUTTON:
str = @"BUTTON";
break;
case YHPN_GESTURERECOGNIZER:
str = @"GESTURERECOGNIZER";
break;
case YHPN_TIMEOUT:
str = @"TIMEOUT";
break;
case YHPN_CODE_ERR:
str = @"CODE_ERR";
break;
case YHPN_H5_FEATURE_META_FAILED:
str = @"NO_WEBMETA";
break;
case YHPN_RN_EXCEPTION:
str = @"RN_EXCEPTION";
break;
case YHPN_CRASH:
str = @"CRASH";
break;
case YHPN_CUSTOM_EXCEPTION:
str = @"CUSTOM_EXCEPTION";
break;
case YHPN_CDN_CHOOSE:
str = @"CDN_CHOOSE";
break;
case YHPN_CENTER_CHOOSE:
str = @"CENTER_CHOOSE";
break;
case YHPN_APP_PATCHLOAD:
str = @"APP_PATCHLOAD";
break;
case YHPN_RN_PATCHLOAD:
str = @"RN_PATCHLOAD";
break;
case YHPN_START:
str = @"START";
break;
case YHPN_RESUME:
str = @"RESUME";
break;
case YHPN_STOP:
str = @"STOP";
break;
case YHPN_DESTROY:
str = @"DESTROY";
break;
case YHPN_PUSH_ACTIVE:
str = @"PUSH_ACTIVE";
break;
case YHPN_T3_ACTIVE:
str = @"T3_ACTIVE";
break;
case YHPN_UL_ACTIVE:
str = @"UL_ACTIVE";
break;
case YHPN_APP_ACTIVE:
str = @"APP_ACTIVE";
break;
case YHPN_BUSINESS_USER_LOGIN:
str = @"BUSINESS_USER_LOGIN";
break;
case YHPN_BUSINESS_USER_REGIST:
str = @"BUSINESS_USER_REGIST";
break;
case YHPN_BUSINESS_USER_REPASSWORD:
str = @"BUSINESS_USER_REPASSWORD";
break;
case YHPN_BUSINESS_ORDER_ADDSHOPPINGCARD:
str = @"BUSINESS_ORDER_ADDSHOPPINGCARD";
break;
case YHPN_BUSINESS_ORDER_ACCOUNT:
str = @"BUSINESS_ORDER_ACCOUNT";
break;
case YHPN_BUSINESS_ORDER_CONFIRM:
str = @"BUSINESS_ORDER_CONFIRM";
break;
case YHPN_BUSINESS_ORDER_PAY:
str = @"BUSINESS_ORDER_PAY";
break;
default:
break;
}
return str;
}
+(NSString *)getPointType:(YHPointType)pointType{
NSString *str = @"";
switch (pointType) {
case YHPT_NETWORK:
str = @"NETWORK";
break;
case YHPT_EXCEPTION:
str = @"EXCEPTION";
break;
case YHPT_CDN:
str = @"CDN";
break;
case YHPT_CENTER:
str = @"CENTER";
break;
case YHPT_PATCH:
str = @"PATCH";
break;
case YHPT_LIFECYCLE:
str = @"LIFECYCLE";
break;
case YHPT_BUSINESS:
str = @"BUSINESS";
break;
case YHPT_PERFORMANCE:
str = @"PERFORMANCE";
break;
default:
break;
}
return str;
}
+(NSString *)getDataType:(YHEventReportTrackDataType)type{
NSString *str = @"";
switch (type) {
case YHEventReportTrackDataTypeStart:
str = @"start";
break;
case YHEventReportTrackDataTypeDestory:
str = @"destory";
break;
case YHEventReportTrackDataTypeStop:
str = @"stop";
break;
case YHEventReportTrackDataTypeHeartbeat:
str = @"hb";
break;
case YHEventReportTrackDataTypeNONE:
str = @"realTime";
break;
default:
break;
}
return str;
}
@end
... ...
... ... @@ -156,13 +156,8 @@
}
-(NSString *)ts{
long long now = [[NSDate date] timeIntervalSince1970];
long long int date = (long long int)now;
_ts = [NSString stringWithFormat:@"%lld", date];
if (!_ts) {
_ts = @"";
}
return _ts;
long long int date = (long long int)[[NSDate date] timeIntervalSince1970];
return [NSString stringWithFormat:@"%lld", date]?:@"";
}
@end
... ...