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. (iOS) Request IDFA access

Step 1. Integrate the AppMetrica Unity plugin

Note.

The plugin uses the External Dependency Manager for Unity to resolve dependencies.

  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.

Step 3. (iOS) Request IDFA access

  1. Add the Info.plist file that explains text with the NSUserTrackingUsageDescription key. In this text, explain to the user why the app requests permission to use the IDFA. You can add an explanation:
    • In the Info.plist file, after generating the Xcode project from the Unity editor.
    • Using PostProcessBuild. For more information, see an example on GitHub.
  2. To display a dialog box requesting IDFA access, call the method:
    AppMetrica.Instance.RequestTrackingAuthorization (status => {
      // check status
    });
    Copied to clipboard

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.