Commit deb90c17 authored by 井庆林's avatar 井庆林

..

parent 39ba6493
...@@ -435,12 +435,14 @@ ...@@ -435,12 +435,14 @@
"${PODS_ROOT}/Target Support Files/Pods-GMPhobos_Example/Pods-GMPhobos_Example-frameworks.sh", "${PODS_ROOT}/Target Support Files/Pods-GMPhobos_Example/Pods-GMPhobos_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/GMCache/GMCache.framework", "${BUILT_PRODUCTS_DIR}/GMCache/GMCache.framework",
"${BUILT_PRODUCTS_DIR}/GMPhobos/GMPhobos.framework", "${BUILT_PRODUCTS_DIR}/GMPhobos/GMPhobos.framework",
"${BUILT_PRODUCTS_DIR}/MJExtension/MJExtension.framework",
"${BUILT_PRODUCTS_DIR}/TMCache/TMCache.framework", "${BUILT_PRODUCTS_DIR}/TMCache/TMCache.framework",
); );
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputPaths = ( outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GMCache.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GMCache.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GMPhobos.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GMPhobos.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJExtension.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TMCache.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TMCache.framework",
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
......
...@@ -36,11 +36,15 @@ NSString *const MockCityId = @"beijing"; ...@@ -36,11 +36,15 @@ NSString *const MockCityId = @"beijing";
NSString *url = @"http://log.test.gengmei.cc/log/collect"; NSString *url = @"http://log.test.gengmei.cc/log/collect";
#endif #endif
[GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey]; [GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
[Phobos clientWithAppName:MockAppName channelId:MockChannelId]; Phobos *client = [Phobos clientWithAppName:MockAppName channelId:MockChannelId];
[Phobos setSharedClient:client];
Phobos.sharedClient.serverAPI = url; Phobos.sharedClient.serverAPI = url;
[Phobos.sharedClient setLogEnabled:NO]; // 调试打Log模式,看情况开启 [Phobos.sharedClient setLogEnabled:NO]; // 调试打Log模式,看情况开启
Phobos.sharedClient.signingType = PhobosSigningTypeDebug; Phobos.sharedClient.signingType = PhobosSigningTypeDebug;
Phobos.sharedClient.userId = @""; Phobos.sharedClient.userId = @"";
Phobos.sharedClient.getTopController = ^UIViewController * _Nonnull{
return self;
};
NSString *inDate = [PhobosUtil currentTime]; NSString *inDate = [PhobosUtil currentTime];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
...@@ -62,7 +66,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -62,7 +66,7 @@ NSString *const MockCityId = @"beijing";
[dict setObject:[PhobosUtil currentTime] forKey:@"in"]; [dict setObject:[PhobosUtil currentTime] forKey:@"in"];
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; [dict setObject:[PhobosUtil currentTime] forKey:@"out"];
[Phobos track:@"page_view" attributes:dict]; [Phobos track:@"page_view" attributes:dict sendNow:YES];
array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey]; array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
[Phobos track:@"test" attributes:dict]; [Phobos track:@"test" attributes:dict];
......
PODS: PODS:
- GMCache (1.0.1): - GMCache (1.0.1):
- TMCache (= 2.1.0) - TMCache (= 2.1.0)
- GMPhobos (1.3.4): - GMPhobos (1.3.5):
- GMCache - GMCache
- MJExtension
- MJExtension (3.2.1)
- TMCache (2.1.0) - TMCache (2.1.0)
DEPENDENCIES: DEPENDENCIES:
...@@ -12,6 +14,7 @@ SPEC REPOS: ...@@ -12,6 +14,7 @@ SPEC REPOS:
"git@git.wanmeizhensuo.com:gengmeiios/GMSpecs.git": "git@git.wanmeizhensuo.com:gengmeiios/GMSpecs.git":
- GMCache - GMCache
https://github.com/cocoapods/specs.git: https://github.com/cocoapods/specs.git:
- MJExtension
- TMCache - TMCache
EXTERNAL SOURCES: EXTERNAL SOURCES:
...@@ -20,7 +23,8 @@ EXTERNAL SOURCES: ...@@ -20,7 +23,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: b78d8e46db864405e91d226ce640cc80d966c611 GMCache: b78d8e46db864405e91d226ce640cc80d966c611
GMPhobos: 54e7aded6e4b6c69c1339c16c8693110f417a69d GMPhobos: 242bc118edb737fb496b49235b2f24d61c349d7b
MJExtension: 635f2c663dcb1bf76fa4b715b2570a5710aec545
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad PODFILE CHECKSUM: ea0fac2144ac80baf8f21576cde49526c19991ad
......
...@@ -25,11 +25,15 @@ NSString *const MockCityId = @"beijing"; ...@@ -25,11 +25,15 @@ NSString *const MockCityId = @"beijing";
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:PhobosGray];
[Phobos clientWithAppName:MockAppName channelId:MockChannelId]; [Phobos clientWithAppName:MockAppName channelId:MockChannelId];
Phobos.sharedClient.serverAPI = @"http://log.test.igengmei.com/log/collect"; Phobos.sharedClient.serverAPI = @"http://log.test.igengmei.com/log/collect";
Phobos.sharedClient.logEnabled = NO; // 调试打Log模式,看情况开启 Phobos.sharedClient.logEnabled = NO; // 调试打Log模式,看情况开启
Phobos.sharedClient.signingType = PhobosSigningTypeDebug; Phobos.sharedClient.signingType = PhobosSigningTypeDebug;
Phobos.sharedClient.userId = @""; Phobos.sharedClient.userId = @"";
Phobos.sharedClient.getTopController = ^UIViewController * _Nonnull{
return [UIViewController new];
};
} }
- (void)tearDown { - (void)tearDown {
...@@ -45,6 +49,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -45,6 +49,7 @@ NSString *const MockCityId = @"beijing";
* @since <#version number#> * @since <#version number#>
*/ */
- (void)testClientWithUserId{ - (void)testClientWithUserId{
[self setUp];
[Phobos removeAllNormalPhobosData]; [Phobos removeAllNormalPhobosData];
[Phobos.sharedClient setUserId:MockUserId]; [Phobos.sharedClient setUserId:MockUserId];
[Phobos.sharedClient setCurrentCityId:MockCityId]; [Phobos.sharedClient setCurrentCityId:MockCityId];
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "GMPhobos" s.name = "GMPhobos"
s.version = "1.3.4" s.version = "1.3.5"
s.summary = "GM statistic data sdk" s.summary = "GM statistic data sdk"
s.description = <<-DESC s.description = <<-DESC
...@@ -25,6 +25,7 @@ Pod::Spec.new do |s| ...@@ -25,6 +25,7 @@ Pod::Spec.new do |s|
s.platform = :ios, '8.0' s.platform = :ios, '8.0'
s.source_files = 'GMPhobos/Classes/*.{h,m}' s.source_files = 'GMPhobos/Classes/*.{h,m}'
s.dependency 'GMCache' s.dependency 'GMCache'
s.dependency 'MJExtension'
s.library = 'z' s.library = 'z'
end end
...@@ -35,8 +35,6 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -35,8 +35,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)sharedClient; + (instancetype)sharedClient;
@property (class, readonly, strong) NewPhobos *sharedClient;
/** 用于Phobos库从old更新到new使用,在全量之后删除相关逻辑 */ /** 用于Phobos库从old更新到new使用,在全量之后删除相关逻辑 */
@property (nonatomic, assign) BOOL isGray; @property (nonatomic, assign) BOOL isGray;
...@@ -124,6 +122,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -124,6 +122,10 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - 事件采集 #pragma mark - 事件采集
/** 点击事件采集 */
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes;
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes sendNow:(BOOL)sendNow;
/** /**
* @brief 自定义事件,数量统计. * @brief 自定义事件,数量统计.
* *
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#import "PhobosCustomVisibleController.h" #import "PhobosCustomVisibleController.h"
#import <GMCache/GMCache.h> #import <GMCache/GMCache.h>
#import <objc/runtime.h> #import <objc/runtime.h>
#import "PhobosDataManager.h"
static NewPhobos *_sharedClient; static NewPhobos *_sharedClient;
static NSString *sdkVersion = @"1.4.0"; static NSString *sdkVersion = @"1.4.0";
...@@ -34,27 +35,12 @@ static NSString *sdkVersion = @"1.4.0"; ...@@ -34,27 +35,12 @@ static NSString *sdkVersion = @"1.4.0";
@implementation NewPhobos @implementation NewPhobos
static dispatch_semaphore_t _immediatelySemaphore;
static dispatch_semaphore_t _normalSemaphore;
static dispatch_queue_t _immediatelyQueue;
static dispatch_queue_t _normalQueue;
+ (NewPhobos *)clientWithAppName:(NSString *)appName channelId:(NSString *)channelId{ + (NewPhobos *)clientWithAppName:(NSString *)appName channelId:(NSString *)channelId{
NewPhobos.sharedClient.appName = appName; NewPhobos.sharedClient.appName = appName;
NewPhobos.sharedClient.channelId = channelId; NewPhobos.sharedClient.channelId = channelId;
return NewPhobos.sharedClient; return NewPhobos.sharedClient;
} }
+ (void)initialize {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_immediatelySemaphore = dispatch_semaphore_create(1);
_normalSemaphore = dispatch_semaphore_create(1);
_immediatelyQueue = dispatch_queue_create("immdiately", DISPATCH_QUEUE_CONCURRENT);
_normalQueue = dispatch_queue_create("normal", DISPATCH_QUEUE_CONCURRENT);
});
}
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_appName = @""; _appName = @"";
...@@ -68,13 +54,9 @@ static dispatch_queue_t _normalQueue; ...@@ -68,13 +54,9 @@ static dispatch_queue_t _normalQueue;
_userType = [[NSMutableDictionary alloc] init]; _userType = [[NSMutableDictionary alloc] init];
_appVersion = [PhobosUtil getAppVersion]; _appVersion = [PhobosUtil getAppVersion];
_signingType = PhobosSigningTypeUndefined; _signingType = PhobosSigningTypeUndefined;
// self.immediatelySemaphore = dispatch_semaphore_create(1);
// self.normalSemaphore = dispatch_semaphore_create(1);
NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosNormalCacheKey] mutableCopy]; NSArray<PhobosSendModel *> *datas = [PhobosDataManager fetchDataModelsWithStatus:PhobosModelSendStatusNormal];
for (NSArray *data in dataDict.allValues) { self.normalCount = datas.count;
self.normalCount += data.count;
}
[self setupNotification]; [self setupNotification];
[self handleSessionStart]; [self handleSessionStart];
...@@ -195,7 +177,7 @@ static dispatch_queue_t _normalQueue; ...@@ -195,7 +177,7 @@ static dispatch_queue_t _normalQueue;
phobosLog(@"handleAppInForeground"); phobosLog(@"handleAppInForeground");
[self handleSessionStart]; [self handleSessionStart];
[self handleEventDeviceOpened]; [self handleEventDeviceOpened];
[self sendImmediatelyNormalData]; [self trackPhobosWithSendAPI:nil data:nil immediate:YES];
[self handlePVEventAppInForeground]; [self handlePVEventAppInForeground];
} }
...@@ -208,7 +190,7 @@ static dispatch_queue_t _normalQueue; ...@@ -208,7 +190,7 @@ static dispatch_queue_t _normalQueue;
phobosLog(@"handleAppInBackgound"); phobosLog(@"handleAppInBackgound");
[self handlePVEventAppInBackgound]; [self handlePVEventAppInBackgound];
[self handleSessionOver]; [self handleSessionOver];
[self sendImmediatelyNormalData]; [self trackPhobosWithSendAPI:nil data:nil immediate:YES];
} }
/** /**
...@@ -378,6 +360,14 @@ static dispatch_queue_t _normalQueue; ...@@ -378,6 +360,14 @@ static dispatch_queue_t _normalQueue;
}); });
} }
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes {
[self track:@"on_cick_button" attributes:attributes];
}
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes sendNow:(BOOL)sendNow {
[self track:@"on_cick_button" attributes:attributes sendNow:sendNow];
}
+ (void)track:(NSString *)eventName{ + (void)track:(NSString *)eventName{
[self track:eventName attributes:@{} sendNow:NO currentAPI:_sharedClient.serverAPI]; [self track:eventName attributes:@{} sendNow:NO currentAPI:_sharedClient.serverAPI];
} }
...@@ -402,13 +392,8 @@ static dispatch_queue_t _normalQueue; ...@@ -402,13 +392,8 @@ static dispatch_queue_t _normalQueue;
NSDictionary *dataDict = [_sharedClient prepareDictionaryForEvent:eventName attributes:attributes]; NSDictionary *dataDict = [_sharedClient prepareDictionaryForEvent:eventName attributes:attributes];
@try { @try {
NSData *JSON = [PhobosUtil encodeJSON:dataDict]; NSData *JSON = [PhobosUtil encodeJSON:dataDict];
if (sendNow) { [_sharedClient trackPhobosWithSendAPI:currentAPI data:dataDict immediate:sendNow];
[_sharedClient sendImmediatelyPhobosWithURL:currentAPI data:dataDict]; } @catch (NSException *exception) {
} else{
[_sharedClient trackPhobosWithURL:currentAPI data:dataDict];
}
}
@catch (NSException *exception) {
NSAssert(NO, @"哎呀呀,VALUE不能为NSObject "); NSAssert(NO, @"哎呀呀,VALUE不能为NSObject ");
} }
} }
...@@ -421,114 +406,20 @@ static dispatch_queue_t _normalQueue; ...@@ -421,114 +406,20 @@ static dispatch_queue_t _normalQueue;
* @param dataArray 埋点数据 * @param dataArray 埋点数据
* @param nowSend 是否需要发送当前缓存数据(app进入到后台、前台等情况) * @param nowSend 是否需要发送当前缓存数据(app进入到后台、前台等情况)
*/ */
- (void)sendImmediatelyNormalData { - (void)trackPhobosWithSendAPI:(NSString *)sendAPI data:(NSDictionary *)data immediate:(BOOL)immediate {
[self trackPhobosWithURL:nil data:nil immediate:YES]; dispatch_async(dispatch_get_main_queue(), ^{
} [PhobosDataManager insertData:data sendAPI:sendAPI immediately:immediate];
- (void)trackPhobosWithURL:(NSString *)url data:(NSDictionary *)data {
[self trackPhobosWithURL:url data:data immediate:NO];
}
- (void)trackPhobosWithURL:(NSString *)url data:(NSDictionary *)data immediate:(BOOL)immediate {
dispatch_async(_normalQueue, ^{
dispatch_semaphore_wait(_normalSemaphore, DISPATCH_TIME_FOREVER);
NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosNormalCacheKey] mutableCopy];
_normalCount++;
if (!immediate) { if (!immediate) {
dataDict = [self dataDict:dataDict setObject:data forKey:url]; _normalCount++;
[GMCache storeObjectAtDocumentPathWithkey:PhobosNormalCacheKey object:dataDict]; } else {
} [PhobosDataManager sendData];
if (immediate || self.normalCount >= 50) { // 数据超过一定数量 或 进入后台等逻辑,统一进行发送普通埋点数据
[dataDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSArray * _Nonnull obj, BOOL * _Nonnull stop) {
if (obj && obj.count > 0) {
[self sendImmediatelyPhobosWithURL:key data:obj];
} }
}]; if ((immediate && sendAPI == nil) || self.normalCount >= 50) { // 数据超过一定数量 或 进入后台等逻辑,统一进行发送普通埋点数据
[NewPhobos removeAllNormalPhobosData]; [NewPhobos removeAllNormalPhobosData];
} }
dispatch_semaphore_signal(_normalSemaphore);
});
}
/**
* 即时发送埋点接口
* @param url : 接口url
* @param data : 使用id类型是因为直接调用实时埋点传过来的是Dict,而普通埋点过来的则是Array类型
*/
- (void)sendImmediatelyPhobosWithURL:(NSString *)url data:(id)data {
dispatch_async(_immediatelyQueue, ^{
dispatch_semaphore_wait(_immediatelySemaphore, DISPATCH_TIME_FOREVER);
__block NSMutableDictionary *dataDict = [[GMCache fetchObjectAtDocumentPathWithkey:PhobosImmediatelyCacheKey] mutableCopy];
dataDict = [self dataDict:dataDict setObject:data forKey:url];
NSInteger allCount = dataDict.allKeys.count;// 请求个数
__block finishCount = 0;// 请求完成次数,不是请求成功次数,能在最后保证未发送成功的数据,能一次保存下来,等待下次发送
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);// 因为网络请求是异步回调,需要保证数据安全
[dataDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSArray * _Nonnull obj, BOOL * _Nonnull stop) {
[self sendDataWithAPI:key data:obj successBlock:^(NSInteger code) {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
finishCount++;
if (code == 200) {// 如果数据请求成功,删除当前数据的缓存
[dataDict removeObjectForKey:key];
}
if (finishCount == allCount) {// 所有数据都请求完成,重新进行数据缓存
[GMCache storeObjectAtDocumentPathWithkey:PhobosImmediatelyCacheKey object:dataDict];
dispatch_semaphore_signal(_immediatelySemaphore);
}
dispatch_semaphore_signal(semaphore);
phobosLog(@"✈ ---------- ✈ data arrived Mars");
}];
}];
}); });
} }
/**
* 将数据存入到字典中
* @param dataDict 需要存入的字典
* @param object 需要存入的数据
* @param key 需要将数据存入到dataDict的key所在的数据中
*/
- (NSMutableDictionary *)dataDict:(NSMutableDictionary *)dataDict setObject:(id)object forKey:(NSString *)key {
if (!dataDict) {
dataDict = [NSMutableDictionary new];
}
// 判断数据类型,统一转换成数组
NSMutableArray *dataArray = [dataDict.allKeys containsObject:key] ? [dataDict[key] mutableCopy] : [NSMutableArray new];
NSArray *data = [object isKindOfClass:[NSArray class]] ? object :@[object];
[dataArray addObjectsFromArray:data];
// 进行数据校验
@try {
NSData *json = [PhobosUtil encodeJSON:dataArray];
[dataDict setValue:dataArray forKey:key];
} @catch (NSException *exception) {
NSAssert(NO, @"哎呀呀,VALUE只不能为NSObject ");
}
return dataDict;
}
// 发送埋点数据
- (void)sendDataWithAPI:(NSString *)api data:(NSArray *)dataArray successBlock:(SendDataSuccessBlock)successBlock {
if (_logEnabled) {
NSData *data = [NSJSONSerialization dataWithJSONObject:dataArray options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
phobosLog([NSString stringWithFormat:@"array prepare to fly --✈: %@", jsonString]);
}
@try {
if (self.phobosSendDataBlock) {
self.phobosSendDataBlock(dataArray);
}
NSData *JSON = [PhobosUtil encodeJSON:dataArray];
NSData *compressedData = [PhobosUtil compressData:JSON];
if (compressedData) {
[PhobosUtil sendData:compressedData currentAPI:api success:successBlock];
}
}
@catch (NSException *exception) {
phobosLog(exception);
}
}
@end @end
@implementation NewPhobos (UtilTest) @implementation NewPhobos (UtilTest)
...@@ -585,19 +476,15 @@ static dispatch_queue_t _normalQueue; ...@@ -585,19 +476,15 @@ static dispatch_queue_t _normalQueue;
/** 清除非立即发送埋点数据缓存 */ /** 清除非立即发送埋点数据缓存 */
+ (void)removeAllNormalPhobosData { + (void)removeAllNormalPhobosData {
NewPhobos.sharedClient.normalCount = 0; NewPhobos.sharedClient.normalCount = 0;
[GMCache removeObjectAtDocumentPathWithkey:PhobosNormalCacheKey]; dispatch_async(dispatch_get_main_queue(), ^{
[PhobosDataManager removeAllDataWithImmediately:NO];
});
} }
/** 清除立即发送埋点数据缓存 */ /** 清除立即发送埋点数据缓存 */
+ (void)removeAllImmediatelyPhobosData { + (void)removeAllImmediatelyPhobosData {
[GMCache removeObjectAtDocumentPathWithkey:PhobosImmediatelyCacheKey]; dispatch_async(dispatch_get_main_queue(), ^{
} [PhobosDataManager removeAllDataWithImmediately:YES];
});
- (void)setPhobosSendDataBlock:(void (^)(NSArray *))phobosSendDataBlock {
objc_setAssociatedObject(self, @selector(phobosSendDataBlock), phobosSendDataBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (void (^)(NSArray *))phobosSendDataBlock {
return objc_getAssociatedObject(self, @selector(phobosSendDataBlock));
} }
@end @end
...@@ -118,6 +118,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -118,6 +118,10 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - 事件采集 #pragma mark - 事件采集
/** 点击事件采集 */
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes;
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes sendNow:(BOOL)sendNow;
/** /**
* @brief 自定义事件,数量统计. * @brief 自定义事件,数量统计.
* *
......
...@@ -49,14 +49,32 @@ static BOOL isGray = NO; ...@@ -49,14 +49,32 @@ static BOOL isGray = NO;
isGray = [[[NSUserDefaults standardUserDefaults] objectForKey:PhobosGray] boolValue]; isGray = [[[NSUserDefaults standardUserDefaults] objectForKey:PhobosGray] boolValue];
if (isGray) { if (isGray) {
_rePhobos = [NewPhobos clientWithAppName:appName channelId:channelId]; _rePhobos = [NewPhobos clientWithAppName:appName channelId:channelId];
sharedClient = _rePhobos;
} else { } else {
_oldPhobos = [OldPhobos clientWithAppName:appName channelId:channelId]; _oldPhobos = [OldPhobos clientWithAppName:appName channelId:channelId];
[OldPhobos setSharedClient:_oldPhobos]; [OldPhobos setSharedClient:_oldPhobos];
sharedClient = _oldPhobos;
} }
} }
return self; return self;
} }
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes {
if (isGray) {
[NewPhobos onClickButtonWithAttributes:attributes];
} else {
[self track:@"on_cick_button" attributes:attributes];
}
}
+ (void)onClickButtonWithAttributes:(NSDictionary *)attributes sendNow:(BOOL)sendNow {
if (isGray) {
[NewPhobos onClickButtonWithAttributes:attributes sendNow:sendNow];
} else {
[self track:@"on_cick_button" attributes:attributes sendNow:sendNow];
}
}
+ (void)track:(NSString *)eventId attributes:(NSDictionary *)attributes { + (void)track:(NSString *)eventId attributes:(NSDictionary *)attributes {
if (isGray) { if (isGray) {
[NewPhobos track:eventId attributes:attributes]; [NewPhobos track:eventId attributes:attributes];
......
...@@ -29,6 +29,7 @@ typedef NS_ENUM (NSInteger, PhobosSigningType) { ...@@ -29,6 +29,7 @@ typedef NS_ENUM (NSInteger, PhobosSigningType) {
#define PhobosEndTime @"PhobosEndTime" //记录APP退出|退到后台时的时间戳 #define PhobosEndTime @"PhobosEndTime" //记录APP退出|退到后台时的时间戳
#define PhobosNormalCacheKey @"PhobosNormalCacheKey" //存放持久化埋点数据的key #define PhobosNormalCacheKey @"PhobosNormalCacheKey" //存放持久化埋点数据的key
#define PhobosImmediatelyCacheKey @"PhobosImmediatelyCacheKey" //存放持久化实时埋点数据的key #define PhobosImmediatelyCacheKey @"PhobosImmediatelyCacheKey" //存放持久化实时埋点数据的key
#define PhobosNewCacheKey @"PhobosNewCacheKey"
#define PhobosCacheKey @"PhobosCacheKey" //old 存放持久化埋点数据的key #define PhobosCacheKey @"PhobosCacheKey" //old 存放持久化埋点数据的key
#define PhobosTempCacheKey @"PhobosTempCacheKey" //old 临时存放待发送埋点数据的key #define PhobosTempCacheKey @"PhobosTempCacheKey" //old 临时存放待发送埋点数据的key
......
//
// PhobosDataManager.h
// GMCache
//
// Created by Locus on 2020/1/21.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, PhobosModelSendStatus) {
PhobosModelSendStatusNormal = 0,
PhobosModelSendStatusSending,
PhobosModelSendStatusFinish,
PhobosModelSendStatusError,
};
@interface PhobosSendModel : NSObject
@property (nonatomic, copy, readonly) NSString *sendId;
@property (nonatomic, strong) id data;
@property (nonatomic, copy) NSString *api;
@property (nonatomic, assign) PhobosModelSendStatus sendStatus;
- (instancetype)initWithData:(id)data sendApi:(NSString *)api;
@end
@interface PhobosDataManager : NSObject
- (void)insertData:(PhobosSendModel *)data immediately:(BOOL)immediately;
- (void)updateData:(PhobosSendModel *)data sendStatus:(PhobosModelSendStatus)sendStatus;
- (void)deleteData:(PhobosSendModel *)data;
- (void)removeNormalData;
- (NSArray<PhobosSendModel *> *)fetchData;
@end
NS_ASSUME_NONNULL_END
//
// PhobosDataManager.m
// GMCache
//
// Created by Locus on 2020/1/21.
//
#import "PhobosDataManager.h"
@implementation PhobosSendModel
- (instancetype)initWithData:(id)data sendApi:(NSString *)api {
if (self = [super init]) {
_data = data;
_sendId = @"123";
_api = api;
}
return self;
}
@end
@implementation PhobosDataManager
- (void)insertData:(PhobosSendModel *)data immediately:(BOOL)immediately {
}
- (void)updateData:(PhobosSendModel *)data sendStatus:(PhobosModelSendStatus)sendStatus {
}
- (void)deleteData:(PhobosSendModel *)data {
}
- (void)removeNormalData {
}
- (NSArray<PhobosSendModel *> *)fetchData {
return nil;
}
@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