GithubHelp home page GithubHelp logo

sensorsdata / sa-sdk-ios Goto Github PK

View Code? Open in Web Editor NEW
670.0 41.0 274.0 3.3 MB

神策数据官方 iOS 埋点 SDK,是一款轻量级用于 iOS 端的数据采集埋点 SDK。神策分析 iOS SDK 不仅有代码埋点功能,还通过使用运行时机制(Runtime)中的相关技术实现 iOS 端的全埋点(无埋点、无码埋点、无痕埋点、自动埋点)、点击图、可视化全埋点。

Home Page: http://opensource.sensorsdata.cn

License: Apache License 2.0

Objective-C 99.30% Ruby 0.35% HTML 0.11% Swift 0.23%

sa-sdk-ios's Introduction

License Average time to resolve an issue Percentage of issues still open GitHub release GitHub release date Carthage Compatible CocoaPods Compatible Platform

神策简介

神策数据 (Sensors Data),隶属于神策网络科技(北京)有限公司,是一家专业的大数据分析服务公司,大数据分析行业开拓者,为客户提供深度用户行为分析平台、以及专业的咨询服务和行业解决方案,致力于帮助客户实现数据驱动。神策数据立足大数据及用户行为分析的技术与实践前沿,业务现已覆盖以互联网、金融、零售快消、高科技、制造等为代表的十多个主要行业、并可支持企业多个职能部门。公司总部在北京,并在上海、深圳、合肥、武汉等地拥有本地化的服务团队,覆盖东区及南区市场;公司拥有专业的服务团队,为客户提供一对一的客户服务。公司在大数据领域积累的核心关键技术,包括在海量数据采集、存储、清洗、分析挖掘、可视化、智能应用、安全与隐私保护等领域。 More

SDK 简介

SensorsAnalytics SDK 是国内第一家开源商用版用户行为采集 SDK,目前支持代码埋点、全埋点、App 点击图、可视化全埋点等。目前已累计有 1500 多家付费客户,2500+ 的 App 集成使用,作为 App 数据采集利器,致力于帮助客户挖掘更多的商业价值,为其精准运营和业务支撑提供了可靠的数据来源。其采集全面而灵活、性能良好,并一直保持稳定的迭代,经受住了时间和客户的考验。

基本要求

iOS 9.0 及以上,Xcode 9.0 及以上。

推荐版本

推荐版本 版本链接
v4.5.7 https://github.com/sensorsdata/sa-sdk-ios/releases/tag/v4.5.7
v4.4.5 https://github.com/sensorsdata/sa-sdk-ios/releases/tag/v4.4.5

集成文档

请参考神策官网 iOS SDK 集成文档

贡献

    1. 在您的 GitHub 账户下 fork sa-sdk-ios 开源项目;
    1. 根据您的需求在本地 clone 一份 sa-sdk-ios 源码;
    1. 您修改或者新增功能后,push 到您 fork 的远程分支;
    1. 创建 pull request,向 sa-sdk-ios 官方开发分支提交合入请求;
    1. 神策 SDK 研发团队会及时 review 代码,测试通过后合入。

规划

可参考 ROADMAP.

新书推荐

《数据驱动:从方法到实践》 《Android 全埋点解决方案》 《iOS 全埋点解决方案》

感谢

License

Copyright 2015-2024 Sensors Data Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

sa-sdk-ios's People

Contributors

caojiang9 avatar minchaozhang avatar wangzhzh avatar yaoyue avatar zhujg-00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sa-sdk-ios's Issues

SENSORS_ANALYTICS_DISABLE_UIWEBVIEW 有遗漏的地方

SensorsAnalyticsSDK/VisualizedAutoTrack/SAVisualizedAutoTrackObjectSerializer.m:104

    if ([object isKindOfClass:UIWebView.class] || [object isKindOfClass:WKWebView.class]) {
        isContainWebView = YES;
    }

改一下?

    if (
#ifndef SENSORS_ANALYTICS_DISABLE_UIWEBVIEW
        [object isKindOfClass:UIWebView.class] ||
#endif
        [object isKindOfClass:WKWebView.class]) {
        isContainWebView = YES;
    }

-JSONSerializableObjectForObject crash, SIGSEGV SEGV_ACCERR

if ([newObj stringValue] && [[obj stringValue] rangeOfString:@"."].location != NSNotFound) {

id v = [self JSONSerializableObjectForObject:obj[key]];

JSONSerializableObjectForObject这个函数中有几处不太合理的代码. 应该使用newObj, 而不是obj. 问题代码会导致野指针崩溃, 不过概率较低.

iOS13崩溃问题

集成引入源码版本 1.10.9
崩溃有俩处. 一处解析崩溃比较多 一处较少在hook方法.

libobjc.A.dylib    0x1801d2030    _objc_retain + 16
SuperApp    0x1003c2a7c    -[JSONUtil JSONSerializeObject:] (JSONUtil.m:42)
SuperApp    0x1003c369c    -[MessageQueueBySqlite addObejct:withType:] (MessageQueueBySqlite.m:78)
SuperApp    0x1003f2b54    -[SensorsAnalyticsSDK enqueueWithType:andEvent:] (SensorsAnalyticsSDK.m:1446)
SuperApp    0x1003f420c    ___53-[SensorsAnalyticsSDK track:withProperties:withType:]_block_invoke (SensorsAnalyticsSDK.m:1724)
SuperApp    0x1009e2328    ___nbsEventNewDispatchAsync_block_invoke + 48
libdispatch.dylib    0x18015c658    __dispatch_call_block_and_release + 24
libdispatch.dylib    0x18015d1cc    __dispatch_client_callout + 16
libdispatch.dylib    0x18013a7c0    __dispatch_lane_serial_drain$VARIANT$armv81 + 564
libdispatch.dylib    0x18013b1d8    __dispatch_lane_invoke$VARIANT$armv81 + 400
libdispatch.dylib    0x1801444c0    __dispatch_workloop_worker_thread + 576
libsystem_pthread.dylib    0x1801acfa8    __pthread_wqthread + 276

binaryImages:

SuperApp    2F4C8AD6-D042-3513-8141-57A2594834AF    arm64    1
libobjc.A.dylib    57088C15-656F-3E7E-BC77-0454706906C3    arm64    0
libdispatch.dylib    721C34EF-4ABD-395F-8285-FECAA2457BA3    arm64    0
libsystem_pthread.dylib    BBAE706A-650C-3CE3-8F16-CF068F398DF0    arm64    0
CoreFoundation    6E8ED431-E507-3897-BF3A-AFD3D4C2C49F    arm64    0
UIKitCore    0x1844ca27c    -[UIApplication sendAction:to:from:forEvent:] + 100
SuperApp    0x1004000a4    -[UIApplication(AutoTrack) sa_sendAction:to:from:forEvent:] (UIApplication+AutoTrack.m:66)
UIKitCore    0x183b86e68    ___45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 148
UIKitCore    0x183b86da0    -[_UIButtonBarTargetAction _invoke:forEvent:] + 188
libobjc.A.dylib    0x180177d5c    -[NSObject performSelector:withObject:withObject:] + 76
UIKitCore    0x1844ca27c    -[UIApplication sendAction:to:from:forEvent:] + 100
SuperApp    0x1004000a4    -[UIApplication(AutoTrack) sa_sendAction:to:from:forEvent:] (UIApplication+AutoTrack.m:66)
UIKitCore    0x183ef1588    -[UIControl sendAction:to:forEvent:] + 208
UIKitCore    0x183ef18fc    -[UIControl _sendActionsForEvents:withEvent:] + 412
UIKitCore    0x183ef090c    -[UIControl touchesEnded:withEvent:] + 524
UIKitCore    0x184504950    -[UIWindow _sendTouchesForEvent:] + 2084
UIKitCore    0x184505c40    -[UIWindow sendEvent:] + 3336
UIKitCore    0x1844e1d9c    -[UIApplication sendEvent:] + 340
UIKitCore    0x18455a924    ___dispatchPreprocessedEventFromEventQueue + 5712
UIKitCore    0x18455cedc    ___handleEventQueueInternal + 4928
UIKitCore    0x184556060    ___handleHIDEventFetcherDrain + 112
CoreFoundation    0x1803dcb40    ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
CoreFoundation    0x1803dca94    ___CFRunLoopDoSource0 + 84
CoreFoundation    0x1803dc200    ___CFRunLoopDoSources0 + 184
CoreFoundation    0x1803d70cc    ___CFRunLoopRun + 1068
CoreFoundation    0x1803d6978    _CFRunLoopRunSpecific + 480
GraphicsServices    0x18a506534    _GSEventRunModal + 108
UIKitCore    0x1844c8f0c    _UIApplicationMain + 1940
SuperApp    0x1000c93c0    _main (main.m:26)

能否帮看下 兼容性问题! 谢谢!

在 Debugonly 模式下可不可以关闭日志的输出?

如题,埋点多的时候,控制台输出信息太多,很烦。

 if (_debugMode != SensorsAnalyticsDebugOff) {
    SAError(@"==========================================================================");
    SAError(@"%@ valid message: %@", self, jsonString);
 }

能不能加个不打印日志的模式。

'SensorsAnalyticsSDK.h' file not found

环境

Xcode : Version 11.0 (11A420a)
iOS 13.1.2 iPhone Xr 真机

报错

FBC9F514-6312-4B7D-BBE2-F58F68CA706C

Podfile

source 'https://github.com/CocoaPods/Specs.git'

inhibit_all_warnings!

platform :ios, '9.0'
use_frameworks!

target 'ace' do
  ... 

  pod 'Sentry'
  pod 'SensorsAnalyticsSDK', :subspecs => ['ENABLE_REACT_NATIVE_APPCLICK', 'LOG']
  pod 'RNSensorsAnalyticsModule', :path => '../node_modules/@sensors.data/react-native-sensors-analytics'

  ...

end

`SENSORS_ANALYTICS_DISABLE_UIWEBVIEW` 建议默认应该开启

为了适应Apple的审核要求,现在的App都得删除UIWebView。如果某些用户需要开启UIWebView,可以自己手动开启。

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'SensorsAnalyticsSDK'
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'SENSORS_ANALYTICS_DISABLE_UIWEBVIEW=0'
      end
    end
  end
end

所以建议 SENSORS_ANALYTICS_DISABLE_UIWEBVIEW 应该默认开启。

carthage 编译失败

*** Checking out sa-sdk-ios at "v1.9.2"
*** xcodebuild output can be found in /var/folders/7z/gkbw5rv50fj5w6d6hx15nh2c0000gn/T/carthage-xcodebuild.AxHda9.log
*** Skipped building sa-sdk-ios due to the error:
Dependency "sa-sdk-ios" has no shared framework schemes

mac下carthage编译失败

1.10.20 registerDynamicSuperProperties注册的键值对, 在启动时可能无法正常上报.

原因:

__block NSDictionary *dynamicSuperPropertiesDict = self.dynamicSuperProperties?self.dynamicSuperProperties():nil;
    dispatch_async(self.serialQueue, ^{
...

获取dynamicSuperProperties时没有放到self.serialQueue中, 所以, 如果调用registerDynamicSuperProperties:后马上调用track进行埋点(比如在启动完成时, 配置神策, 然后马上对启动埋一个点), 则可能取到的self.dynamicSuperProperties为nil. BUG!

总结: 多线程同步问题.

注入js问题

按照文档注入js时出现的异常
JavaScript execution returned a result of an unsupported type

上传苹果审核 无法通过,原因可能是:sdk内含uiwebview

命令行工具:cd 项目文件夹 grep -r UIWebView . ./ios/Pods/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m:#error disable UIWebView and use WKWebView, minimum deployment target is 8.0
./ios/Pods/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m: UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
./ios/Pods/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m: NSAssert(![webView isKindOfClass:NSClassFromString(@"UIWebView")], @"当前集成方式已禁用 UIWebView!❌");

IGListKit 中的collectionViewCell点击事件无法被正确track

看了一下源码,原因是因为:

  • sa-sdk通过setDelegate来对delegate对象的collectionview:didSelectItemAtIndexPath:进行swizzle
  • 进行swizzle的时候会一层一层的遍历父对象,通过class_getInstanceMethod来拿到originalSelector
  • IGListKit中的IGListAdapterProxy并没有实现相关方法,而是通过forwardingTargetForSelector将selector的代理到其他的对象中。

这样确实比较棘手,因为貌似直接拿不到原始的selector。有没有可能这样:

如果遍历不到originalSelector,尝试查看这个对象是不是响应collectionview:didSelectItemAtIndexPath:,如果遍历没找到实现,但是又做出了相应,则说明这个是一个proxy,通过forwardingTargetForSelector来继续进行查找,找到实现了这个方法的对象,进行swizzle。

UITableView 同理

打包成 framework

2018-01-12 16:55:01.503603+0800 12[44335:9302820] Could not successfully update network info during initialization.
2018-01-12 16:55:01.505292+0800 12[44335:9302820] <SensorsAnalyticsSDK: 0x7fb472c01cf0> initialized the instance of Sensors Analytics SDK with server url 'http://test-zouyuhan.cloud.sensorsdata.cn:8006/sa?project=wangzhuozhou&token=db52d13749514676', configure url 'http://test-zouyuhan.cloud.sensorsdata.cn:8006/config/iOS.conf?project=wangzhuozhou', debugMode: 'DebugAndTrack'
2018-01-12 16:55:01.505558+0800 12[44335:9302820] +[UIViewController sa_swizzleMethod:withMethod:error:]: unrecognized selector sent to class 0x1128c4ca8

打包成 framework 之后接入报错,找不到这个方法

iOS 13 崩溃问题:UIThreadSafeNode 找不到 nextResponder 方法

我们的App收到有关 iOS13 测试版中神策埋点SDK的两个崩溃,请帮忙解决:

UncaughtException=>NSInvalidArgumentException', reason: '-[UIThreadSafeNode nextResponder]: unrecognized selector sent to instance ' =>BWA=>-[UIApplication(AutoTrack) sa_sendAction:to:from:forEvent:] (UIApplication+AutoTrack.m:69)

UncaughtException=>NSInvalidArgumentException', reason: '-[UIThreadSafeNode nextResponder]: unrecognized selector sent to instance ' =>CoreFoundation=>

SDK 版本:1.10.20

UIView 分类 viewController 方法

@interface UIView (SensorsAnalytics)
- (nullable UIViewController *)viewController;

//viewID
@property (copy,nonatomic) NSString* sensorsAnalyticsViewID;

viewController 方法建议加上前缀

推送相关的ID写反了

1.6.39版本SensorsAnalyticsSDK.m文件第55行和56行好像写反了。

`NSString* const APP_PUSH_ID_PROPERTY_GETUI = @"$app_push_id_xiaomi";

NSString* const APP_PUSH_ID_PROPERTY_XIAOMI = @"$app_push_id_getui";`

image

优化 - (NSURLRequest *)buildFlushRequestWithJSONString:(NSString *)jsonString HTTPMethod:(NSString *)HTTPMethod

- (NSURLRequest *)buildFlushRequestWithJSONString:(NSString *)jsonString HTTPMethod:(NSString *)HTTPMethod {
    NSString *postBody;
    @try {
        // 2. 使用gzip进行压缩
        NSData *zippedData = [SAGzipUtility gzipData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
        // 3. base64
        NSString *b64String = [zippedData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn];
        int hashCode = [b64String sensorsdata_hashCode];
        b64String = [b64String stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]];
        postBody = [NSString stringWithFormat:@"crc=%d&gzip=1&data_list=%@", hashCode, b64String];


    /**
     base64 编码会使数据变大 可以优化掉
     https://zh.wikipedia.org/wiki/Base64
     优化版本
     */
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.serverURL];
    @try {
        // 2. 使用gzip进行压缩
        NSData *zippedData = [SAGzipUtility gzipData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];

        // 3. 生成签名
        NSData *md5Data = [zippedData md5];
        NSString *md5String = [md5Data base64Encode];

        // 4. 构建request
        request.HTTPBody = zippedData;
        [request setValue:md5String forHTTPHeaderField:@"Content-MD5"];
        [request setValue:@"application/zip" forHTTPHeaderField:@"Content-Type"];

    } @catch (NSException *exception) {

    } @finally {

    }

不符合Apple开发人员计划许可协议和应用的第3.3.2节商店审查指南2.5.2

你好,我使用了你们的SDK,仅仅初始化,未埋点,Apple审核上线几天后,收到违反政策通知,并要求下次更新移除,不知道有什么办法规避。下面是通知详情

Your app, extension, and/or linked framework appears to contain code designed explicitly with the capability to change your app’s behavior or functionality after App Review approval, which is not in compliance with section 3.3.2 of the Apple Developer Program License Agreement and App Store Review Guideline 2.5.2. This code, combined with a remote resource, can facilitate significant changes to your app’s behavior compared to when it was initially reviewed for the App Store. While you may not be using this functionality currently, it has the potential to load private frameworks, private methods, and enable future feature changes.

This includes any code which passes arbitrary parameters to dynamic methods such as dlopen(), dlsym(), respondsToSelector:, performSelector:, method_exchangeImplementations(), and running remote scripts in order to change app behavior or call SPI, based on the contents of the downloaded script. Even if the remote resource is not intentionally malicious, it could easily be hijacked via a Man In The Middle (MiTM) attack, which can pose a serious security vulnerability to users of your app.

Please perform an in-depth review of your app and remove any code, frameworks, or SDKs that fall in line with the functionality described above before submitting the next update for your app for review.

Best regards,

App Store Review

iOS 10.2&10.2.1上面奔溃

0 libsystem_kernel.dylib __pthread_kill + 8
1 libsystem_pthread.dylib pthread_kill + 112
2 libsystem_c.dylib abort + 140
3 libsystem_malloc.dylib __nano_vet_and_size_of_live
4 libsystem_malloc.dylib _nano_realloc + 648
5 libsystem_malloc.dylib malloc_zone_realloc + 180
6 CoreFoundation ___CFStringCreateImmutableFunnel3 + 692
7 CoreFoundation CFStringCreateFromExternalRepresentation + 104
8 Foundation -[NSPlaceholderString initWithData:encoding:] + 148
9 SensorsAnalyticsSDK -[MessageQueueBySqlite getFirstRecords:withType:] + 1072
10 SensorsAnalyticsSDK -[SensorsAnalyticsSDK flushByType:flushSize:] + 100
11 SensorsAnalyticsSDK -[SensorsAnalyticsSDK _flush:] + 180
12 libdispatch.dylib __dispatch_call_block_and_release + 24
13 libdispatch.dylib __dispatch_client_callout + 16
14 libdispatch.dylib __dispatch_queue_serial_drain + 928
15 libdispatch.dylib __dispatch_queue_invoke + 652
16 libdispatch.dylib __dispatch_queue_override_invoke + 360
17 libdispatch.dylib __dispatch_root_queue_drain + 572
18 libdispatch.dylib __dispatch_worker_thread3 + 124
19 libsystem_pthread.dylib _pthread_wqthread + 1288

NSPredicate异常

SAObjectSelector 类中的nextFilter方法中
NSPredicate *parsedPredicate = [NSPredicate predicateWithFormat:predicateFormat];
这一行抛异常,可能是正则语句拼接问题,是不是AND后边少了空格?
log如下:
po predicateFormat
(mp_varB='79b8fa9c1121f57d278e80859874cc05e6a372e5'ANDmp_varC='2e2d8e4253076ca9f32c167995e01787b8bcd8ed')

路径获取的缺陷

当三个按钮在 storybord 生成的,之后三个分别链接一个方法,那么他们的路径完全一致,如图:这样区分不出来的哦

swift支持么

如果是swift我看到里头有动态的method swizzling,那Sensors支持swift么。

iOS 13.1.2 Crash

iOS13.1.2 crash
下面是日志

-[SAJSONUtil JSONSerializeObject:] (in latin) (SAJSONUtil.m:59)
-[MessageQueueBySqlite addObejct:withType:] (in latin) (MessageQueueBySqlite.m:0)
-[SensorsAnalyticsSDK enqueueWithType:andEvent:] (in latin) (SensorsAnalyticsSDK.m:1477)
__53-[SensorsAnalyticsSDK track:withProperties:withType:]_block_invoke (in latin) (SensorsAnalyticsSDK.m:1740)

okkkkkkk

  • (NSString *)sa_viewId {
    return objc_getAssociatedObject(self, @selector(mixpanelViewId));
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.