相关文档
配置环境:
下载官方SDK
1. 将sdk中的UMMobClick.framework拖拉到程序中。
2. target -> General -> Linked Frameworks and Librarises 添加库
CoreTelephony.framework
libz.tbd
libsqlite.tbd
Security.framework
3. 添加头文件 #import “UMMobClick/MobClick.h”
4. appdelegate中添加相关方法
- (void)umengTrack {
[MobClick setAppVersion:XcodeAppVersion]; //参数为NSString * 类型,自定义app版本信息,如果不设置,默认从CFBundleVersion里取
UMConfigInstance.appKey = @"5718e84467e58ec1c4003aa5";
// UMConfigInstance.token = @"5718e84467e58ec1c4003aa5";
// UMConfigInstance.secret = @"secretstringaldfkals";
// UMConfigInstance.eSType = E_UM_GAME;
[MobClick startWithConfigure:UMConfigInstance];
[MobClick setLogEnabled:YES];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 友盟的方法本身是异步执行,所以不需要再异步调用
[self umengTrack];
return YES;
}
5. 页面的统计
#pragma mark 页面的统计
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[MobClick beginLogPageView:@"ViewController"];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[MobClick endLogPageView:@"ViewController"];
}
6. 计数事件
6.1 统计发生次数
[MobClick event:(NSString *)eventId]; //eventId为事件id
[MobClick event:@"Forward"];
6.2 统计点击行为各属性被触发的次数
[MobClick event:(NSString *)eventId attributes:(NSDictionary *)attributes]; //考虑事件在不同属性上的取值
NSDictionary *dict = @{@"type" : @"book", @"quantity" : @"3"};
[MobClick event:@"purchase" attributes:dict];