IOS 接入
在您的IOS App中快速接入 456 数据,全面了解用户行为,驱动业务增长。
快速开始
1. 注册账号
登录 456 数据控制台,在「站点管理」中创建站点,获取您的 打点地址 和 站点编号。
2. 下载IOS SDK
请点击 这里 下载IOS SDK并集成到您的App中
将libYhxwfx456SDK.a和Yhxwfx456SDK.h、Yhxwfx456AnalyticsSDK.h文件添加到工程目录中,在弹出窗口中,将 Destination 选项 Copy items into destination group’s folder (if needed)选中。 点击 Finish,完成静态库添加。
添加依赖框架
打开工程 Targets 的 Build Phases 选项,在 Link Binary With Libraries 分别添加如下2个依赖库:
libsqlite3.tbd
CFNetwork.framework
添加编译选项
注意:由于静态库中涉及到分类,在Build Settings中的Linking,找到Other Linker Flags,添加-ObjC。
打开Keychain Sharing选项
注意:由于该库用到钥匙串来存储手机的UUID,所以,确保打开keychain sharing选项。
在Capabilities中找到Keychain Sharing选项,将开关打开。
3. 初始化 456 - APP 统计 IOS SDK
在需要统计事件的工程.m文件中添加头文件:
#import "Yhxwfx456SDK.h"
在 AppDelegate 的 - application: didFinishLaunchingWithOptions: 中添加初始化代码:
/*
website:站点编号
channel:渠道
logflag:是否开启调式日志
autoclick:是否开启自动采集点击元素功能
anrtime:应用卡顿时间阈值,默认0秒(关闭),如果想检测1秒以上的卡顿,请设置为1,支持小数,如1.5
custompage:传入需要自定义的页面controller名字,每个页面用 | 隔开,还可以用(*)定义多个页面
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSDictionary *options = @{@"website":@"1000000X",@"channel":@"appstore", @"logflag":@"YES", @"autoclick":@"YES", @"custompage":@"PageViewController|ContentViewController", @"anrtime":@"1"};
[Yhxwfx456AnalyticsSDK startWithServerURL:@"https://www.456.cn/logcount/logcount.html" options:options];
return YES;
}
3. 进阶配置(可选)
用户属性设置
//userid 和 username 这两个为必填属性,其他属性可以自定义
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"321",@"userid",@"Leo",@"username",@"男",@"性别",@"28",@"年龄",nil];//userid、username不可随意更改,其余属性自定义,支持中文
[[Yhxwfx456AnalyticsSDK sharedInstance] trackUserSet:dict];
自定义事件设置
NSMutableDictionary *properties = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"1231",@"商品id",@"88",@"价格",nil];
[[Yhxwfx456AnalyticsSDK sharedInstance] trackEvent:@"event" eventCate:@"购物" eventName:@"加入购物车" properties:properties];
app和H5打通
App使用SDK ,采集到数据后,发往H5,H5 收到 App 发送的数据后,设置用户的Cookie,这样就保持了用户唯一识别标识的统一。
App端通过以下方法获取App中的用户唯一识别标识:
NSString *appCookie = [[Yhxwfx456AnalyticsSDK sharedInstance] getUserCookie];
H5端:
apph5.html?yhxwcookie=前面获取的appCookie&yhxwcounttype=app&yhxwsystemtype=ios