Installation and initialization
AppMetrica Unity is a plugin for the Unity3d platform. It includes the AppMetrica SDK support for Android and iOS.
This section describes the steps to enable and initialize the AppMetrica Unity plugin:
Step 1. Enable the AppMetrica Unity plugin
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.3.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.3.0" } }
Step 2. Initialize the library
We recommend activating AppMetrica with RuntimeInitializeOnLoadMethodAttribute.
Create a static method with the [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
attribute and activate AppMetrica using the AppMetrica.Activate()
method.
Example:
using Io.AppMetrica; using UnityEngine; public static class AppMetricaActivator { [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void Activate() { AppMetrica.Activate(new AppMetricaConfig("APIKey") { FirstActivationAsUpdate = !IsFirstLaunch(), }); } 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; } }
See also
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.