Migrating to version 6.0.0
Running two versions of AppMetrica SDK in parallel
You can use two versions of AppMetrica SDK in your app in parallel. This is undesirable. The statistics should be collected normally, though minor deviations are possible. In that case, the app size might increase slightly since it will include two SDKs instead of one.
Alert
We strongly advise against running two SDK versions with the same API_KEY in the app code. In other words, you can't activate AppMetrica and use the prefab with the same API_KEY at the same time. While that won't cause crashes or failures in the app, it will distort and disrupt the statistics. When migrating to the new plugin version, make sure you don't have the Assets/AppMetrica directory. The new plugin version is provided via UPM and saved to Library/PackageCache/io.appmetrica.analytics@hash.
Migration guide
This guide contains examples that show the differences between plugin versions 5.2.0 and 6.0.0. This section only covers methods that do not have backward compatibility.
To migrate to the new version, follow these steps:
- Remove the previous plugin version.
- Add the new plugin version using UPM. For more information, see the section on enabling the plugin.
- Replace the prefab with activation via RuntimeInitializeOnLoadMethodAttribute. For more information, see the section on replacing the prefab.
- In the project code, replace the classes and methods that have been renamed or only changed their package. For more information, see the section on renamings.
Enabling AppMetrica Unity Plugin 6.0.0
The plugin is enabled via the Unity Package Manager.
Add the following dependencies to 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.183",
"io.appmetrica.analytics": "6.7.0"
}
}
-
Follow the documentation to enable External Dependency Manager.
-
Add AppMetrica Unity Plugin to the dependencies in Packages/manifest.json:
{ "dependencies": { "io.appmetrica.analytics": "https://github.com/appmetrica/appmetrica-unity-plugin.git#v6.7.0" } }
Replacing the prefab
- Create a static method with the
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]attribute and activate AppMetrica using theAppMetrica.Activate()method.
Example:
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;
}
}
- Remove the
AppMetricaprefab from your stages.
Renamings
Note
Use static methods from the AppMetrica class for working with AppMetrica. To do this, replace AppMetrica.Instance with AppMetrica and add Io.AppMetrica import.
- Removed the
IYandexAppMetricainterface and transferred the methods to theAppMetricaclass.- Removed the
LibraryVersionproperty, use theGetLibraryVersion()method. - Removed the
LibraryApiLevelproperty. - Renamed the
ActivateWithConfigurationmethod asActivate. - Removed the
ReportEvent(string, IDictionary<string, object>)method, use theReportEvent(string, string)method instead. - Removed the
ReportError(string, string)method. - Removed the
ReportError(string, string, string)method. - Removed the
ReportError(string, string, YandexAppMetricaErrorDetails)method, use theReportError(string, string, Exception)method instead. - Removed the
ReportError(string, string, YandexAppMetricaErrorDetails)method, use theReportError(string, string, Exception)method instead. - Removed the
ReportError(Exception, string)method, use theReportError(string, Exception)method instead. - Removed the
ReportError(YandexAppMetricaErrorDetails, string)method, use theReportError(string, Exception)method instead. - Removed the
ReportUnhandledException(YandexAppMetricaErrorDetails)method, use theReportUnhandledException(Exception)method instead. - Removed the
ReportErrorFromLogCallbackmethod. - Renamed the
SetStatisticsSendingmethod asSetDataSendingEnabled. - Removed the
RequestAppMetricaDeviceIDmethod, use theRequestStartupParamsmethod instead. - Removed the
ReportReferralUrlmethod. - Removed the
RequestTrackingAuthorizationmethod.
- Removed the
- Renamed the
YandexAppMetricaConfigclass asAppMetricaConfigand transferred it to theIo.AppMetricanamespace.- Renamed the
StatisticsSendingproperty asDataSendingEnabled. - Renamed the
HandleFirstActivationAsUpdateproperty asFirstActivationAsUpdate. - Removed the
AppForKidsproperty.
- Renamed the
- Renamed the
YandexAppMetricaConfig.Coordinatesclass asLocationand transferred it to theIo.AppMetricanamespace. - Renamed the
YandexAppMetricaPreloadInfoclass asPreloadInfoand transferred it to theIo.AppMetricanamespace. - Removed the
YandexAppMetricaRequestDeviceIDErrorenumeration. - Removed the
YandexAppMetricaRequestTrackingStatusenumeration.
AdRevenue
- Renamed the
YandexAppMetricaAdRevenueclass asAdRevenueand transferred it to theIo.AppMetricanamespace.- Renamed the
AdRevenueproperty asAdRevenueValue.
- Renamed the
Revenue
- Renamed the
YandexAppMetricaRevenueclass asRevenueand transferred it to theIo.AppMetricanamespace.- Removed the
(double, string)constructor, use(long, string). - Removed the
Priceproperty, usePriceMicros. - Renamed the
Receiptproperty asReceiptValue.
- Removed the
- Renamed the
YandexAppMetricaReceiptclass asRevenue.Receiptand transferred it to theIo.AppMetricanamespace.
User attributes
- Renamed the
YandexAppMetricaAttributeclass asAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaBirthDateAttributeclass asBirthDateAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaBooleanAttributeclass asBooleanAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaCounterAttributeclass asCounterAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaGenderAttributeclass asGenderAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaGenderAttribute.Genderclass asGenderAttribute.Genderand transferred it to theIo.AppMetrica.Profilenamespace.- Changed the name of the
FEMALEvalue toFemale. - Changed the name of the
MALEvalue toMale. - Changed the name of the
OTHERvalue toOther.
- Changed the name of the
- Renamed the
YandexAppMetricaNameAttributeclass asNameAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaNotificationsEnabledAttributeclass asNotificationsEnabledAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaNumberAttributeclass asNumberAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaStringAttributeclass asStringAttributeand transferred it to theIo.AppMetrica.Profilenamespace. - Renamed the
YandexAppMetricaUserProfileclass asUserProfileand transferred it to theIo.AppMetrica.Profilenamespace.- Removed the
ApplyFromArray(List<YandexAppMetricaUserProfileUpdate>)method.
- Removed the
- Renamed the
YandexAppMetricaUserProfileUpdateclass asUserProfileUpdateand transferred it to theIo.AppMetrica.Profilenamespace.