Kitemetrics iOS 客户端 SDK
Kitemetics iOS 客户端 SDK 自动记录苹果搜索广告的关键词归因、安装和用户会话。另外,您还可以记录注册和其他自定义事件。报告可通过 http://kitemetrics.com/ 获取。
内容
要求
- iOS 8.0+
- Xcode 9.0+
- Objective-C 或 Swift 4.0+
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
需要 CocoaPods 1.1.0+ 版本来构建 Kitemetrics
要使用 CocoaPods 将 Kitemetrics 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'Kitemetrics'
end
然后,运行以下命令
$ pod install
还要运行以下更新命令以确保您有最新版本
$ pod update Kitemetrics
手动
如果您不想使用 CocoaPods 依赖管理器,您可以通过将文件复制到您的项目中或将它作为 git 子模块添加的方式,手动将 Kitemetrics 集成到项目中。
用法
在 AppDelegate 中初始化会话
Swift 5.0
import Kitemetrics
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Kitemetrics.shared.initSession(apiKey: "API_KEY")
return true
}
Objective-C
@import Kitemetrics;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Kitemetrics shared] initSessionWithApiKey:@"API_KEY"];
return YES;
}
记录购买事件
Swift 4.0
Kitemetrics.shared.logInAppPurchase(skProduct, quantity: 1)
//It is recommended to include the purchaseType if known
Kitemetrics.shared.logInAppPurchase(skProduct, quantity: 1, purchaseType: KFPurchaseType.appleInAppNonConsumable)
//If the SKProduct is unavailable you can log a purchase directly as
Kitemetrics.shared.logPurchase(productIdentifier: "productId", price: Decimal(0.99), currencyCode: "USD", quantity: 1, purchaseType: .eCommerce)
Objective-C
[[Kitemetrics shared] logInAppPurchase:skProduct quantity:1];
//It is recommended to include the purchaseType if known
[[Kitemetrics shared] logInAppPurchase:skProduct quantity:1 purchaseType:KFPurchaseTypeAppleInAppNonConsumable];
//If the SKProduct is unavailable you can log a purchase directly as
NSDecimal price = [[[NSDecimalNumber alloc] initWithFloat:0.99f] decimalValue];
[[Kitemetrics shared] logPurchaseWithProductIdentifier:@"productId" price:price currencyCode:@"USD" quantity:1 purchaseType:KFPurchaseTypeECommerce];
预定义和自定义事件的完整列表可在完整文档中找到。
示例
要运行示例项目,请克隆此仓库,然后从示例目录中运行pod install
命令。
文档
完整文档可在此网址查阅:http://kitemetrics.com/docs/。
注释
Kitemetrics使用广告标识符(IDFA)。在提交应用程序到苹果时,应回答“是”广告标识符问题,并在旁边勾选“将此应用内采取的操作归因于此前提供的广告”的复选框。
许可协议
Kitemetrics iOS客户端SDK在Apache License 2.0许可下可用。有关更多信息,请参阅LICENSE文件。