Skip to content

Commit

Permalink
Release 1.6.13
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhzh committed Sep 29, 2016
1 parent 5511e9f commit 2cbe0ee
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -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}" }
Expand Down
35 changes: 35 additions & 0 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* 用来设置每个事件都带有的一些公共属性
Expand Down
78 changes: 73 additions & 5 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#import <WebKit/WebKit.h>
#endif

#define VERSION @"1.6.12"
#define VERSION @"1.6.13"

#define PROPERTY_LENGTH_LIMITATION 8191

Expand Down Expand Up @@ -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;

Expand All @@ -115,6 +118,7 @@ @implementation SensorsAnalyticsSDK {
BOOL _autoTrack; // 自动采集事件
BOOL _appRelaunched; // App 从后台恢复
NSString *_referrerScreenUrl;
NSDictionary *_lastScreenTrackProperties;
}

static SensorsAnalyticsSDK *sharedInstance = nil;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"];

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1257,6 +1282,14 @@ - (void)setVtrackWindow:(UIWindow *)vtrackWindow {
}
}

- (NSString *)getLastScreenUrl {
return _referrerScreenUrl;
}

- (NSDictionary *)getLastScreenTrackProperties {
return _lastScreenTrackProperties;
}

#pragma mark - UIApplication Events

- (void)setUpListeners {
Expand Down Expand Up @@ -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<SAAutoTracker> *autoTrackerController = (UIViewController<SAAutoTracker> *)controller;
[properties addEntriesFromDictionary:[autoTrackerController getTrackProperties]];
_lastScreenTrackProperties = [autoTrackerController getTrackProperties];
}

if ([controller conformsToProtocol:@protocol(SAScreenAutoTracker)]) {
Expand All @@ -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 {
Expand Down

0 comments on commit 2cbe0ee

Please sign in to comment.