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
0495bdd9
Commit
0495bdd9
authored
Mar 25, 2020
by
乔金柱
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ajp/7.24.0_addParam' into 'master'
Ajp/7.24.0 add param See merge request
!47
parents
fe46540b
d215d30e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
96 deletions
+156
-96
Podfile.lock
Example/Podfile.lock
+1
-1
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+79
-82
Phobos.m
GMPhobos/Classes/Phobos.m
+38
-11
PhobosPVProtocol.h
GMPhobos/Classes/PhobosPVProtocol.h
+9
-0
PhobosUtil.m
GMPhobos/Classes/PhobosUtil.m
+1
-1
UIResponder+PhobosPV.m
GMPhobos/Classes/UIResponder+PhobosPV.m
+28
-1
No files found.
Example/Podfile.lock
View file @
0495bdd9
...
...
@@ -70,4 +70,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad
COCOAPODS: 1.
8.4
COCOAPODS: 1.
9.0
Example/Tests/GMPhotoTest.m
View file @
0495bdd9
...
...
@@ -9,7 +9,8 @@
#import <XCTest/XCTest.h>
#import <GMPhobos/Phobos.h>
#import "GMPhobosController.h"
#import <GMCache/GMCache.h>
#define PhobosCacheKey @"PhobosCacheKey"
@import
GMCache
;
NSString
*
const
MockAppName
=
@"gengmei_test"
;
NSString
*
const
MockChannelId
=
@"AppStore"
;
...
...
@@ -18,25 +19,26 @@ NSString *const MockUserId = @"1";
NSString
*
const
MockCityId
=
@"beijing"
;
@interface
GMPhotoTest
:
XCTestCase
@property
Phobos
*
client
;
@end
///[NSThread sleepForTimeInterval:0.2]; 因为是异步处理数据,所以需要延迟获取,进行单元测试
@implementation
GMPhotoTest
-
(
void
)
setUp
{
[
super
setUp
];
[
Phobos
clientWithAppName
:
MockAppName
channelId
:
MockChannelId
];
Phobos
.
sharedClient
.
serverAPI
=
@"http://log.test.igengmei.com/log/collect"
;
Phobos
.
sharedClient
.
logEnabled
=
NO
;
// 调试打Log模式,看情况开启
Phobos
.
sharedClient
.
signingType
=
PhobosSigningTypeDebug
;
Phobos
.
sharedClient
.
userId
=
@""
;
_client
=
[
Phobos
clientWithAppName
:
MockAppName
channelId
:
MockChannelId
];
_client
.
serverAPI
=
@"http://log.test.igengmei.com/log/collect"
;
[
_client
setLogEnabled
:
NO
];
// 调试打Log模式,看情况开启
_client
.
signingType
=
PhobosSigningTypeDebug
;
_client
.
userId
=
@""
;
[
Phobos
setSharedClient
:
_client
];
}
-
(
void
)
tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[
super
tearDown
];
[
Phobos
removeAllNormalPhobosData
];
[
Phobos
removeAllImmediatelyPhobosData
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
}
/**
...
...
@@ -45,12 +47,10 @@ NSString *const MockCityId = @"beijing";
* @since <#version number#>
*/
-
(
void
)
testClientWithUserId
{
[
Phobos
removeAllNormalPhobosData
];
[
Phobos
.
sharedClient
setUserId
:
MockUserId
];
[
Phobos
.
sharedClient
setCurrentCityId
:
MockCityId
];
[
_client
setUserId
:
MockUserId
];
[
_client
setCurrentCityId
:
MockCityId
];
[
Phobos
track
:
MockEventId
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -64,8 +64,7 @@ NSString *const MockCityId = @"beijing";
*/
-
(
void
)
testTrackEventWithoutAttr
{
[
Phobos
track
:
MockEventId
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -80,8 +79,7 @@ NSString *const MockCityId = @"beijing";
-
(
void
)
testTrackEventWithAttr
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -97,13 +95,13 @@ NSString *const MockCityId = @"beijing";
* @since <#version number#>
*/
-
(
void
)
testTrackEventWithAttrAndSendNow
{
[
Phobos
removeAllNormalPhobosData
];
// Given
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
// When
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
// Then
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
0
,
@"array should be empty"
);
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array should be empty"
);
}
/**
...
...
@@ -120,7 +118,8 @@ NSString *const MockCityId = @"beijing";
// When
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
!=
0
,
@"array shouldn't be empty"
);
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"array shouldn't be empty"
);
}
/**
...
...
@@ -134,16 +133,16 @@ NSString *const MockCityId = @"beijing";
// 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 TODO
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
25
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
NSArray
*
array
=
[
Phobos
immediatelyPhobosForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
25
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
NSArray
*
array
=
[
Phobos
immediatelyPhobosForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
array
=
[
Phobos
normalPhobosDataForServerAPI
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
0
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
});
});
}
...
...
@@ -154,27 +153,23 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithDoubleAttrAndNoSendNow
{
[
Phobos
removeAllNormalPhobosData
];
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
//
[
NSThread
sleepForTimeInterval
:
0
.
2
];
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
[
NSThread
sleepForTimeInterval
:
0
.
2
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
}
/**
...
...
@@ -183,36 +178,35 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithSendNowAndNoSendNowOne
{
[
Phobos
removeAllNormalPhobosData
];
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
NSDictionary
*
sendNowAttr
=
@{
@"attr"
:
@"track_attr_send_now"
};
for
(
int
i
=
0
;
i
<
30
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
30
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
30
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
31
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
31
,
@"array shouldn't be empty"
);
}
/**
...
...
@@ -221,34 +215,33 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithSendNowAndNoSendNowTwo
{
[
Phobos
removeAllNormalPhobosData
];
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
NSDictionary
*
sendNowAttr
=
@{
@"attr"
:
@"track_attr_send_now"
};
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
0
,
@"array shouldn't be empty"
);
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
sendNowAttr
sendNow
:
YES
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
3
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
3
,
@"array shouldn't be empty"
);
}
/**
...
...
@@ -257,24 +250,23 @@ NSString *const MockCityId = @"beijing";
* @since 1.1.4
*/
-
(
void
)
testTrackEventWithSendNowAndNoSendNowThree
{
[
Phobos
removeAllNormalPhobosData
];
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
//
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
// PhobosCacheKey超过50条数据会自动上报,模拟此情况
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
1
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
2
,
@"array shouldn't be empty"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array shouldn't be empty"
);
}
-
(
void
)
verfiyDict
:
(
NSDictionary
*
)
dict
{
...
...
@@ -286,10 +278,16 @@ NSString *const MockCityId = @"beijing";
XCTAssertTrue
([
keys
containsObject
:
@"user_id"
],
@"Missing user_id"
);
XCTAssertTrue
([
keys
containsObject
:
@"create_at"
],
@"Missing create_at"
);
XCTAssertTrue
([
keys
containsObject
:
@"params"
],
@"Missing params"
);
XCTAssertTrue
([
keys
containsObject
:
@"absolute_time"
],
@"Missing absolute_time"
);
XCTAssertTrue
([
keys
containsObject
:
@"create_at_millis"
],
@"Missing create_at_millis"
);
XCTAssertTrue
([
keys
containsObject
:
@"nano_time"
],
@"Missing nano_time"
);
XCTAssertTrue
([[
dict
[
@"params"
]
allKeys
]
containsObject
:
@"referrer_link"
],
@"Missing referrer_link"
);
XCTAssertTrue
((
dict
[
@"params"
][
@"referrer_link"
]
!=
nil
||
!
[
dict
[
@"params"
][
@"referrer_link"
]
isEqual
:@{}]
||
dict
[
@"params"
][
@"referrer_link"
]
!=
NULL
),
@"referrer_link至少使用默认的[]"
);
}
-
(
void
)
testCatchNullInAttributes
{
Phobos
.
sharedC
lient
.
captureNullExpection
=
^
(
NSString
*
eventId
,
NSDictionary
*
att
)
{
_c
lient
.
captureNullExpection
=
^
(
NSString
*
eventId
,
NSDictionary
*
att
)
{
NSCAssert
([
att
[
@"bussness_id"
]
integerValue
]
==
1244
,
@"testCatchNullInAttributes 没有捕获到有用信息"
);
};
NSDictionary
*
attributes
=
@{
@"key"
:
[
NSNull
null
],
...
...
@@ -317,8 +315,7 @@ NSString *const MockCityId = @"beijing";
[
controller
viewWillAppear
:
true
];
[
controller
viewWillDisappear
:
true
];
[
self
paramUnNilCheck
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
NSDictionary
*
dic
=
array
[
0
][
@"params"
];
...
...
@@ -327,20 +324,21 @@ NSString *const MockCityId = @"beijing";
}
-
(
void
)
testSimulativePageViewEvent
{
[
NSThread
sleepForTimeInterval
:
0
.
2
];
[
Phobos
.
sharedClient
simulativePV
:
nil
businessId
:
nil
referer
:
nil
];
[
_client
simulativePV
:
nil
businessId
:
nil
referer
:
nil
];
[
self
paramUnNilCheck
];
}
-
(
void
)
paramUnNilCheck
{
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
NSDictionary
*
dic
=
array
[
0
][
@"params"
];
XCTAssertTrue
(
dic
[
@"page_name"
]
!=
nil
,
@"page_name至少使用默认的空字符串"
);
XCTAssertTrue
([
dic
[
@"referer"
]
integerValue
]
>=
0
,
@"referer至少使用默认的空字符串"
);
XCTAssertTrue
(
dic
[
@"business_id"
]
!=
nil
,
@"business_id至少使用默认的空字符串"
);
XCTAssertTrue
(
dic
[
@"in_time_millis"
]
!=
nil
,
@"in_time_millis至少使用默认的空字符串"
);
XCTAssertTrue
(
dic
[
@"out_time_millis"
]
!=
nil
,
@"out_time_millis至少使用默认的空字符串"
);
XCTAssertTrue
((
dic
[
@"referrer_link"
]
!=
nil
||
!
[
dic
[
@"referrer_link"
]
isEqual
:@{}]
||
dic
[
@"referrer_link"
]
!=
NULL
),
@"referrer_link至少使用默认的[]"
);
}
#pragma mark - 属性test
...
...
@@ -352,9 +350,8 @@ NSString *const MockCityId = @"beijing";
XCTAssertFalse
(
controller
.
needLogPV
,
@"needLogPV赋值为NO时应该NO"
);
}
// 该单元测试暂时不用,因为过滤代码暂时不用,所以不需要跑通
-
(
void
)
testCheckPVPhobos
{
[
Phobos
removeAllNormalPhobosData
];
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
NSString
*
inDate
=
[
PhobosUtil
currentTime
];
[
NSThread
sleepForTimeInterval
:
1
];
//模拟浏览页面,让out和in时间相差1s
...
...
@@ -370,12 +367,12 @@ NSString *const MockCityId = @"beijing";
[
dict
setObject
:
@""
forKey
:
@"referrer_tab_name"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"is_push"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
NSArray
*
array
=
[
Phobos
normalPhobosDataForServerAPI
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"PhobosCacheKey 下面应该有数据"
);
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
XCTAssertTrue
([
Phobos
normalPhobosCount
]
==
1
,
@"PhobosCacheKey 上条数据不应该发送"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"PhobosCacheKey 上条数据不应该发送"
);
[
NSThread
sleepForTimeInterval
:
2
];
//模拟浏览页面,让第二次浏览和上一次时间相差2s
...
...
@@ -383,14 +380,14 @@ NSString *const MockCityId = @"beijing";
[
NSThread
sleepForTimeInterval
:
1
];
//模拟浏览页面,让out和in时间相差1s
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
2
,
@"PhobosCacheKey 上条数据应该发送"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"PhobosCacheKey 上条数据应该发送"
);
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
2
,
@"PhobosCacheKey 上条数据不应该发送"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"PhobosCacheKey 上条数据不应该发送"
);
[
Phobos
track
:
@"test"
attributes
:
dict
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
(
[
Phobos
normalPhobosCount
]
==
3
,
@"PhobosCacheKey 上条数据应该发送"
);
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
3
,
@"PhobosCacheKey 上条数据应该发送"
);
}
...
...
GMPhobos/Classes/Phobos.m
View file @
0495bdd9
...
...
@@ -136,12 +136,16 @@ 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
...
...
@@ -354,12 +358,21 @@ 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
{
if
(
!
[
PhobosUtil
isNonEmpty
:
page
.
pageName
]
||
!
page
.
needLogPV
)
{
return
;
}
// 业务层更新
if
(
page
.
updatePVEndBlock
)
{
page
.
updatePVEndBlock
();
}
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
@try
{
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
...
...
@@ -367,12 +380,18 @@ 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"
];
[
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事件
...
...
@@ -410,11 +429,17 @@ static NSString *sdkVersion = @"110";
*
* @since 0.0.1
*/
-
(
NSDictionary
*
)
prepareDictionaryForEvent
:
(
NSString
*
)
eventId
attributes
:
(
NSDictionary
*
)
attributes
{
-
(
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
];
...
...
@@ -446,14 +471,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"
];
}
...
...
GMPhobos/Classes/PhobosPVProtocol.h
View file @
0495bdd9
...
...
@@ -8,6 +8,8 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef
void
(
^
PhobosUpdatePVBlock
)(
void
);
@protocol
PhobosPVProtocol
<
NSObject
>
/**
...
...
@@ -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
GMPhobos/Classes/PhobosUtil.m
View file @
0495bdd9
...
...
@@ -426,7 +426,7 @@
}
/**
* 获取手机运行时间,从开机到现在
* 获取手机运行时间,从开机到现在
(秒)
*/
+
(
NSString
*
)
deviceRunTime
{
struct
timeval
boottime
;
...
...
GMPhobos/Classes/UIResponder+PhobosPV.m
View file @
0495bdd9
...
...
@@ -152,7 +152,6 @@
objc_setAssociatedObject
(
self
,
@selector
(
inTime
),
inTime
,
OBJC_ASSOCIATION_COPY
);
}
/**
这个地方inTime的值为nil的情况不做考虑,因为Phobos不会发送。inTime必须在controller viewWillAppear时赋值
*/
...
...
@@ -161,6 +160,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 +244,23 @@
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
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