友盟统计是用来帮助移动应用开发商统计和分析流量来源、内容使用、用户属性和行为数据的。
一 登录友盟官网,添加新的应用,获取Appkey
相关链接
二 sdk集成 CocoaPods
$ cd/你的项目地址
$ open -e Podfile
target '你的app' do
pod 'UMengAnalytics-NO-IDFA'
end
$ pod install
三 代码示例
//AppDelegate.swift 设置Umeng appkey
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let config = UMAnalyticsConfig.sharedInstance()
config?.appKey = Constant.YouMengKey
MobClick.start(withConfigure: config)
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"]as! String
MobClick .setAppVersion(version)
}
四 相关使用
//具体页面的统计
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
MobClick.beginLogPageView("HomePage")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
MobClick.endLogPageView("HomePage")
}
//统计自定义事件
//1 统计发生次数
[MobClick event:(NSString *)eventId];
//2 统计点击行为各属性被触发的次数
[MobClick event:(NSString *)eventId attributes:(NSDictionary *)attributes];
//3 统计数值型变量的值的分布
[MobClick event:@"pay" attributes:@{@"book" : @"Swift Fundamentals"} counter:110];