Installation and initialization

AppMetrica Unity is a plugin for theUnity3d 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. Integrate the AppMetrica Unity Plugin

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"
  }
}

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.

Contact support