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 AppMetrica Unity:

  1. Step 1. Integrate the AppMetrica Unity plugin
  2. Step 2. Configure the plugin
  3. Step 3. (Android) Connect the Play Install Referrer library

Step 1. Integrate the AppMetrica Unity plugin

  1. Add the plugin to the project. To do this open the project in Unity Editor and import AppMetrica.unitypackage (Assets → Import Package → Custom Package).

  2. Open the Assets/AppMetrica folder and drag the prefab AppMetrica to the project's main stage.

If the plugin is integrated this way, the AppMetrica script on the added prefab automatically initializes the AppMetrica SDK and configures tracking of sessions and errors.

The added AppMetrica prefab is a singleton. It isn't deleted when switching to a new Unity stage, and it deletes other objects that the AppMetrica script is installed on.

Step 2. Configure the plugin

In the Inspector panel specify the settings for the prefab added to the scene:

  • API key — The unique application identifier that is issued in the AppMetrica web interface during app registration.
  • Exceptions Reporting — Enable or disable sending errors.
  • Session Timeout Sec — The timeout for ending the session if the app is inactive.
  • Location Tracking — Enable or disable transmitting location data.
  • Logs — Enable or disable logging the library's activity.
  • Handle First Activation As Update — Enable or disable the ability to confirm that the first launch of an app with the AppMetrica Plugin is an app update, and not an install.
  • StatisticsSending — Enable or disable sending statistics.
Note. The AppMetrica/ExampleUI directory has examples of using AppMetrica in apps.

To launch the iOS version in Unity 4, you need to copy the file Other/Unity.iOS.Extensions.Xcode.dll to the directory Assets/AppMetrica/Editor.

If you don't want to collect device location data, go to the Unity 3d interface (Settings → Other Settings → Scripting Define Symbols) and add the APP_METRICA_TRACK_LOCATION_DISABLED directive.

Step 3. (Android) Connect the Play Install Referrer library

Connecting the library Play Install Referrer is mandatory. It is used to track the installation source.

If you are using Gradle to build the app, add the following dependency to the Assets/Plugins/Android/mainTemplate.gradle file:
dependencies {
    ...
    implementation 'com.android.installreferrer:installreferrer:1.1.2'
}
Copied to clipboard
If there is no file Assets/Plugins/Android/mainTemplate.gradle , use the non-Gradle method.
If you don't use Gradle

Download the Play Install Referrer library and move it to Assets/Plugins/Android.