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:
Step 1. Integrate the AppMetrica Unity plugin
The plugin uses the External Dependency Manager for Unity to resolve dependencies.
- Download the AppMetrica Unity plugin.
- Add the plugin to the project. To do this open the project in Unity Editor and import AppMetrica.unitypackage ( ).
- 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.
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 want to collect device location data, add the following permission to the AndroidManifest.xml file: android.permission.ACCESS_COARSE_LOCATION
.
Step 3. (iOS) Request IDFA access
- Add the
Info.plist
file that explains text with theNSUserTrackingUsageDescription
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.
- To display a dialog box requesting IDFA access, call the method:
AppMetrica.Instance.RequestTrackingAuthorization (status => { // check status });
Copied to clipboard