Skip to content

Commit

Permalink
Release 1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuhan ZOU committed Aug 13, 2016
1 parent 8a5dcb9 commit 979d528
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 24 deletions.
4 changes: 2 additions & 2 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = "SensorsAnalyticsSDK"
s.version = "1.6.2"
s.version = "1.6.4"
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}" }
s.license = { :type => "Apache License, Version 2.0" }
s.author = { "Yuhan ZOU" => "[email protected]" }

s.source_files = "SensorsAnalyticsSDK/SensorsAnalyticsSDK", "SensorsAnalyticsSDK/SensorsAnalyticsSDK/*.{h,m}"
s.source_files = "SensorsAnalyticsSDK/SensorsAnalyticsSDK", "SensorsAnalyticsSDK/SensorsAnalyticsSDK/*.{h,m}", "SensorsAnalyticsSDK/SensorsAnalyticsSDK/Reachability.{h,m}"
s.public_header_files = "SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h"
s.frameworks = 'UIKit', 'Foundation', 'SystemConfiguration', 'CoreTelephony', 'CoreGraphics', 'QuartzCore'
s.libraries = 'icucore', 'sqlite3', 'z'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
A3A85C1F1C3BB8E100DCA1A4 /* SAUIControlBinding.m in Sources */ = {isa = PBXBuildFile; fileRef = A3997A2E1C3AC3B8005A9374 /* SAUIControlBinding.m */; };
A3A85C201C3BB8E100DCA1A4 /* SAUITableViewBinding.m in Sources */ = {isa = PBXBuildFile; fileRef = A3997A301C3AC3B8005A9374 /* SAUITableViewBinding.m */; };
A3BD57C51C58B1700006392F /* SAValueTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = A3F32BCF1C57296700C3B98D /* SAValueTransformers.m */; };
A3E3889F1D509B7100F6B9FC /* SAReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = A3E3889E1D509B7100F6B9FC /* SAReachability.m */; };
A3E388A11D509B8900F6B9FC /* SAReachability.h in Headers */ = {isa = PBXBuildFile; fileRef = A3E388A01D509B8900F6B9FC /* SAReachability.h */; };
A3E388A21D509BA100F6B9FC /* SAReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = A3E3889E1D509B7100F6B9FC /* SAReachability.m */; };
A3EEDCE91C4E084200D1362F /* DemoController.m in Sources */ = {isa = PBXBuildFile; fileRef = A3EEDCE81C4E084200D1362F /* DemoController.m */; };
A3F32BD01C57296700C3B98D /* SAValueTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = A3F32BCF1C57296700C3B98D /* SAValueTransformers.m */; };
A3F32BD11C57302700C3B98D /* NSData+SABase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D14F1801B4A7B15006AD786 /* NSData+SABase64.m */; };
Expand Down Expand Up @@ -199,6 +202,8 @@
A399F50C1C3C281D00B44340 /* SAValueTransformers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SAValueTransformers.h; sourceTree = "<group>"; };
A3A85C141C3BB1B800DCA1A4 /* NSInvocation+SAHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSInvocation+SAHelpers.h"; sourceTree = "<group>"; };
A3A85C151C3BB1B800DCA1A4 /* NSInvocation+SAHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSInvocation+SAHelpers.m"; sourceTree = "<group>"; };
A3E3889E1D509B7100F6B9FC /* SAReachability.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAReachability.m; sourceTree = "<group>"; };
A3E388A01D509B8900F6B9FC /* SAReachability.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SAReachability.h; sourceTree = "<group>"; };
A3EEDCE71C4E081F00D1362F /* DemoController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoController.h; sourceTree = "<group>"; };
A3EEDCE81C4E084200D1362F /* DemoController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoController.m; sourceTree = "<group>"; };
A3F32BCF1C57296700C3B98D /* SAValueTransformers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SAValueTransformers.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -277,6 +282,8 @@
4D5CA7791B43E92D00D7ACB7 /* SensorsAnalyticsSDK */ = {
isa = PBXGroup;
children = (
A3E388A01D509B8900F6B9FC /* SAReachability.h */,
A3E3889E1D509B7100F6B9FC /* SAReachability.m */,
A3746E791C3115EB008A50A3 /* SAAbstractDesignerMessage.h */,
A3746E7A1C3115EB008A50A3 /* SAAbstractDesignerMessage.m */,
A3746E7D1C3115EB008A50A3 /* SADesignerMessage.h */,
Expand Down Expand Up @@ -359,6 +366,7 @@
buildActionMask = 2147483647;
files = (
A3746E9C1C313E15008A50A3 /* SAApplicationStateSerializer.h in Headers */,
A3E388A11D509B8900F6B9FC /* SAReachability.h in Headers */,
A3997A331C3AC3B8005A9374 /* SAUIControlBinding.h in Headers */,
A3997A251C3AC1DE005A9374 /* SAObjectSelector.h in Headers */,
A3997A1F1C3ABCE3005A9374 /* SADesignerEventBindingMessage.h in Headers */,
Expand Down Expand Up @@ -440,7 +448,7 @@
TargetAttributes = {
4D0EB7BD1B47A88C0019FD21 = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = Y679VLFDC2;
DevelopmentTeam = RGJ23PSZZ8;
};
4D5CA7761B43E92D00D7ACB7 = {
CreatedOnToolsVersion = 6.3.2;
Expand Down Expand Up @@ -484,6 +492,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A3E3889F1D509B7100F6B9FC /* SAReachability.m in Sources */,
A3333BD61C5A12300013353F /* SADesignerDisconnectMessage.m in Sources */,
A3BD57C51C58B1700006392F /* SAValueTransformers.m in Sources */,
A3A85C181C3BB8E100DCA1A4 /* NSInvocation+SAHelpers.m in Sources */,
Expand Down Expand Up @@ -524,6 +533,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
A3E388A21D509BA100F6B9FC /* SAReachability.m in Sources */,
A3F32BD11C57302700C3B98D /* NSData+SABase64.m in Sources */,
4DBA6FA41B4B9B9C004F0ADB /* MessageQueueBySqlite.m in Sources */,
A3997A2A1C3AC342005A9374 /* SASwizzler.m in Sources */,
Expand Down Expand Up @@ -587,6 +597,7 @@
GCC_PREPROCESSOR_DEFINITIONS = (
"SENSORS_ANALYTICS_IDFA=1",
"$(inherited)",
"SENSORS_ANALYTICS_ENABLE_LOG=1",
);
INFOPLIST_FILE = HelloSensorsAnalytics/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
Expand Down
38 changes: 35 additions & 3 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,34 @@
* http://www.sensorsdata.cn/manual/debug_mode.html
*
* Debug模式有三种选项:
* SensorsAnalyticsDebugModeOff - 关闭DEBUG模式
* DebugOnly - 打开DEBUG模式,但该模式下发送的数据仅用于调试,不进行数据导入
* DebugAndTrack - 打开DEBUG模式,并将数据导入到SensorsAnalytics中
* SensorsAnalyticsDebugOff - 关闭DEBUG模式
* SensorsAnalyticsDebugOnly - 打开DEBUG模式,但该模式下发送的数据仅用于调试,不进行数据导入
* SensorsAnalyticsDebugAndTrack - 打开DEBUG模式,并将数据导入到SensorsAnalytics中
*/
typedef NS_ENUM(NSInteger, SensorsAnalyticsDebugMode) {
SensorsAnalyticsDebugOff,
SensorsAnalyticsDebugOnly,
SensorsAnalyticsDebugAndTrack,
};

/**
* @abstract
* TrackTimer 接口的时间单位。调用该接口时,传入时间单位,可以设置 event_duration 属性的时间单位。
*
* @discuss
* 时间单位有以下选项:
* SensorsAnalyticsTimeUnitMilliseconds - 毫秒
* SensorsAnalyticsTimeUnitSeconds - 秒
* SensorsAnalyticsTimeUnitMinutes - 分钟
* SensorsAnalyticsTimeUnitHours - 小时
*/
typedef NS_ENUM(NSInteger, SensorsAnalyticsTimeUnit) {
SensorsAnalyticsTimeUnitMilliseconds,
SensorsAnalyticsTimeUnitSeconds,
SensorsAnalyticsTimeUnitMinutes,
SensorsAnalyticsTimeUnitHours
};

/**
* @abstract
* App推送平台,用于设定相关推送平台的 Register ID
Expand Down Expand Up @@ -275,12 +293,26 @@ typedef NS_ENUM(NSInteger, SensorsAnalyticsAppPushService) {
* 送事件;随后在事件结束时,调用 track:"Event" withProperties:properties,SDK 会追踪 "Event" 事件,并自动将事件持续时
* 间记录在事件属性 "event_duration" 中。
*
* 默认时间单位为毫秒,若需要以其他时间单位统计时长,请使用 trackTimer:withTimeUnit
*
* 多次调用 trackTimer:"Event" 时,事件 "Event" 的开始时间以最后一次调用时为准。
*
* @param event event的名称
*/
- (void)trackTimer:(NSString *)event;

/**
* @abstract
* 初始化事件的计时器,允许用户指定计时单位。
*
* @discussion
* 请参考 trackTimer
*
* @param event event的名称
* @param timeUnit 计时单位,毫秒/秒/分钟/小时
*/
- (void)trackTimer:(NSString *)event withTimeUnit:(SensorsAnalyticsTimeUnit)timeUnit;

/**
* @abstract
* 清除所有事件计时器
Expand Down
73 changes: 55 additions & 18 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "SASwizzler.h"
#import "SensorsAnalyticsSDK.h"

#define VERSION @"1.6.3"
#define VERSION @"1.6.4"

#define PROPERTY_LENGTH_LIMITATION 8191

Expand All @@ -38,6 +38,8 @@
NSString* const APP_END_EVENT = @"$AppEnd";
// App 浏览页面
NSString* const APP_VIEW_SCREEN_EVENT = @"$AppViewScreen";
// App 首次启动
NSString* const APP_FIRST_START_PROPERTY = @"$is_first_time";
// App 是否从后台恢复
NSString* const RESUME_FROM_BACKGROUND_PROPERTY = @"$resume_from_background";
// App 浏览页面名称
Expand Down Expand Up @@ -98,8 +100,8 @@ @implementation SensorsAnalyticsSDK {
UInt64 _flushInterval;
UIWindow *_vtrackWindow;
NSDateFormatter *_dateFormatter;
BOOL _autoTrack;
BOOL _appRelaunched;
BOOL _autoTrack; // 自动采集事件
BOOL _appRelaunched; // App 从后台恢复
}

static SensorsAnalyticsSDK *sharedInstance = nil;
Expand Down Expand Up @@ -208,6 +210,8 @@ - (instancetype)initWithServerURL:(NSString *)serverURL
_autoTrack = NO;
_appRelaunched = NO;



_dateFormatter = [[NSDateFormatter alloc] init];
[_dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss.SSS"];

Expand Down Expand Up @@ -594,23 +598,37 @@ - (void)track:(NSString *)event withProperties:(NSDictionary *)propertieDict wit
if ([type isEqualToString:@"track"] || [type isEqualToString:@"track_signup"]) {
// track / track_signup 类型的请求,还是要加上各种公共property
// 这里注意下顺序,按照优先级从低到高,依次是automaticProperties, superProperties和propertieDict
[p addEntriesFromDictionary:self.automaticProperties];
[p addEntriesFromDictionary:_automaticProperties];
[p addEntriesFromDictionary:_superProperties];

// 是否WIFI是每次track的时候需要判断一次的
// 每次 track 时手机网络状态
NSString *networkType = [SensorsAnalyticsSDK getNetWorkStates];
[p setObject:networkType forKey:@"$network_type"];

if ([networkType isEqualToString:@"WIFI"]) {
[p setObject:@YES forKey:@"$wifi"];
} else {
[p setObject:@NO forKey:@"$wifi"];
}

NSNumber *eventBegin = self.trackTimer[event];
if (eventBegin) {
NSDictionary *eventTimer = self.trackTimer[event];
if (eventTimer) {
[self.trackTimer removeObjectForKey:event];
[p setObject:@([timeStamp longValue] - [eventBegin longValue]) forKey:@"$event_duration"];
NSNumber *eventBegin = [eventTimer valueForKey:@"eventBegin"];
SensorsAnalyticsTimeUnit timeUnit = [[eventTimer valueForKey:@"timeUnit"] intValue];

long eventDuration = [timeStamp longValue] - [eventBegin longValue];
switch (timeUnit) {
case SensorsAnalyticsTimeUnitHours:
eventDuration = eventDuration / 60;
case SensorsAnalyticsTimeUnitMinutes:
eventDuration = eventDuration / 60;
case SensorsAnalyticsTimeUnitSeconds:
eventDuration = eventDuration / 1000;
case SensorsAnalyticsTimeUnitMilliseconds:
break;
}

[p setObject:@(eventDuration) forKey:@"event_duration"];
}
}

Expand Down Expand Up @@ -685,6 +703,10 @@ - (void)track:(NSString *)event {
}

- (void)trackTimer:(NSString *)event {
[self trackTimer:event withTimeUnit:SensorsAnalyticsTimeUnitMilliseconds];
}

- (void)trackTimer:(NSString *)event withTimeUnit:(SensorsAnalyticsTimeUnit)timeUnit {
if (![self isValidName:event]) {
NSString *errMsg = [NSString stringWithFormat:@"Event name[%@] not valid", event];
if (_debugMode != SensorsAnalyticsDebugOff) {
Expand All @@ -700,7 +722,7 @@ - (void)trackTimer:(NSString *)event {
NSNumber *eventBegin = @([[self class] getCurrentTime]);

dispatch_async(self.serialQueue, ^{
self.trackTimer[event] = eventBegin;
self.trackTimer[event] = @{@"eventBegin" : eventBegin, @"timeUnit" : [NSNumber numberWithInt:timeUnit]};
});
}

Expand Down Expand Up @@ -1053,8 +1075,7 @@ + (NSString *)getNetWorkStates {
SANetworkStatus status = [reachability currentReachabilityStatus];
if (status == SAReachableViaWiFi) {
return @"WIFI";
}
else if (status == SAReachableViaWWAN) {
} else if (status == SAReachableViaWWAN) {
CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
if ([netinfo.currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
return @"2G";
Expand Down Expand Up @@ -1200,9 +1221,16 @@ - (void)setUpListeners {
if (_autoTrack) {
Class klass = [(UITableViewController *)obj class];
if (klass) {
[self track:APP_VIEW_SCREEN_EVENT withProperties:@{
SCREEN_NAME_PROPERTY : NSStringFromClass(klass)
}];
NSString *screenName = NSStringFromClass(klass);
if (![screenName isEqualToString:@"SFBrowserRemoteViewController"] &&
![screenName isEqualToString:@"SFSafariViewController"] &&
![screenName isEqualToString:@"UIInputWindowController"] &&
![screenName isEqualToString:@"UINavigationController"] &&
![screenName isEqualToString:@"UIApplicationRotationFollowingControllerNoTouches"]) {
[self track:APP_VIEW_SCREEN_EVENT withProperties:@{
SCREEN_NAME_PROPERTY : NSStringFromClass(klass)
}];
}
}
}
};
Expand All @@ -1223,20 +1251,29 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification {
- (void)applicationDidBecomeActive:(NSNotification *)notification {
SADebug(@"%@ application did become active", self);

[self startFlushTimer];
// 是否首次启动
BOOL isFirstStart = NO;
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) {
isFirstStart = YES;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

if (_autoTrack) {
// 追踪 AppStart 事件
[self track:APP_START_EVENT withProperties:@{
RESUME_FROM_BACKGROUND_PROPERTY : @(_appRelaunched),
APP_FIRST_START_PROPERTY : @(isFirstStart),
}];
// 启动 AppEnd 事件计时器
[self trackTimer:APP_END_EVENT];
[self trackTimer:APP_END_EVENT withTimeUnit:SensorsAnalyticsTimeUnitSeconds];
}

if (self.checkForEventBindingsOnActive) {
[self checkForConfigure];
}

[self startFlushTimer];
}

- (void)applicationWillResignActive:(NSNotification *)notification {
Expand Down Expand Up @@ -1340,7 +1377,7 @@ - (void)checkForConfigure {
}
}

SADebug(@"Sensors Analytics SDK is initializing with the VTrack server url: %@", _vtrackServerURL);
SADebug(@"%@ initialized the VTrack with server url: %@", self, _vtrackServerURL);
};

NSURL *URL = [NSURL URLWithString:self.configureURL];
Expand Down

0 comments on commit 979d528

Please sign in to comment.