Migrating to version 2.0.0
Running two versions of AppMetrica Push SDK in parallel
Two versions of the AppMetrica Push SDK can concurrently run in one app.
Alert
We don't recommend that you use several AppMetrica Push SDK versions in one app, because this can lead to anomalies in reports. In other words, you shouldn't activate AppMetricaPush
while using the AppMetricaPush
prefab from the older version. 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/AppMetricaPush
directory. The new plugin version is provided via UPM and saved to Library/PackageCache/io.appmetrica.analytics.push@hash
.
Migration guide
This guide contains examples that show the differences between the plugin versions 1.1.0
and 2.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 Push Unity plugin 2.0.0
The plugin is enabled via the Unity Package Manager.
Add the following dependencies to Packages/manifest.json:
{
"dependencies": {
"io.appmetrica.analytics.push": "https://github.com/appmetrica/push-unity-plugin.git#v2.0.0"
}
}
Replacing the prefab
-
Create a static method with the
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
attribute and activate AppMetricaPush using theAppMetricaPush.Activate()
method.Example:
using Io.AppMetrica; using Io.AppMetrica.Push; using UnityEngine; public static class AppMetricaActivator { [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void Activate() { AppMetrica.Activate(new AppMetricaConfig("APIKey")); AppMetricaPush.Activate(); } }
Note
You must call
AppMetricaPush.Activate()
strictly afterAppMetrica.Activate()
. -
Remove the
AppMetricaPush
prefab from your scenes.
Renaming the API
Note
To work with AppMetricaPush, use static methods from the AppMetricaPush
class. To do this, replace AppMetricaPush.Instance
with AppMetricaPush
and import Io.AppMetricaPush
.
- Removed the
IYandexAppMetricaPush
interface and transferred its methods to theAppMetricaPush
class.- Renamed the
Initialize
method asActivate
.
- Renamed the