Commit baf057d6 authored by 刘鹿杰's avatar 刘鹿杰

埋点库添加referrer_Position参数, 方便 AI 落地页埋点链路监控

parent 3d867177
......@@ -50,9 +50,11 @@
/* Begin PBXFileReference section */
259B47496C313B9EC720BD76 /* GMPhobos.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = GMPhobos.podspec; path = ../GMPhobos.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
307F0A9AE09C3400AA3E80C3 /* Pods_GMPhobos_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GMPhobos_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
39F84A4B7451E3C570109001 /* Pods-GMPhobos_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Tests.release.xcconfig"; path = "Target Support Files/Pods-GMPhobos_Tests/Pods-GMPhobos_Tests.release.xcconfig"; sourceTree = "<group>"; };
3E2C3B0828BB1AA652517366 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
5973B392CD963C413ADE924A /* Pods-GMPhobos_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-GMPhobos_Example/Pods-GMPhobos_Example.release.xcconfig"; sourceTree = "<group>"; };
5A925189F951EA5E99801E5F /* Pods-GMPhobos_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-GMPhobos_Tests/Pods-GMPhobos_Tests.release.xcconfig"; sourceTree = "<group>"; };
5BECCE13A9644D7FC0ABE491 /* Pods-GMPhobos_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Example.release.xcconfig"; path = "Target Support Files/Pods-GMPhobos_Example/Pods-GMPhobos_Example.release.xcconfig"; sourceTree = "<group>"; };
5C8C0EC8AB1257BC31A5BCFC /* Pods-GMPhobos_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GMPhobos_Tests/Pods-GMPhobos_Tests.debug.xcconfig"; sourceTree = "<group>"; };
6003F58A195388D20070C39A /* GMPhobos_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GMPhobos_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
......@@ -76,6 +78,7 @@
63EFAB0E22658352005EEAC6 /* GMPhobos_ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GMPhobos_ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
63EFAB1022658352005EEAC6 /* GMPhobos_ExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GMPhobos_ExampleTests.m; sourceTree = "<group>"; };
63EFAB1222658352005EEAC6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
773D510F733436C849F61689 /* Pods-GMPhobos_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Example.debug.xcconfig"; path = "Target Support Files/Pods-GMPhobos_Example/Pods-GMPhobos_Example.debug.xcconfig"; sourceTree = "<group>"; };
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
94F09197043C44CCA8756031 /* Pods-GMPhobos_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GMPhobos_Example/Pods-GMPhobos_Example.debug.xcconfig"; sourceTree = "<group>"; };
D321A04E1F4A8F4100A6B934 /* Launch Screen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
......@@ -86,6 +89,7 @@
E49977051C59F40000623ABA /* GMPhotoTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GMPhotoTest.m; sourceTree = "<group>"; };
E4AF92BF1C71C6C700CF0B64 /* GMPhobosUtilTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GMPhobosUtilTest.m; sourceTree = "<group>"; };
E4AF92C31C71CCE600CF0B64 /* libz.1.2.5.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.1.2.5.tbd; path = usr/lib/libz.1.2.5.tbd; sourceTree = SDKROOT; };
EBFF902F7DDD31799747B1A0 /* Pods-GMPhobos_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GMPhobos_Tests.debug.xcconfig"; path = "Target Support Files/Pods-GMPhobos_Tests/Pods-GMPhobos_Tests.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -130,7 +134,7 @@
63EFAB0F22658352005EEAC6 /* GMPhobos_ExampleTests */,
6003F58C195388D20070C39A /* Frameworks */,
6003F58B195388D20070C39A /* Products */,
F0A9B46EC6044F749D0CDBCA /* Pods */,
DD770357FB89002C494C140E /* Pods */,
);
sourceTree = "<group>";
};
......@@ -204,6 +208,7 @@
6003F5B7195388D20070C39A /* Tests-Info.plist */,
6003F5B8195388D20070C39A /* InfoPlist.strings */,
606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */,
F0A9B46EC6044F749D0CDBCA /* Pods */,
);
name = "Supporting Files";
sourceTree = "<group>";
......@@ -227,6 +232,18 @@
path = GMPhobos_ExampleTests;
sourceTree = "<group>";
};
DD770357FB89002C494C140E /* Pods */ = {
isa = PBXGroup;
children = (
773D510F733436C849F61689 /* Pods-GMPhobos_Example.debug.xcconfig */,
5BECCE13A9644D7FC0ABE491 /* Pods-GMPhobos_Example.release.xcconfig */,
EBFF902F7DDD31799747B1A0 /* Pods-GMPhobos_Tests.debug.xcconfig */,
39F84A4B7451E3C570109001 /* Pods-GMPhobos_Tests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
F0A9B46EC6044F749D0CDBCA /* Pods */ = {
isa = PBXGroup;
children = (
......@@ -236,6 +253,7 @@
5A925189F951EA5E99801E5F /* Pods-GMPhobos_Tests.release.xcconfig */,
);
name = Pods;
path = ..;
sourceTree = "<group>";
};
/* End PBXGroup section */
......@@ -601,7 +619,7 @@
};
6003F5C0195388D20070C39A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 94F09197043C44CCA8756031 /* Pods-GMPhobos_Example.debug.xcconfig */;
baseConfigurationReference = 773D510F733436C849F61689 /* Pods-GMPhobos_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
......@@ -622,7 +640,7 @@
};
6003F5C1195388D20070C39A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5973B392CD963C413ADE924A /* Pods-GMPhobos_Example.release.xcconfig */;
baseConfigurationReference = 5BECCE13A9644D7FC0ABE491 /* Pods-GMPhobos_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
......@@ -641,7 +659,7 @@
};
6003F5C3195388D20070C39A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5C8C0EC8AB1257BC31A5BCFC /* Pods-GMPhobos_Tests.debug.xcconfig */;
baseConfigurationReference = EBFF902F7DDD31799747B1A0 /* Pods-GMPhobos_Tests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_IDENTITY = "iPhone Developer";
......@@ -668,7 +686,7 @@
};
6003F5C4195388D20070C39A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5A925189F951EA5E99801E5F /* Pods-GMPhobos_Tests.release.xcconfig */;
baseConfigurationReference = 39F84A4B7451E3C570109001 /* Pods-GMPhobos_Tests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_IDENTITY = "iPhone Developer";
......
......@@ -7,11 +7,17 @@
//
#import "GMAppDelegate.h"
#import <Phobos.h>
@implementation GMAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Phobos sharedClient].getTopController = ^UIViewController * _Nonnull{
return [UIViewController new];
};
// Override point for customization after application launch.
return YES;
}
......
......@@ -35,9 +35,9 @@ PODS:
- GMKit/Protocol (1.1.3):
- Masonry (= 1.1.0)
- SDWebImage (= 3.7.6)
- GMPhobos (1.2.9):
- GMCache (= 0.2.3)
- GMKit (= 1.1.3)
- GMPhobos (1.3.0):
- GMCache
- GMKit
- Masonry (1.1.0)
- SDWebImage (3.7.6):
- SDWebImage/Core (= 3.7.6)
......@@ -63,7 +63,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639
GMKit: 35f788243cceeddf3e13c5226b3ea0b5e08e2117
GMPhobos: 89d9654a951819abc9285b392e055278d10877f2
GMPhobos: c1dd33760f8d4243e6bf562a115899e66c6ec7d2
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
......
......@@ -349,6 +349,7 @@ static NSString *sdkVersion = @"110";
- (void)onPVStart:(UIResponder<PhobosPVProtocol> *)page {
// 必须在此处调用一下referer,因为onControllerStart
[page initReferer];
[page initReferrerPosition];
[page initReferrerIdIfNil];
[page initReferrerTabName];
page.inTime = [PhobosUtil currentTime];
......@@ -358,6 +359,8 @@ static NSString *sdkVersion = @"110";
if (![PhobosUtil isNonEmpty:page.pageName] || !page.needLogPV) {
return;
}
// 如果referrer_position存在,添加 referrerPosition 参数
[self addReferrerPosition:page];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try {
......@@ -408,6 +411,13 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1
*/
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes{
// 点击事件 referrer_position
NSMutableDictionary *attributesParams = [NSMutableDictionary dictionaryWithDictionary:attributes];
NSString *referrerPosition = sharedClient.visibleController.referrerPosition;
if (![eventId isEqualToString:@"page_view"] && ![referrerPosition isEqualToString:@""]) {
[attributesParams setValue:referrerPosition forKey:@"referrer_position"];
}
[self catchNullForEvent:eventId attributes:attributes];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try {
......@@ -683,4 +693,45 @@ static NSString *sdkVersion = @"110";
[self.APIArray addObject:api];
}
}
// 字符串转字典
- (NSDictionary *)dictionaryWithJsonString:(NSString *)pageExtraParam {
NSData *jsonData = [pageExtraParam dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingMutableContainers
error:&err];
if(err) {
NSLog(@"json解析失败:%@",err);
return nil;
}
return dic;
}
// 字典转字符串
- (NSString *)jsonStringWithDictionary:(NSDictionary *)dictionary {
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
// 添加 ReferrerPosition 逻辑封装
- (NSString *)addReferrerPosition:(UIResponder<PhobosPVProtocol> *)page{
// 如果referrer_position存在,添加 referrerPosition 参数
if (![page.referrerPosition isEqualToString:@""]) {
if (![page.extraParam isEqualToString:@""]) {
NSMutableDictionary *extraParamDict = [self dictionaryWithJsonString:page.extraParam];
// 当为用户贴时 page.extraParam = user_post, 此时不是字典。
// 防止page.extraParam为其它格式数据,当解析字典不成功时 不再添加 referrer_position
if (extraParamDict == nil) { return page.extraParam; }
[extraParamDict setValue:page.referrerPosition forKey:@"referrer_position"];
page.extraParam = [self jsonStringWithDictionary:extraParamDict];
}else{
page.extraParam = [self jsonStringWithDictionary:@{@"referrer_position" : page.referrerPosition}];
}
}
return page.extraParam;
}
@end
......@@ -75,5 +75,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, copy) NSString *isPush;
/**
获取上一个页面的referrer_position by 7.20.0 如果有则添加, 没有则不添加
*/
@property (nonatomic, copy) NSString *referrerPosition;
@end
NS_ASSUME_NONNULL_END
......@@ -15,6 +15,11 @@
*/
- (void)initReferer;
/**
只适用于当为AI落地页的时候, 链路中页面浏览PV 添加 ReferrerPosition 参数
*/
- (void)initReferrerPosition;
/**
此方法在onPvStart时调用,如果发现已经有值了,不会给referrerId再次赋值
*/
......
......@@ -45,6 +45,41 @@
}
}
// 只适用于当为AI落地页的时候, 链路中页面浏览PV 添加 ReferrerPosition 参数
- (void)initReferrerPosition {
if ([self.referrerPosition isEqualToString:@""] && [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(referrerPosition), top.referrerPosition, OBJC_ASSOCIATION_COPY);
} else {
objc_setAssociatedObject(self, @selector(referrerPosition), me.presentingViewController.referrerPosition, 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(referrerPosition), controller.referrerPosition, OBJC_ASSOCIATION_COPY);
}
}
}
- (void)setReferrerPosition:(NSString *)referrerPosition {
objc_setAssociatedObject(self, @selector(referrerPosition), referrerPosition, OBJC_ASSOCIATION_COPY);
}
- (NSString *)referrerPosition {
NSString *referrerPosition = objc_getAssociatedObject(self, @selector(referrerPosition));
return referrerPosition == nil ? @"" : referrerPosition;
}
/**
此方法在onPvStart时调用,给referrerTabName赋值
*/
......
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