From 2cbe0ee9e5a628005d82e06b6bc4f87b246d984d Mon Sep 17 00:00:00 2001 From: wangzhuozhou Date: Thu, 29 Sep 2016 12:58:01 +0800 Subject: [PATCH] Release 1.6.13 --- .../SensorsAnalyticsSDK.podspec | 2 +- .../SensorsAnalyticsSDK/SensorsAnalyticsSDK.h | 35 +++++++++ .../SensorsAnalyticsSDK/SensorsAnalyticsSDK.m | 78 +++++++++++++++++-- 3 files changed, 109 insertions(+), 6 deletions(-) diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec b/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec index 19eae403..82b5d0f9 100644 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SensorsAnalyticsSDK" - s.version = "1.6.12" + s.version = "1.6.13" s.summary = "The offical iOS SDK of Sensors Analytics." s.homepage = "http://www.sensorsdata.cn" s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" } diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h index 60084f19..ab2a1412 100755 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h @@ -404,6 +404,41 @@ typedef NS_ENUM(NSInteger, SensorsAnalyticsAppPushService) { */ - (void)trackInstallation:(NSString *)event; +/** + * @abstract + * 在AutoTrack时,用户可以设置哪些controlls不被AutoTrack + * + * @param controllers controller‘字符串’数组 + */ +- (void)filterAutoTrackControllers:(NSArray *)controllers; + +/** + * @abstract + * 获取LastScreenUrl + * + * @return LastScreenUrl + */ +- (NSString *)getLastScreenUrl; + +/** + * @abstract + * 获取LastScreenTrackProperties + * + * @return LastScreenTrackProperties + */ +- (NSDictionary *)getLastScreenTrackProperties; + +/** + * @abstract + * Track $AppViewScreen事件 + * + * @param url 当前页面url + * @param 用户扩展属性 + * + * @return + */ +- (void)trackViewScreen:(NSString *)url withProperties:(NSDictionary *)properties; + /** * @abstract * 用来设置每个事件都带有的一些公共属性 diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m index b7a75980..a3e26b9d 100755 --- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m +++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m @@ -35,7 +35,7 @@ #import #endif -#define VERSION @"1.6.12" +#define VERSION @"1.6.13" #define PROPERTY_LENGTH_LIMITATION 8191 @@ -96,6 +96,9 @@ @interface SensorsAnalyticsSDK() @property (nonatomic, strong) NSTimer *timer; @property (nonatomic, strong) NSTimer *vtrackConnectorTimer; +//用户设置的不被AutoTrack的Controllers +@property (nonatomic, strong) NSMutableArray *filterControllers; + // 用于 SafariViewController @property (strong, nonatomic) UIWindow *secondWindow; @@ -115,6 +118,7 @@ @implementation SensorsAnalyticsSDK { BOOL _autoTrack; // 自动采集事件 BOOL _appRelaunched; // App 从后台恢复 NSString *_referrerScreenUrl; + NSDictionary *_lastScreenTrackProperties; } static SensorsAnalyticsSDK *sharedInstance = nil; @@ -197,9 +201,13 @@ - (instancetype)initWithServerURL:(NSString *)serverURL andVTrackServerURL:(NSString *)vtrackServerURL andDebugMode:(SensorsAnalyticsDebugMode)debugMode { if (serverURL == nil || [serverURL length] == 0) { - @throw [NSException exceptionWithName:@"InvalidArgumentException" + if (_debugMode != SensorsAnalyticsDebugOff) { + @throw [NSException exceptionWithName:@"InvalidArgumentException" reason:@"serverURL is nil" userInfo:nil]; + } else { + SAError(@"serverURL is nil"); + } } if (debugMode != SensorsAnalyticsDebugOff) { @@ -229,7 +237,9 @@ - (instancetype)initWithServerURL:(NSString *)serverURL _autoTrack = NO; _appRelaunched = NO; _referrerScreenUrl = nil; + _lastScreenTrackProperties = nil; + _filterControllers = [[NSMutableArray alloc] init]; _dateFormatter = [[NSDateFormatter alloc] init]; [_dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"]; @@ -837,14 +847,29 @@ - (void)trackInstallation:(NSString *)event { [self track:nil withProperties:properties withType:@"profile_set_once"]; } +- (void)filterAutoTrackControllers:(NSArray *)controllers { + if (controllers == nil || controllers.count == 0) { + return; + } + [_filterControllers addObjectsFromArray:controllers]; + + //去重 + NSSet *set = [NSSet setWithArray:_filterControllers]; + if (set != nil) { + _filterControllers = [NSMutableArray arrayWithArray:[set allObjects]]; + } else{ + _filterControllers = [[NSMutableArray alloc] init]; + } +} + - (void)identify:(NSString *)distinctId { if (distinctId == nil || distinctId.length == 0) { SAError(@"%@ cannot identify blank distinct id: %@", self, distinctId); - @throw [NSException exceptionWithName:@"InvalidDataException" reason:@"SensorsAnalytics distinct_id should not be nil or empty" userInfo:nil]; +// @throw [NSException exceptionWithName:@"InvalidDataException" reason:@"SensorsAnalytics distinct_id should not be nil or empty" userInfo:nil]; } if (distinctId.length > 255) { SAError(@"%@ max length of distinct_id is 255, distinct_id: %@", self, distinctId); - @throw [NSException exceptionWithName:@"InvalidDataException" reason:@"SensorsAnalytics max length of distinct_id is 255" userInfo:nil]; +// @throw [NSException exceptionWithName:@"InvalidDataException" reason:@"SensorsAnalytics max length of distinct_id is 255" userInfo:nil]; } dispatch_async(self.serialQueue, ^{ // 先把之前的distinctId设为originalId @@ -1257,6 +1282,14 @@ - (void)setVtrackWindow:(UIWindow *)vtrackWindow { } } +- (NSString *)getLastScreenUrl { + return _referrerScreenUrl; +} + +- (NSDictionary *)getLastScreenTrackProperties { + return _lastScreenTrackProperties; +} + #pragma mark - UIApplication Events - (void)setUpListeners { @@ -1304,12 +1337,26 @@ - (void)setUpListeners { return; } + //过滤用户设置的不被AutoTrack的Controllers + if (_filterControllers != nil && _filterControllers.count > 0) { + @try { + for (id controller in _filterControllers) { + if ([screenName isEqualToString:controller]) { + return; + } + } + } @catch (NSException *exception) { + SAError(@" unable to parse filterController"); + } + } + NSMutableDictionary *properties = [[NSMutableDictionary alloc] init]; [properties setValue:NSStringFromClass(klass) forKey:SCREEN_NAME_PROPERTY]; if ([controller conformsToProtocol:@protocol(SAAutoTracker)]) { UIViewController *autoTrackerController = (UIViewController *)controller; [properties addEntriesFromDictionary:[autoTrackerController getTrackProperties]]; + _lastScreenTrackProperties = [autoTrackerController getTrackProperties]; } if ([controller conformsToProtocol:@protocol(SAScreenAutoTracker)]) { @@ -1330,10 +1377,31 @@ - (void)setUpListeners { }; // 监听所有 UIViewController 显示事件 - [SASwizzler swizzleBoolSelector:@selector(viewWillAppear:) + if (_autoTrack) { + [SASwizzler swizzleBoolSelector:@selector(viewWillAppear:) onClass:[UIViewController class] withBlock:block named:@"track_view_screen"]; + } +} + +- (void)trackViewScreen:(NSString *)url withProperties:(NSDictionary *)properties { + NSMutableDictionary *trackProperties = [[NSMutableDictionary alloc] init]; + if (properties) { + [trackProperties addEntriesFromDictionary:properties]; + } + @synchronized(_lastScreenTrackProperties) { + _lastScreenTrackProperties = properties; + } + + [trackProperties setValue:url forKey:SCREEN_URL_PROPERTY]; + @synchronized(_referrerScreenUrl) { + if (_referrerScreenUrl) { + [trackProperties setValue:_referrerScreenUrl forKey:SCREEN_REFERRER_URL_PROPERTY]; + } + _referrerScreenUrl = url; + } + [self track:APP_VIEW_SCREEN_EVENT withProperties:trackProperties]; } - (void)applicationWillEnterForeground:(NSNotification *)notification {