Commit ddf12bb5 authored by 汪洋's avatar 汪洋

Merge branch 'yefengming/GMPhobos' into 'master'

Yefengming/gm phobos

See merge request !22
parents 945921bf 2c86f2d8
......@@ -326,6 +326,7 @@ static NSString *sdkVersion = @"110";
// 必须在此处调用一下referer,因为onControllerStart
[page initReferer];
[page initReferrerIdIfNil];
[page initReferrerTabName];
page.inTime = [PhobosUtil currentTime];
}
......@@ -344,6 +345,10 @@ static NSString *sdkVersion = @"110";
[dict setObject:@(0) forKey:@"fake"];
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"];
[dict setObject:page.homeTabName ? : @"" forKey:@"tab_name"];
[dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"];
NSAssert(page.inTime.length > 0, @"页面显示时间不能为空!");
[Phobos track:@"page_view" attributes:dict];
if (page.inTime.length > 0) {
// 页面显示时间为空时不记录页面pv事件
[Phobos track:@"page_view" attributes:dict];
......
......@@ -58,4 +58,14 @@
*/
@property (nonatomic, copy, nonnull) NSString *extraParam;
/**
首页tab名称
*/
@property (nonatomic, copy) NSString *tabName;
/**
获取上一个页面的tab名称
*/
@property (nonatomic, copy) NSString *referrerTabName;
@end
......@@ -19,4 +19,9 @@
此方法在onPvStart时调用,如果发现已经有值了,不会给referrerId再次赋值
*/
- (void)initReferrerIdIfNil;
/**
此方法在onPvStart时调用,给referrerTabName赋值
*/
- (void)initReferrerTabName;
@end
......@@ -45,6 +45,35 @@
}
}
/**
此方法在onPvStart时调用,给referrerTabName赋值
*/
- (void)initReferrerTabName {
// 只有是controller的情况下才自动获取
if ([self isKindOfClass:[UIViewController class]]) {
// 分present与navigation两种情况
UIViewController *me = (UIViewController *)self;
if (me.presentingViewController != nil) {
// app全局只有一个navigation,发现此时用navigation.topViewController presentViewController时,最终使用的是navigation弹出的
// 所以此处要判断,如果是navigation弹出,最后还是要定位到topViewController
if ([me.presentingViewController isKindOfClass:[UINavigationController class]]) {
UIViewController *top = ((UINavigationController *)me.presentingViewController).topViewController;
objc_setAssociatedObject(self, @selector(referrerTabName), top.tabName, OBJC_ASSOCIATION_COPY);
} else {
objc_setAssociatedObject(self, @selector(referrerTabName), me.presentingViewController.tabName, OBJC_ASSOCIATION_COPY);
}
} else {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIndex = navigationPool.count - 2;
if (refererIndex < 0 ) {
return ;
}
UIViewController *controller = navigationPool[refererIndex];
objc_setAssociatedObject(self, @selector(referrerTabName), controller.tabName, OBJC_ASSOCIATION_COPY);
}
}
}
- (void)setReferer:(NSString *)referer {
objc_setAssociatedObject(self, @selector(referer), referer, OBJC_ASSOCIATION_COPY);
}
......@@ -134,4 +163,22 @@
return extraParam == nil ? @"" : extraParam;
}
- (void)setTabName:(NSString *)tabName {
objc_setAssociatedObject(self, @selector(tabName), tabName, OBJC_ASSOCIATION_COPY);
}
- (NSString *)tabName {
NSString *tabName = objc_getAssociatedObject(self, @selector(tabName));
return tabName == nil ? @"" : tabName;
}
- (void)setReferrerTabName:(NSString *)referrerTabName {
objc_setAssociatedObject(self, @selector(referrerTabName), referrerTabName, OBJC_ASSOCIATION_COPY);
}
- (NSString *)referrerTabName {
NSString *referrerTabName = objc_getAssociatedObject(self, @selector(referrerTabName));
return referrerTabName == nil ? @"" : referrerTabName;
}
@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