迁移到版本 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 之间的差异。 该部分仅涵盖不具备向后兼容性的方法。
要迁移到新版本,请执行以下步骤:
- 删除之前的插件版本。
- 使用 UPM 添加新插件版本。 要了解更多信息,请查看启用插件的部分。
- 将预制体替换为通过 RuntimeInitializeOnLoadMethodAttribute 进行激活。 要了解更多信息,请查看替换预制体的部分。
- 在项目代码中,替换已重命名或仅更改包的类和方法。 要了解更多信息,请查看重命名部分。
启用 AppMetrica Unity 插件 6.0.0
插件通过 Unity Package Manager 启用。
OpenUPM
UPM (GitHub)
将以下依赖项添加到 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"
}
}
-
根据文档启用外部依赖管理器。
-
将 AppMetrica Unity Plugin 添加到 Packages/manifest.json 中的依赖项:
{ "dependencies": { "io.appmetrica.analytics": "https://github.com/appmetrica/appmetrica-unity-plugin.git#v6.10.0" } }
替换预制件
- 创建一个静态方法,添加
[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;
}
}
- 从你的阶段中移除
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.
- Changed the name of the
- 将
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>)方法。
- Removed the
- 将类
YandexAppMetricaUserProfileUpdate重命名为UserProfileUpdate,并将其移至命名空间Io.AppMetrica.Profile.