IOS移动应用接入
一、配置环境
1、前提条件
系统中创建自定义渠道 绑定IOS 应用, 绑定之后提供 write key 提供给开发。
2、引入ios sdk
将NzAnalytics文件夹拷贝到项目目录
选择 File——Add Files to“Your Project”
选择 NzAnalytics文件
勾选 Copy items if needed
确保所有要用到SDK的 targets 都处于选中状态。
3、初始化sdk
在AppDelegate.m中引入 NzAnalytics.h文件,并在初始化方法 (BOOL) application:(UIApplication *)didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中初始化 SDK。示例代码
#import "NzAnalytics.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
NzAnalyticsOption * sdkConfiguration = [[NzAnalyticsOption alloc] init];
sdkConfiguration.writeKey = @"MS1mODdiMDkwMC1hNTI3LTQ2M******YyYWRmZjIyNzU=";// writeKey: 在linkflow的自定义渠道创建应用后,在“移动应用”列表页面里查看writeKey。
sdkConfiguration.endpoint = @"https://cdp.linkflowtech.com"; // 接收数据服务器地址,比如https://cdp.linkflowtech.com
sdkConfiguration.channelTypeId = @"externalId";
sdkConfiguration.launchOptions = launchOptions;
sdkConfiguration.debugMode = YES; // 默认值为NO。如果您需要将事件数据标记为测试,请设置为YES。
sdkConfiguration.autoTrackViewScreenHide = YES; //设置值为YES情况下,SDK会采集移动应用的打开页面事件
[NzAnalyticsSDK setupWithConfiguration:sdkConfiguration];
//other code
}
二、开发调用
1、获取用户信息,调用identify(识别用户)将用户信息上传
用户自定义属性 props 中的属性需要在系统中先创建 参照文档 自定义属性
接口:
设置用户身份
NSMutableArray<NzIdentity *> * identities = [NSMutableArray arrayWithObjects:
[[NzIdentity alloc] initWithId:@"bbb" type:@"wechat.openId"],
[[NzIdentity alloc] initWithId:@"12312312312" type:@"mobile"],
[[NzIdentity alloc] initWithId:@"cccc" type:@"wechat.unionId"],
[[NzIdentity alloc] initWithId:@"eeee" type:@"externalId"],
nil];
[[NzAnalyticsSDK shared] setIdentities: identities];
设置用户属性
NSMutableDictionary * profile = [NSMutableDictionary dictionary];
[profile setObject:@"dev" forKey:@"name"];
[profile setObject:@"12312312312" forKey:@"mobilePhone"];
[profile setObject:@"male" forKey:@"gender"];
NSMutableDictionary * props = [NSMutableDictionary dictionary];
[props setObject:@"1" forKey:@"memberLevel"];
[profile setObject:props forKey:@"props"];
[[NzAnalyticsSDK shared] setProfile: profile];
存在切换用户的时候需要调用清理缓存接口
[[NzAnalyticsSDK shared] cleanIdentities];
2、用户自定义事件
事件编码 以及事件属性 在系统中定义好之后导出提供
在linkflow平台,配置事件元数据,此步骤可由甲方管理员或者拥有配置权限角色来配置。
NzEvent * evt = [[NzEvent alloc] init];
evt.event = @"add_to_wishlist";
[evt setPropValue:[NSNumber numberWithInt:12345] forKey:@"product_id"];
[evt setPropValue:@"Huawei Mate5 Pro" forKey:@"product_name"];
[[NzAnalyticsSDK shared] track:evt];