Commit 31344624 authored by 井庆林's avatar 井庆林

merge

parent 049fe1cc
......@@ -119,12 +119,15 @@ static NSString *sdkVersion = @"1.4.0";
}
- (UIViewController *)visibleController {
id target = self.getTopController();
if (self.getTopController) {
id target = self.getTopController();
if ([target conformsToProtocol:NSProtocolFromString(@"PhobosCustomVisibleController")]) {
target = [target performSelector:@selector(phobosVisibleController)];
if ([target conformsToProtocol:NSProtocolFromString(@"PhobosCustomVisibleController")]) {
target = [target performSelector:@selector(phobosVisibleController)];
}
return target;
}
return target;
return nil;
}
#pragma mark - notification handler
......@@ -247,6 +250,12 @@ static NSString *sdkVersion = @"1.4.0";
[page initReferrerIdIfNil];
[page initReferrerTabName];
page.inTime = [PhobosUtil currentTime];
page.inTimeMillis = [PhobosUtil currentMMTime];
// 业务层更新
if (page.updatePVStartBlock) {
page.updatePVStartBlock();
}
}
- (void)onPVEnd:(UIResponder<PhobosPVProtocol> *)page {
......@@ -261,12 +270,18 @@ static NSString *sdkVersion = @"1.4.0";
[dict setObject:page.pageName forKey:@"page_name"];
[dict setObject:page.businessId?:@"" forKey:@"business_id"];
[dict setObject:page.referer?:@"" forKey:@"referrer"];
[dict setObject:page.referrerLink ? : @[] forKey:@"referrer_link"];
if ([page.referrerLink isKindOfClass:[NSArray class]] && page.referrerLink.count) {
[dict setObject:page.referrerLink forKey:@"referrer_link"];
} else {
[dict setObject:@[] forKey:@"referrer_link"];
}
[dict setObject:@(0) forKey:@"fake"];
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"];
[dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"];
[dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"];
[dict setObject:page.inTimeMillis?:@"" forKey:@"in_time_millis"];
[dict setObject:[PhobosUtil currentMMTime] forKey:@"out_time_millis"];
if (page.inTime.length > 0) {
// 页面显示时间为空时不记录页面pv事件
......@@ -283,11 +298,16 @@ static NSString *sdkVersion = @"1.4.0";
*
* @since 0.0.1
*/
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventName attributes:(NSDictionary *)attributes{
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventName attributes:(NSDictionary *)attributes {
NSArray *referrerLink = _sharedClient.visibleController.referrerLink;
if (![eventName isEqualToString:@"page_view"]) {
// 对于埋点没有referrer_link的情况,在这里进行统一添加
if (![attributes.allKeys containsObject:@"referrer_link"]) {
NSMutableDictionary *attributesParams = [NSMutableDictionary dictionaryWithDictionary:attributes];
[attributesParams setValue:referrerLink ? : @[] forKey:@"referrer_link"];
if ([referrerLink isKindOfClass:[NSArray class]] && referrerLink.count) {
[attributesParams setValue:referrerLink forKey:@"referrer_link"];
} else {
[attributesParams setValue:@[] forKey:@"referrer_link"];
}
attributes = attributesParams;
}
[self catchNullForEvent:eventName attributes:attributes];
......@@ -322,14 +342,16 @@ static NSString *sdkVersion = @"1.4.0";
if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) {
[dict setObject:@(0) forKey:@"is_release"];
}
NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]];
[dict setObject:eventName forKey:@"type"];
[dict setObject:appParams forKey:@"app"];
[dict setObject:sdkVersion forKey:@"version"];
[dict setObject:deviceParams forKey:@"device"];
[dict setObject:_userId forKey:@"user_id"];
[dict setObject:currentTime forKey:@"create_at"];
[dict setObject:@([[NSProcessInfo processInfo] systemUptime]) forKey:@"nano_time"];
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];
[dict setObject:currentTime forKey:@"create_at"];// 1584513842 当前时间(秒)
[dict setObject:nano_time?:@"" forKey:@"nano_time"];// 1657008897 系统启动后时长(秒)
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒)
[dict setObject:[PhobosUtil currentMMTime] forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒)
[dict setObject:attributes forKey:@"params"];
[dict setObject:_sessionId forKey:@"app_session_id"];
}
......
......@@ -112,12 +112,15 @@ static NSString *sdkVersion = @"110";
}
- (UIViewController *)visibleController {
id target = self.getTopController();
if (self.getTopController) {
id target = self.getTopController();
if ([target conformsToProtocol:NSProtocolFromString(@"PhobosCustomVisibleController")]) {
target = [target performSelector:@selector(phobosVisibleController)];
if ([target conformsToProtocol:NSProtocolFromString(@"PhobosCustomVisibleController")]) {
target = [target performSelector:@selector(phobosVisibleController)];
}
return target;
}
return target;
return nil;
}
#pragma mark - notification handler
......@@ -329,6 +332,11 @@ static NSString *sdkVersion = @"110";
[page initReferrerIdIfNil];
[page initReferrerTabName];
page.inTime = [PhobosUtil currentTime];
page.inTimeMillis = [PhobosUtil currentMMTime];
// 业务层更新
if (page.updatePVStartBlock) {
page.updatePVStartBlock();
}
}
- (void)onPVEnd:(UIResponder<PhobosPVProtocol> *)page {
......@@ -343,7 +351,11 @@ static NSString *sdkVersion = @"110";
[dict setObject:page.pageName forKey:@"page_name"];
[dict setObject:page.businessId?:@"" forKey:@"business_id"];
[dict setObject:page.referer?:@"" forKey:@"referrer"];
[dict setObject:page.referrerLink ? : @[] forKey:@"referrer_link"];
if ([page.referrerLink isKindOfClass:[NSArray class]] && page.referrerLink.count) {
[dict setObject:page.referrerLink forKey:@"referrer_link"];
} else {
[dict setObject:@[] forKey:@"referrer_link"];
}
[dict setObject:@(0) forKey:@"fake"];
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"];
......@@ -387,9 +399,14 @@ static NSString *sdkVersion = @"110";
*/
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes{
NSArray *referrerLink = sharedClient.visibleController.referrerLink;
if (![eventId isEqualToString:@"page_view"]) {
// 对于埋点没有referrer_link的情况,在这里进行统一添加
if (![attributes.allKeys containsObject:@"referrer_link"]) {
NSMutableDictionary *attributesParams = [NSMutableDictionary dictionaryWithDictionary:attributes];
[attributesParams setValue:referrerLink ? : @[] forKey:@"referrer_link"];
if ([referrerLink isKindOfClass:[NSArray class]] && referrerLink.count) {
[attributesParams setValue:referrerLink forKey:@"referrer_link"];
} else {
[attributesParams setValue:@[] forKey:@"referrer_link"];
}
attributes = attributesParams;
}
[self catchNullForEvent:eventId attributes:attributes];
......@@ -421,14 +438,16 @@ static NSString *sdkVersion = @"110";
if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) {
[dict setObject:@(0) forKey:@"is_release"];
}
NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]];
[dict setObject:eventId forKey:@"type"];
[dict setObject:appParams forKey:@"app"];
[dict setObject:sdkVersion forKey:@"version"];
[dict setObject:deviceParams forKey:@"device"];
[dict setObject:_userId forKey:@"user_id"];
[dict setObject:currentTime forKey:@"create_at"];
[dict setObject:@([[NSProcessInfo processInfo] systemUptime]) forKey:@"nano_time"];
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];
[dict setObject:currentTime forKey:@"create_at"];// 1584513842 当前时间(秒)
[dict setObject:nano_time?:@"" forKey:@"nano_time"];// 1657008897 系统启动后时长(秒)
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒)
[dict setObject:[PhobosUtil currentMMTime] forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒)
[dict setObject:attributes forKey:@"params"];
[dict setObject:_sessionId forKey:@"app_session_id"];
}
......
......@@ -10,6 +10,8 @@
NS_ASSUME_NONNULL_BEGIN
@protocol PhobosPVProtocol <NSObject>
typedef void(^PhobosUpdatePVBlock)(void);
/**
* @author 翟国钧, 16-02-24 17:02:22
*
......@@ -42,6 +44,9 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, copy, nonnull) NSString *inTime;
/// 当前VC.view 显示的时候的时间戳(精确到毫秒)
@property (nonatomic, copy, nonnull) NSString *inTimeMillis;
/**
前一个页面的businessId。该属性有可能为空字符串
*/
......@@ -80,6 +85,10 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, copy) NSArray *referrerLink;
/// 业务层更新PVStart信息
@property (nonatomic, copy) PhobosUpdatePVBlock updatePVStartBlock;
/// 业务层更新PVEnd信息
@property (nonatomic, copy) PhobosUpdatePVBlock updatePVEndBlock;
@end
NS_ASSUME_NONNULL_END
......@@ -436,7 +436,7 @@
}
/**
* 获取手机运行时间,从开机到现在
* 获取手机运行时间,从开机到现在(秒)
*/
+ (NSString *)deviceRunTime {
struct timeval boottime;
......
......@@ -161,6 +161,15 @@
return inTime;
}
- (void)setInTimeMillis:(NSString *)inTimeMillis {
objc_setAssociatedObject(self, @selector(inTimeMillis), inTimeMillis, OBJC_ASSOCIATION_COPY);
}
- (NSString *)inTimeMillis {
NSString *inTimeMillis = objc_getAssociatedObject(self, @selector(inTimeMillis));
return inTimeMillis;
}
- (void)initReferrerIdIfNil {
// 只有不为空,且是controller的情况下才自动获取
if ([self.referrerId isEqualToString:@""] && [self isKindOfClass:[UIViewController class]]) {
......@@ -236,4 +245,22 @@
return isPush == nil ? @"" : isPush;
}
- (void)setUpdatePVStartBlock:(PhobosUpdatePVBlock)updatePVStartBlock {
objc_setAssociatedObject(self, @selector(updatePVStartBlock), updatePVStartBlock, OBJC_ASSOCIATION_COPY);
}
- (PhobosUpdatePVBlock)updatePVStartBlock {
PhobosUpdatePVBlock updatePVBlock = objc_getAssociatedObject(self, @selector(updatePVStartBlock));
return updatePVBlock;
}
- (void)setUpdatePVEndBlock:(PhobosUpdatePVBlock)updatePVEndBlock {
objc_setAssociatedObject(self, @selector(updatePVEndBlock), updatePVEndBlock, OBJC_ASSOCIATION_COPY);
}
- (PhobosUpdatePVBlock)updatePVEndBlock {
PhobosUpdatePVBlock updatePVBlock = objc_getAssociatedObject(self, @selector(updatePVEndBlock));
return updatePVBlock;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment