Authored by 周蓉君

Merge branch 'yoho' of http://git.dev.yoho.cn/ios/yh_analytics into yoho

Conflicts:
	YH_Analytics/YH_Analytics/YH_Analytics/Utils/YHAssemblyAssistant.m
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc"> 2 +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="14F1021" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
3 <dependencies> 3 <dependencies>
4 <deployment identifier="iOS"/> 4 <deployment identifier="iOS"/>
5 - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/> 5 + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
6 <capability name="Constraints to layout margins" minToolsVersion="6.0"/> 6 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
7 </dependencies> 7 </dependencies>
8 <scenes> 8 <scenes>
@@ -38,5 +38,22 @@ @@ -38,5 +38,22 @@
38 <array> 38 <array>
39 <string>UIInterfaceOrientationPortrait</string> 39 <string>UIInterfaceOrientationPortrait</string>
40 </array> 40 </array>
  41 + <key>NSAppTransportSecurity</key>
  42 + <dict>
  43 + <key>NSAllowsArbitraryLoads</key>
  44 + <true/>
  45 + <key>NSExceptionDomains</key>
  46 + <dict>
  47 + <key>alipay.com</key>
  48 + <dict>
  49 + <key>NSIncludesSubdomains</key>
  50 + <true/>
  51 + <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
  52 + <true/>
  53 + <key>NSTemporaryExceptionMinimumTLSVersion</key>
  54 + <string>TLSv1.1</string>
  55 + </dict>
  56 + </dict>
  57 + </dict>
41 </dict> 58 </dict>
42 </plist> 59 </plist>
@@ -83,10 +83,14 @@ @@ -83,10 +83,14 @@
83 83
84 - (IBAction)performanceAction:(id)sender { 84 - (IBAction)performanceAction:(id)sender {
85 85
  86 + for (int i = 0; i<101; i++) {
86 [[YH_Analytics sharedInstance]logPerformanceWithType:kPerformanceTypeImageLoad parameters:@{ 87 [[YH_Analytics sharedInstance]logPerformanceWithType:kPerformanceTypeImageLoad parameters:@{
  88 + @"index":@(i),
87 JsonKeyPerformanceTag:@"YH_TAGS", 89 JsonKeyPerformanceTag:@"YH_TAGS",
88 JsonKeyPerformanceURL:@"http://ad.yoho.cn/yohobuy/img/home/02.jpg", 90 JsonKeyPerformanceURL:@"http://ad.yoho.cn/yohobuy/img/home/02.jpg",
89 JsonKeyPerformanceEvt:JsonKeyPerformanceEvtBegin 91 JsonKeyPerformanceEvt:JsonKeyPerformanceEvtBegin
90 }]; 92 }];
  93 + }
  94 +
91 } 95 }
92 @end 96 @end
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 /* 12 /*
13 用于组装数据 13 用于组装数据
14 */ 14 */
15 - 15 +@class YHPerformance;
16 @interface YHAssemblyAssistant : NSObject 16 @interface YHAssemblyAssistant : NSObject
17 17
18 + (instancetype)sharedInstance; 18 + (instancetype)sharedInstance;
@@ -21,6 +21,8 @@ @@ -21,6 +21,8 @@
21 21
22 - (void)saveItemData:(YHAnalyItemData *)itemData; 22 - (void)saveItemData:(YHAnalyItemData *)itemData;
23 23
  24 +- (void)savePerformanceData:(YHPerformance *)perf;
  25 +
24 - (NSUInteger)getAllEventCount; 26 - (NSUInteger)getAllEventCount;
25 27
26 - (NSDictionary *)getUploadData; 28 - (NSDictionary *)getUploadData;
@@ -272,6 +272,29 @@ static dispatch_queue_t persisting_queue() { @@ -272,6 +272,29 @@ static dispatch_queue_t persisting_queue() {
272 } 272 }
273 273
274 #pragma mark - 持久化数据 274 #pragma mark - 持久化数据
  275 +- (void)savePerformanceData:(YHPerformance *)perf
  276 +{
  277 + if (perf == nil || ![perf isKindOfClass:[YHPerformance class]]) {
  278 + NSException *exception = [NSException exceptionWithName:NSInvalidArgumentException
  279 + reason:@"The input parameter is nil or an unexpected value."
  280 + userInfo:nil];
  281 + [exception raise];
  282 +
  283 + }
  284 +
  285 + if ([self canPersisting]) {
  286 + perf.net = self.currentStatus.net;
  287 +
  288 + dispatch_async(persisting_queue(), ^{
  289 +
  290 + if ([self writePerformanceToFile:perf]) {
  291 + [self autoUploadData];
  292 + }
  293 + });
  294 + }
  295 +
  296 +}
  297 +
275 - (void)saveItemData:(YHAnalyItemData *)itemData 298 - (void)saveItemData:(YHAnalyItemData *)itemData
276 { 299 {
277 if (itemData == nil || ![itemData isKindOfClass:[YHAnalyItemData class]]) { 300 if (itemData == nil || ![itemData isKindOfClass:[YHAnalyItemData class]]) {
@@ -665,6 +688,8 @@ static dispatch_queue_t persisting_queue() { @@ -665,6 +688,8 @@ static dispatch_queue_t persisting_queue() {
665 688
666 //直接添加 immediUploadDataDic 内容(里面包含 device 信息) 689 //直接添加 immediUploadDataDic 内容(里面包含 device 信息)
667 @synchronized(self.immediUploadItemDic) { 690 @synchronized(self.immediUploadItemDic) {
  691 + [self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypeErrors];
  692 + [self.immediUploadItemDic removeObjectForKey:JsonKeyDataTypeEvents];
668 [collectData addEntriesFromDictionary:self.immediUploadItemDic]; 693 [collectData addEntriesFromDictionary:self.immediUploadItemDic];
669 } 694 }
670 695
@@ -32,8 +32,8 @@ @@ -32,8 +32,8 @@
32 #define kYHAnalyticsSDKVersion @"1.0" // 数据分析库版本 32 #define kYHAnalyticsSDKVersion @"1.0" // 数据分析库版本
33 #define kDefalutChannelNum @"2119" // 推广渠道号 33 #define kDefalutChannelNum @"2119" // 推广渠道号
34 #define kMinInterval 60 // 间隔发送的最小时间周期,60秒 34 #define kMinInterval 60 // 间隔发送的最小时间周期,60秒
35 -#define kMaxLocalEventsCount 3000 // 本地持久化event最大条数,3000条  
36 -#define kMaxLocalRecoderFileSize (1024 * 300) // 本地持久化文件大小(300KB) 35 +#define kMaxLocalEventsCount 100 // 本地持久化event最大条数,3000条
  36 +#define kMaxLocalRecoderFileSize (1024 * 50) // 本地持久化文件大小(300KB)
37 37
38 /*********** Path and FileName *************/ 38 /*********** Path and FileName *************/
39 39
@@ -55,6 +55,16 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) { @@ -55,6 +55,16 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) {
55 */ 55 */
56 - (void)logPerformanceWithType:(NSString *)perfType parameters:(NSDictionary *)param; 56 - (void)logPerformanceWithType:(NSString *)perfType parameters:(NSDictionary *)param;
57 57
  58 +///**
  59 +// @brief 统一事件记录的接口
  60 +//
  61 +// @param extraData 统计类型 IMG_LOAD, API_CALL, WEBVIEW_LOAD
  62 +// @param param 操作参数
  63 +//
  64 +// @since 1.0
  65 +// */
  66 +//- (void)logWithExtraData:(NSString *)extraData dataType:() parameters:(NSDictionary *)param;
  67 +
58 68
59 /** 69 /**
60 * 用户id 70 * 用户id
@@ -111,8 +111,8 @@ @@ -111,8 +111,8 @@
111 111
112 */ 112 */
113 113
114 - _logStrategy = LogStrategyAppLaunch | LogStrategyCustom;  
115 - _currentInterval = 5*60; 114 + _logStrategy = LogStrategyAppLaunch | LogStrategyImmedi;
  115 +// _currentInterval = 5*60;
116 116
117 YALog(@"logStrategy = %d currentInterval = %0.1f", _logStrategy, _currentInterval); 117 YALog(@"logStrategy = %d currentInterval = %0.1f", _logStrategy, _currentInterval);
118 } 118 }
@@ -326,11 +326,14 @@ @@ -326,11 +326,14 @@
326 self.perfermance.param = param; 326 self.perfermance.param = param;
327 327
328 // 立即发送策略 328 // 立即发送策略
329 - if ((self.logStrategy & LogStrategyImmedi) != 0) {  
330 - [[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:self.perfermance];  
331 - } else {  
332 - [[YHAssemblyAssistant sharedInstance] saveItemData:self.perfermance];  
333 - } 329 +// if ((self.logStrategy & LogStrategyImmedi) != 0) {
  330 +// [[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:self.perfermance];
  331 +// } else {
  332 +// [[YHAssemblyAssistant sharedInstance] saveItemData:self.perfermance];
  333 +// }
  334 +
  335 + // 性能统计事件不需要立即发送
  336 + [[YHAssemblyAssistant sharedInstance]savePerformanceData:self.perfermance];
334 } 337 }
335 338
336 @end 339 @end