Commit f2862f77 authored by 叶凤鸣's avatar 叶凤鸣

加tabName

parent aa7c8cd2
......@@ -303,6 +303,7 @@ static NSString *sdkVersion = @"110";
// 必须在此处调用一下referer,因为onControllerStart
[page initReferer];
[page initReferrerIdIfNil];
[page initHomeTabName];
page.inTime = [PhobosUtil currentTime];
}
......@@ -321,7 +322,7 @@ 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.currentTabName ? : @"" forKey:@"tab_name"];
NSAssert(page.inTime.length > 0, @"页面显示时间不能为空!");
[Phobos track:@"page_view" attributes:dict];
}
......
......@@ -59,8 +59,13 @@
@property (nonatomic, copy, nonnull) NSString *extraParam;
/**
上一个页面tab名称
首页tab名称
*/
@property (nonatomic, copy) NSString *homeTabName;
/**
获取上一个页面的tab名称
*/
@property (nonatomic, copy) NSString *currentTabName;
@end
......@@ -19,4 +19,9 @@
此方法在onPvStart时调用,如果发现已经有值了,不会给referrerId再次赋值
*/
- (void)initReferrerIdIfNil;
/**
此方法在onPvStart时调用,给currentTabName赋值
*/
- (void)initHomeTabName;
@end
......@@ -45,6 +45,41 @@
}
}
/**
此方法在onPvStart时调用,给currentTabName赋值,来源为首页时,才给currentTabName赋值,因为首页的pageName为home或者zone_v3,聚合页的pageName也是zone_v3,所以根据referer判断来源可能为首页或者聚合页,但是只有首页有tab名称,所以currentTabName为首页tab名称
*/
- (void)initHomeTabName {
// 只有不为空,且是controller的情况下才自动获取
if (([self.referer isEqualToString:@"home"] || [self.referer isEqualToString:@"zone_v3"]) && [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;
if (![top.homeTabName isEqualToString:@""]) {
objc_setAssociatedObject(self, @selector(currentTabName), top.homeTabName, OBJC_ASSOCIATION_COPY);
}
} else {
if (![me.presentingViewController.homeTabName isEqualToString:@""]) {
objc_setAssociatedObject(self, @selector(currentTabName), me.presentingViewController.homeTabName, OBJC_ASSOCIATION_COPY);
}
}
} else {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIndex = navigationPool.count - 2;
if (refererIndex < 0 ) {
return ;
}
UIViewController *controller = navigationPool[refererIndex];
if (![controller.homeTabName isEqualToString:@""]) {
objc_setAssociatedObject(self, @selector(currentTabName), controller.homeTabName, OBJC_ASSOCIATION_COPY);
}
}
}
}
- (void)setReferer:(NSString *)referer {
objc_setAssociatedObject(self, @selector(referer), referer, OBJC_ASSOCIATION_COPY);
}
......@@ -143,4 +178,13 @@
return homeTabName == nil ? @"" : homeTabName;
}
- (void)setCurrentTabName:(NSString *)currentTabName {
objc_setAssociatedObject(self, @selector(currentTabName), currentTabName, OBJC_ASSOCIATION_COPY);
}
- (NSString *)currentTabName {
NSString *currentTabName = objc_getAssociatedObject(self, @selector(currentTabName));
return currentTabName == nil ? @"" : currentTabName;
}
@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