Swiftlytics
入门
要运行示例项目,请克隆仓存,并首先从 Example 目录运行 pod install
声明 (全局) MultiAnalyticsProvider 实例
import Swiftlytics
let swiftlytics: AnalyticsProvider = MultiAnalyticsProvider(providers: [
FirebaseAnalyticsProvider(priority: 3), //requires GoogleServices.info
FacebookAnalyticsProvider(priority: 2),
AppsFlyerAnalyticsProvider(priority: 1, devKey: "YOUR_DEV_KEY", appId: "YOUR_APP_ID")
])
将 AppDelegate 生命周期事件传递到您的实例
查看 Example/Swiftlytics/AppDelegate.swift
定义您的活动
struct MemoryWarningEvent: AnalyticsEventConvertible {
let name = "memory_warning"
let count: UInt
}
跟踪您的活动
...
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
count += 1
swiftlytics.trackEvent(MemoryWarningEvent(count: count))
}
跟踪用户属性以确定活动
swiftlytics.setUserId(UUID().uuidString) // your persistent database value in production
swiftlytics.setUserProperty(name: "name", withValue: "Sandy")
需求
已在 Xcode 9.4.1、Swift 4、Cocoapods 1.5.3 上测试
安装
Swiftlytics 可通过 CocoaPods 获取,并已拆分为 subspec 以避免集成您不希望集成的提供程序的膨胀。要安装它,只需在 Podfile 中添加以下行即可
pod 'Swiftlytics'
pod 'Swiftlytics/Firebase'
pod 'Swiftlytics/AppsFlyer'
pod 'Swiftlytics/Facebook'
贡献-添加新的提供程序
向 Swiftlytics.podspec 添加条目
s.subspec 'AppsFlyer' do |appsflyer|
appsflyer.source_files = 'Swiftlytics/AppsFlyer/**/*'
appsflyer.dependency 'AppsFlyerFramework'
end
定义一个新的AnalyticsProvider,实现所有协议方法
参见 Swiftlytics/AppsFlyer/AppsFlyerAnalyticsProvider 以获取示例
将任何测试添加到Example项目
确保在Example/Podfile中导入subspect,例如:
pod 'Swiftlytics/Facebook', :path => '../'
然后 pod install
许可协议
Swiftlytics采用MIT许可协议。更多信息请参阅LICENSE文件。