This guide contains instructions for the latest version of the Firebase Crashlytics SDK. If you migrated your app from Fabric, make sure you're upgraded to the latest SDK.

从 Fabric 解答切换为 Google Analytics(分析)

欢迎使用 Google Analytics(分析)!Google Analytics(分析)提供与 Fabric 相同的功能,并且支持您将事件数据与 Firebase 中的其他服务(如 Firebase Crashlytics 和 Firebase Cloud Messaging)集成。

本页面介绍如何在迁移后的应用中从 Fabric Answers 切换为 Google Analytics(分析)。您还可以查看我们的最常见问题解答

第 1 步:添加 Google Analytics(分析)

如果您还未将 Google Analytics(分析)添加到您的应用,请执行此操作。

第 2 步:将解答事件替换为 Analytics(分析)事件

在 Xcode 工作区中,将对解答事件的所有调用替换为对等的 Analytics(分析)事件。根据下方的转换表进行更改:

解答事件 Analytics(分析)事件 (Swift) Analytics(分析)事件 (Objective-C)
logPurchaseWithPrice AnalyticsEventEcommercePurchase kFIREventAddToCart
logAddToCartWithPrice AnalyticsEventAddToCart kFIREventAddToCart
logStartCheckoutWithPrice AnalyticsEventBeginCheckout kFIREventBeginCheckout
logContentViewWithName AnalyticsEventViewItem kFIREventViewItem
logSearchWithQuery AnalyticsEventSearch kFIREventSearch
logShareWithMethod AnalyticsEventShare kFIREventShare
logRating 无直接对等项 无直接对等项
logSignUpWithMethod AnalyticsEventSignUp kFIREventSignUp
logLoginWithMethod AnalyticsEventLogin kFIREventLogin
logInviteWithMethod 无直接对等项 无直接对等项
logLevelStart AnalyticsEventLevelStart kFIREventLevelStart
logLevelEnd AnalyticsEventLevelEnd kFIREventLevelEnd

例如,将:

Swift

Answers.logShareWithMethod("Twitter",
  contentName: "Answers named #2 in Mobile Analytics",
  contentType: "tweet",
  contentId: "601072000245858305",
  customAttributes: nil)
    

Objective-C

[Answers logShareWithMethod:@"Twitter"
    contentName: @"Answers named #2 in Mobile Analytics",
    contentType: @"tweet",
    contentId: @601072000245858305,
    customAttributes: @{}];
    

替换为:

Swift

Analytics.logEvent("AnalyticsEventShareWithMethod", parameters: [
  AnalyticsParameterName: "Twitter",
  AnalyticsParameterContentName: "Answers named #2 in Mobile Analytics",
  AnalyticsParameterContentType: "tweet",
  AnalyticsParameterContentId: "601072000245858305",
  AnalyticsParameterCustomAttributes: nil])
    

Objective-C

[FIRAnalytics logEventWithName:@"AnalyticsEventShareWithMethod"
    parameters: @{
        AnalyticsParameterName: @"Twitter",
        AnalyticsParameterContentName: @"Answers named #2 in Mobile Analytics",
        AnalyticsParameterContentType: @"tweet",
        AnalyticsParameterContentId: @601072000245858305,
        AnalyticsParameterCustomAttributes: @{}}];
    

常见问题解答

我的应用中有特定的解答事件,但我找不到对等的 Analytics(分析)事件来替换它。该怎么做?

您可以在 FirebaseAnalytics Framework 参考文档(SwiftObjective-C)中找到 Google Analytics(分析)的所有预定义事件以及有关创建自定义事件类型的说明。