AppMetrica 是一个一站式营销平台,用于安装归因、应用分析和推送活动。AppMetrica 提供三大关键功能来评估您的应用性能:广告追踪、使用分析和崩溃分析。
dependencies: [
.package(url: "https://github.com/appmetrica/appmetrica-sdk-ios", from: "5.0.0")
],
.target(
name: "YourTargetName",
dependencies: [
.product(name: "AppMetricaCore", package: "appmetrica-sdk-ios"),
// Add other modules like AppMetricaCrashes if needed.
]
)
pod init
。target 'YourAppName' do
# For all analytics features, add this umbrella module:
pod 'AppMetricaAnalytics', '~> 5.0.0'
# If you need specific integration, skip 'AppMetricaAnalytics' and add specific modules:
pod 'AppMetricaCore', '~> 5.0.0'
# Add other modules like 'AppMetricaCrashes', 'AppMetricaWebKit' or 'AppMetricaAdSupport' if needed.
end
pod install
安装依赖项。.xcworkspace
文件在 Xcode 中打开您的项目。为了符合 Apple 应用商店关于儿童隐私的规则(例如 COPPA),请添加 AppMetrica,但排除 AppMetricaAdSupport
模块
CocoaPods:
pod 'AppMetricaCore', '~> 5.0.0'
pod 'AppMetricaCrashes', '~> 5.0.0'
pod 'AppMetricaWebKit', '~> 5.0.0'
SPM:不要包含 AppMetricaAdSupport
。在 Xcode 中选择软件包时,为此模块选择 None,或者在 Package.swift
中指定依赖项。
AppMetricaCore
: 基本 SDK 使用所必需。AppMetricaCrashes
: 启用崩溃报告。AppMetricaWebKit
: 用于处理来自 WebKit 的事件。AppMetricaAdSupport
: IDFA 收集所需,不要将其包含在儿童应用中。以下是如何将 AppMetrica 添加到您的项目(适用于 SwiftUI 和 UIKit)
在您的 AppDelegate
中 import AppMetricaCore
。
在 application(_:didFinishLaunchingWithOptions:)
方法中使用您的 API 密钥初始化 AppMetrica。
将此代码放入您的 AppDelegate.swift
import AppMetricaCore
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
if let configuration = AppMetricaConfiguration(apiKey: "Your_API_Key") {
AppMetrica.activate(with: configuration)
}
return true
}
创建一个新的 Swift 文件以实现 AppDelegate
兼容性,并使用以下代码
import UIKit
import AppMetricaCore
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
if let configuration = AppMetricaConfiguration(apiKey: "Your_API_Key") {
AppMetrica.activate(with: configuration)
}
return true
}
}
然后在您的 App
结构体中
@main
struct YourAppNameApp: App {
// Use the `@UIApplicationDelegateAdaptor` property wrapper to work with AppDelegate and set up AppMetrica
@UIApplicationDelegateAdaptor var appDelegate: AppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
注意: 将 "Your_API_Key"
替换为您的实际 AppMetrica API 密钥,该密钥是在 AppMetrica Web 界面的设置下提供的,它是您应用程序的唯一标识符。
发送自定义事件:要捕获和分析应用内的用户操作,您应该配置自定义事件的发送。有关更多信息,请参见 事件。
用户配置文件:要深入了解您的用户群,请设置配置文件属性的发送。这允许通过自定义属性对用户行为进行更丰富的分析。请记住,配置文件属性只能保存一个值,并且为属性发送新值将覆盖现有值。有关更多信息,请参见 用户配置文件。
应用内购买(收入追踪):要有效地监控应用内购买,请配置收入事件的发送。此功能使您能够全面跟踪应用程序内的交易。有关设置详细信息,请参见 应用内购买。
在继续测试之前,建议将测试数据与实际应用统计信息隔离。考虑使用单独的 API 密钥进行测试数据,方法是将统计信息发送到其他 API 密钥或在 AppMetrica 界面中添加具有新 API 密钥的另一个应用实例。
启动应用:启动与 AppMetrica SDK 集成的应用程序,并与之交互一段时间以生成测试数据。
互联网连接:确保运行该应用程序的设备已连接到互联网,以便将数据传输到 AppMetrica。
在 AppMetrica 界面中验证数据:登录到 AppMetrica 界面并确认以下内容
如果您遇到任何问题,请查阅故障排除部分。
您可以在我们的完整文档中找到全面的集成详细信息以及安装、配置、测试等说明。
AppMetrica 在 MIT 许可证下发布。 许可协议可在 LICENSE 中找到。