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:
{
"dependencies": {
"com.google.external-dependency-manager": "https://github.com/google-unity/external-dependency-manager.git#1.2.177",
"io.appmetrica.analytics": "https://github.com/appmetrica/appmetrica-unity-plugin.git#v6.0.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
AppMetrica
prefab 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
IYandexAppMetrica
interface and transferred the methods to theAppMetrica
class.- Removed the
LibraryVersion
property, use theGetLibraryVersion()
method. - Removed the
LibraryApiLevel
property. - Renamed the
ActivateWithConfiguration
method 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
ReportErrorFromLogCallback
method. - Renamed the
SetStatisticsSending
method asSetDataSendingEnabled
. - Removed the
RequestAppMetricaDeviceID
method, use theRequestStartupParams
method instead. - Removed the
ReportReferralUrl
method. - Removed the
RequestTrackingAuthorization
method.
- Removed the
- Renamed the
YandexAppMetricaConfig
class asAppMetricaConfig
and transferred it to theIo.AppMetrica
namespace.- Renamed the
StatisticsSending
property asDataSendingEnabled
. - Renamed the
HandleFirstActivationAsUpdate
property asFirstActivationAsUpdate
. - Removed the
AppForKids
property.
- Renamed the
- Renamed the
YandexAppMetricaConfig.Coordinates
class asLocation
and transferred it to theIo.AppMetrica
namespace. - Renamed the
YandexAppMetricaPreloadInfo
class asPreloadInfo
and transferred it to theIo.AppMetrica
namespace. - Removed the
YandexAppMetricaRequestDeviceIDError
enumeration. - Removed the
YandexAppMetricaRequestTrackingStatus
enumeration.
AdRevenue
- Renamed the
YandexAppMetricaAdRevenue
class asAdRevenue
and transferred it to theIo.AppMetrica
namespace.- Renamed the
AdRevenue
property asAdRevenueValue
.
- Renamed the
Revenue
- Renamed the
YandexAppMetricaRevenue
class asRevenue
and transferred it to theIo.AppMetrica
namespace.- Removed the
(double, string)
constructor, use(long, string)
. - Removed the
Price
property, usePriceMicros
. - Renamed the
Receipt
property asReceiptValue
.
- Removed the
- Renamed the
YandexAppMetricaReceipt
class asRevenue.Receipt
and transferred it to theIo.AppMetrica
namespace.
User attributes
- Renamed the
YandexAppMetricaAttribute
class asAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaBirthDateAttribute
class asBirthDateAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaBooleanAttribute
class asBooleanAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaCounterAttribute
class asCounterAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaGenderAttribute
class asGenderAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaGenderAttribute.Gender
class asGenderAttribute.Gender
and transferred it to theIo.AppMetrica.Profile
namespace.- Changed the name of the
FEMALE
value toFemale
. - Changed the name of the
MALE
value toMale
. - Changed the name of the
OTHER
value toOther
.
- Changed the name of the
- Renamed the
YandexAppMetricaNameAttribute
class asNameAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaNotificationsEnabledAttribute
class asNotificationsEnabledAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaNumberAttribute
class asNumberAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaStringAttribute
class asStringAttribute
and transferred it to theIo.AppMetrica.Profile
namespace. - Renamed the
YandexAppMetricaUserProfile
class asUserProfile
and transferred it to theIo.AppMetrica.Profile
namespace.- Removed the
ApplyFromArray(List<YandexAppMetricaUserProfileUpdate>)
method.
- Removed the
- Renamed the
YandexAppMetricaUserProfileUpdate
class asUserProfileUpdate
and transferred it to theIo.AppMetrica.Profile
namespace.