迁移到版本 6.0.0

同时运行两个版本的AppMetricaSDK

您可以在应用中并行使用两个版本的AppMetrica SDK。 这是不希望看到的。 统计数据应正常收集,尽管可能出现轻微偏差。 在这种情况下,应用大小可能会略微增加,因为它将包含两个 SDK 而不是一个。

注意

我们强烈不建议在应用代码中同时运行两个使用相同 API_KEY 的 SDK 版本。 换句话说,你不能同时激活AppMetrica并使用同一个API_KEY。 虽然这不会导致应用程序崩溃或失败,但会扭曲和破坏统计数据。 在迁移到新插件版本时,请确保不存在 Assets/AppMetrica 目录。 新的插件版本通过 UPM 提供,并保存到 Library/PackageCache/io.appmetrica.analytics@hash。

迁移指南

本指南包含示例,展示插件版本 5.2.0 和 6.0.0 之间的差异。 该部分仅涵盖不具备向后兼容性的方法。

要迁移到新版本,请执行以下步骤:

  1. 删除之前的插件版本。
  2. 使用 UPM 添加新插件版本。 要了解更多信息,请查看启用插件的部分。
  3. 将预制体替换为通过 RuntimeInitializeOnLoadMethodAttribute 进行激活。 要了解更多信息,请查看替换预制体的部分。
  4. 在项目代码中,替换已重命名或仅更改包的类和方法。 要了解更多信息,请查看重命名部分。

启用 AppMetrica Unity 插件 6.0.0

插件通过 Unity Package Manager 启用。

将以下依赖项添加到 Packages/manifest.json:

{
  "scopedRegistries": [
    {
      "name": "package.openupm.com",
      "url": "https://package.openupm.com",
      "scopes": [
        "com.google.external-dependency-manager",
        "io.appmetrica.analytics"
      ]
    }
  ],
  "dependencies": {
    "com.google.external-dependency-manager": "1.2.187",
    "io.appmetrica.analytics": "6.10.0"
  }
}
  1. 根据文档启用外部依赖管理器。

  2. 将 AppMetrica Unity Plugin 添加到 Packages/manifest.json 中的依赖项:

    {
      "dependencies": {
        "io.appmetrica.analytics": "https://github.com/appmetrica/appmetrica-unity-plugin.git#v6.10.0"
      }
    }
    

替换预制件

  1. 创建一个静态方法,添加 [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] 属性,然后使用 AppMetrica.Activate() 方法激活 AppMetrica。

示例:

using Io.AppMetrica;
using UnityEngine;

public static class AppMetricaActivator {
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    private static void Activate() {
        AppMetrica.Activate(new AppMetricaConfig("APIKey") {
            // copy settings from prefab
            CrashReporting = true, // prefab field 'Exceptions Reporting'
            SessionTimeout = 10, // prefab field 'Session Timeout Sec'
            LocationTracking = false, // prefab field 'Location Tracking'
            Logs = false, // prefab field 'Logs'
            FirstActivationAsUpdate = !IsFirstLaunch(), // prefab field 'Handle First Activation As Update'
            DataSendingEnabled = true, // prefab field 'Statistics Sending'
        });
    }

    private static bool IsFirstLaunch() {
        // Implement logic to detect whether the app is opening for the first time.
        // For example, you can check for files (settings, databases, and so on),
        // which the app creates on its first launch.
        return true;
    }
}
  1. 从你的阶段中移除AppMetrica预制件。

Renamings

备注

使用来自AppMetrica类的静态方法来工作于AppMetrica。 为了做这一步,请将AppMetrica.Instance替换为AppMetrica,并添加Io.AppMetrica导入。

  • 移除了 IYandexAppMetrica 接口,并将方法转移到了 AppMetrica 类。
    • 已移除 LibraryVersion 属性,请使用 GetLibraryVersion() 方法。
    • 已删除 LibraryApiLevel 属性。
    • 将ActivateWithConfiguration方法重命名为Activate.
    • 已移除 ReportEvent(string, IDictionary<string, object>) 方法,请使用 ReportEvent(string, string) 方法。
    • Removed the 报告错误(字符串, 字符串) 方法。
    • Removed the 报告错误(字符串, 字符串, 字符串) 方法。
    • 已移除 ReportError(string, string, YandexAppMetricaErrorDetails) 方法,请使用 ReportError(string, string, Exception) 方法代替。
    • 已移除 ReportError(string, string, YandexAppMetricaErrorDetails) 方法,请使用 ReportError(string, string, Exception) 方法。
    • 已移除 ReportError(Exception, string) 方法,请使用 ReportError(string, Exception) 方法。
    • 已移除 ReportError(YandexAppMetricaErrorDetails, string) 方法,请使用 ReportError(string, Exception) 方法。
    • 已移除 ReportUnhandledException(YandexAppMetricaErrorDetails) 方法,请使用 ReportUnhandledException(Exception) 方法。
    • Removed the ReportErrorFromLogCallback 方法。
    • 将SetStatisticsSending方法重命名为SetDataSendingEnabled.
    • 已移除 RequestAppMetricaDeviceID 方法,请使用 RequestStartupParams 方法。
    • Removed the 报告推荐链接 方法。
    • Removed the 请求跟踪授权 方法。
  • 将类YandexAppMetricaConfig重命名为AppMetricaConfig,并将其移至命名空间Io.AppMetrica.
    • 将属性 StatisticsSending 重命名为 DataSendingEnabled.
    • 将属性 HandleFirstActivationAsUpdate 重命名为 FirstActivationAsUpdate.
    • Removed the 儿童应用属性。
  • 将YandexAppMetricaConfig.Coordinates类重命名为Location,并将其移至Io.AppMetrica命名空间。
  • 将类YandexAppMetricaPreloadInfo重命名为PreloadInfo,并将其移至Io.AppMetrica命名空间。
  • 已删除 YandexAppMetricaRequestDeviceIDError 枚举。
  • 已删除 YandexAppMetricaRequestTrackingStatus 枚举。

广告收入

  • 将类YandexAppMetricaAdRevenue重命名为AdRevenue,并将其移至Io.AppMetrica命名空间。
    • 将属性 AdRevenue 重命名为 AdRevenueValue.

收入

  • 将类YandexAppMetricaRevenue重命名为Revenue,并将其移至Io.AppMetrica命名空间。
    • 已移除 (double, string) 构造函数,请使用 (long, string).
    • 已移除 Price 属性,请使用 PriceMicros.
    • 将属性 Receipt 重命名为 ReceiptValue.
  • 将YandexAppMetricaReceipt类重命名为Revenue.Receipt,并将其移至Io.AppMetrica命名空间。

用户属性

  • 将类YandexAppMetricaAttribute重命名为Attribute,并将其移至Io.AppMetrica.Profile命名空间。
  • 将类YandexAppMetricaBirthDateAttribute重命名为BirthDateAttribute,并将其移至命名空间Io.AppMetrica.Profile.
  • 将YandexAppMetricaBooleanAttribute类重命名为BooleanAttribute,并移至Io.AppMetrica.Profile命名空间。
  • 将YandexAppMetricaCounterAttribute类重命名为CounterAttribute,并移至Io.AppMetrica.Profile命名空间。
  • 将类YandexAppMetricaGenderAttribute重命名为GenderAttribute,并将其移至命名空间Io.AppMetrica.Profile.
  • 将 YandexAppMetricaGenderAttribute.Gender 类重命名为 GenderAttribute.Gender,并将其移至 Io.AppMetrica.Profile 命名空间。
    • Changed the name of the 女性 value to 女.
    • 将 MALE 值的名称更改为 Male.
    • 将 OTHER 的名称更改为 Other.
  • 将YandexAppMetricaNameAttribute类重命名为NameAttribute,并将其移至Io.AppMetrica.Profile命名空间。
  • 将类YandexAppMetricaNotificationsEnabledAttribute重命名为NotificationsEnabledAttribute,并将其移至命名空间Io.AppMetrica.Profile。
  • 将YandexAppMetricaNumberAttribute类重命名为NumberAttribute,并将其移至Io.AppMetrica.Profile命名空间。
  • 将YandexAppMetricaStringAttribute类重命名为StringAttribute,并将其移至Io.AppMetrica.Profile命名空间。
  • 将类 YandexAppMetricaUserProfile 重命名为 UserProfile,并将其移至命名空间 Io.AppMetrica.Profile。
    • Removed the ApplyFromArray(List<YandexAppMetricaUserProfileUpdate>) 方法。
  • 将类 YandexAppMetricaUserProfileUpdate 重命名为 UserProfileUpdate,并将其移至命名空间 Io.AppMetrica.Profile.