Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMPhobos
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMPhobos
Commits
a68c9258
Commit
a68c9258
authored
Dec 11, 2019
by
刘鹿杰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
全局添加referer_link参数
parent
baf057d6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
68 deletions
+28
-68
GMAppDelegate.m
Example/GMPhobos/GMAppDelegate.m
+1
-3
Phobos.m
GMPhobos/Classes/Phobos.m
+6
-50
PhobosPVProtocol.h
GMPhobos/Classes/PhobosPVProtocol.h
+2
-2
UIResponder+PhobosPV.h
GMPhobos/Classes/UIResponder+PhobosPV.h
+2
-2
UIResponder+PhobosPV.m
GMPhobos/Classes/UIResponder+PhobosPV.m
+17
-11
No files found.
Example/GMPhobos/GMAppDelegate.m
View file @
a68c9258
...
...
@@ -13,11 +13,9 @@
-
(
BOOL
)
application
:(
UIApplication
*
)
application
didFinishLaunchingWithOptions
:(
NSDictionary
*
)
launchOptions
{
[
Phobos
sharedClient
].
getTopController
=
^
UIViewController
*
_Nonnull
{
Phobos
.
sharedClient
.
getTopController
=
^
UIViewController
*
_Nonnull
{
return
[
UIViewController
new
];
};
// Override point for customization after application launch.
return
YES
;
}
...
...
GMPhobos/Classes/Phobos.m
View file @
a68c9258
...
...
@@ -349,7 +349,7 @@ static NSString *sdkVersion = @"110";
-
(
void
)
onPVStart
:
(
UIResponder
<
PhobosPVProtocol
>
*
)
page
{
// 必须在此处调用一下referer,因为onControllerStart
[
page
initReferer
];
[
page
initRefer
rerPosition
];
[
page
initRefer
erLink
];
[
page
initReferrerIdIfNil
];
[
page
initReferrerTabName
];
page
.
inTime
=
[
PhobosUtil
currentTime
];
...
...
@@ -359,9 +359,6 @@ static NSString *sdkVersion = @"110";
if
(
!
[
PhobosUtil
isNonEmpty
:
page
.
pageName
]
||
!
page
.
needLogPV
)
{
return
;
}
// 如果referrer_position存在,添加 referrerPosition 参数
[
self
addReferrerPosition
:
page
];
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
@try
{
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
...
...
@@ -369,11 +366,13 @@ 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
.
refererLink
?
:
@[]
forKey
:
@"referer_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"
];
if
(
page
.
inTime
.
length
>
0
)
{
// 页面显示时间为空时不记录页面pv事件
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
...
...
@@ -411,13 +410,10 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1
*/
-
(
NSDictionary
*
)
prepareDictionaryForEvent
:
(
NSString
*
)
eventId
attributes
:
(
NSDictionary
*
)
attributes
{
// 点击事件 referrer_position
NSArray
*
refererLink
=
sharedClient
.
visibleController
.
refererLink
;
NSMutableDictionary
*
attributesParams
=
[
NSMutableDictionary
dictionaryWithDictionary
:
attributes
];
NSString
*
referrerPosition
=
sharedClient
.
visibleController
.
referrerPosition
;
if
(
!
[
eventId
isEqualToString
:
@"page_view"
]
&&
!
[
referrerPosition
isEqualToString
:
@""
])
{
[
attributesParams
setValue
:
referrerPosition
forKey
:
@"referrer_position"
];
}
[
attributesParams
setValue
:
refererLink
?
:
@[]
forKey
:
@"referer_Link"
];
attributes
=
attributesParams
;
[
self
catchNullForEvent
:
eventId
attributes
:
attributes
];
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
@try
{
...
...
@@ -694,44 +690,4 @@ static NSString *sdkVersion = @"110";
}
}
// 字符串转字典
-
(
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
GMPhobos/Classes/PhobosPVProtocol.h
View file @
a68c9258
...
...
@@ -76,9 +76,9 @@ NS_ASSUME_NONNULL_BEGIN
@property
(
nonatomic
,
copy
)
NSString
*
isPush
;
/**
获取上一个页面
的referrer_position by 7.20.0 如果有则添加, 没有则不添加
获取上一个页面
链路的page_name link by 7.20.0 如果有此页面有page_name则添加 , 没有添加""
*/
@property
(
nonatomic
,
copy
)
NS
String
*
referrerPosition
;
@property
(
nonatomic
,
copy
)
NS
Array
*
refererLink
;
@end
...
...
GMPhobos/Classes/UIResponder+PhobosPV.h
View file @
a68c9258
...
...
@@ -16,9 +16,9 @@
-
(
void
)
initReferer
;
/**
只适用于当为AI落地页的时候, 链路中页面浏览PV 添加 ReferrerPosition
参数
// 只适用于链路中页面浏览PVLink 添加 refererLink
参数
*/
-
(
void
)
initRefer
rerPosition
;
-
(
void
)
initRefer
erLink
;
/**
此方法在onPvStart时调用,如果发现已经有值了,不会给referrerId再次赋值
...
...
GMPhobos/Classes/UIResponder+PhobosPV.m
View file @
a68c9258
...
...
@@ -45,9 +45,9 @@
}
}
// 只适用于
当为AI落地页的时候, 链路中页面浏览PV 添加 ReferrerPosition
参数
-
(
void
)
initRefer
rerPosition
{
if
([
self
.
referrerPosition
isEqualToString
:
@""
]
&&
[
self
isKindOfClass
:[
UIViewController
class
]])
{
// 只适用于
链路中页面浏览PVLink 添加 refererLink
参数
-
(
void
)
initRefer
erLink
{
if
([
self
isKindOfClass
:[
UIViewController
class
]])
{
// 分present与navigation两种情况
UIViewController
*
me
=
(
UIViewController
*
)
self
;
if
(
me
.
presentingViewController
!=
nil
)
{
...
...
@@ -55,9 +55,13 @@
// 所以此处要判断,如果是navigation弹出,最后还是要定位到topViewController
if
([
me
.
presentingViewController
isKindOfClass
:[
UINavigationController
class
]])
{
UIViewController
*
top
=
((
UINavigationController
*
)
me
.
presentingViewController
).
topViewController
;
objc_setAssociatedObject
(
self
,
@selector
(
referrerPosition
),
top
.
referrerPosition
,
OBJC_ASSOCIATION_COPY
);
NSMutableArray
*
tempRefererLink
=
[
NSMutableArray
arrayWithArray
:
top
.
refererLink
];
[
tempRefererLink
addObject
:
top
.
pageName
];
objc_setAssociatedObject
(
self
,
@selector
(
pageLink
),
tempRefererLink
,
OBJC_ASSOCIATION_COPY
);
}
else
{
objc_setAssociatedObject
(
self
,
@selector
(
referrerPosition
),
me
.
presentingViewController
.
referrerPosition
,
OBJC_ASSOCIATION_COPY
);
NSMutableArray
*
tempRefererLink
=
[
NSMutableArray
arrayWithArray
:
me
.
presentingViewController
.
refererLink
];
[
tempRefererLink
addObject
:
me
.
presentingViewController
.
pageName
];
objc_setAssociatedObject
(
self
,
@selector
(
pageLink
),
tempRefererLink
,
OBJC_ASSOCIATION_COPY
);
}
}
else
{
NSArray
*
navigationPool
=
((
UIViewController
*
)
self
).
navigationController
.
viewControllers
;
...
...
@@ -66,18 +70,20 @@
return
;
}
UIViewController
*
controller
=
navigationPool
[
refererIndex
];
objc_setAssociatedObject
(
self
,
@selector
(
referrerPosition
),
controller
.
referrerPosition
,
OBJC_ASSOCIATION_COPY
);
NSMutableArray
*
tempRefererLink
=
[
NSMutableArray
arrayWithArray
:
controller
.
refererLink
];
[
tempRefererLink
addObject
:
controller
.
pageName
];
objc_setAssociatedObject
(
self
,
@selector
(
refererLink
),
tempRefererLink
,
OBJC_ASSOCIATION_COPY
);
}
}
}
-
(
void
)
setRefer
rerPosition
:
(
NSString
*
)
referrerPosition
{
objc_setAssociatedObject
(
self
,
@selector
(
refer
rerPosition
),
referrerPosition
,
OBJC_ASSOCIATION_COPY
);
-
(
void
)
setRefer
erLink
:
(
NSArray
*
)
refererLink
{
objc_setAssociatedObject
(
self
,
@selector
(
refer
erLink
),
refererLink
,
OBJC_ASSOCIATION_COPY
);
}
-
(
NSString
*
)
referrerPosition
{
NS
String
*
referrerPosition
=
objc_getAssociatedObject
(
self
,
@selector
(
referrerPosition
));
return
refer
rerPosition
==
nil
?
@""
:
referrerPosition
;
-
(
NSArray
*
)
refererLink
{
NS
Array
*
refererLink
=
objc_getAssociatedObject
(
self
,
@selector
(
refererLink
));
return
refer
erLink
;
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment