Installation and initialization

AppMetrica Unity is a plugin for the Unity3d game platform that includes support for the AppMetrica SDK version 3.0.0 and later for Android and iOS.

Attention. The version 3.0.0 of the plugin is incompatible with current versions of the AppMetrica Push Unity plugin.

Integrating the AppMetrica Unity plugin

Step 1. Download the plugin.

Step 2. Add the plugin to the project. Open the project in Unity Editor and import the plugin AppMetrica.unitypackage (Assets → Import Package → Custom Package).

Step 3. 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.

Configuring the plugin

In the Inspector panel, you can specify settings for the prefab added to the stage:

  • 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.
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.

API methods

In the code, use AppMetrica.Instance for accessing AppMetrica.

Activating the plugin
void ActivateWithConfiguration(YandexAppMetricaConfig config);
event ConfigUpdateHandler OnActivation;
YandexAppMetricaConfig? ActivationConfig { get; }
Event tracking
void ReportEvent(string message);
void ReportEvent(string message, Dictionary<string, object> parameters);
void ReportError(string condition, string stackTrace);
Monitoring sessions
void ResumeSession();
void PauseSession();
AppMetrica settings
void SetLocationTracking(bool enabled);
void SetLocation(YandexAppMetricaConfig.Coordinates? coordinates);
void SetUserProfileID(string userProfileID);
Sending Revenue
void ReportRevenue(YandexAppMetricaRevenue revenue);
Sending user profiles
void ReportUserProfile(YandexAppMetricaUserProfile userProfile);
Information about the version of AppMetrica used
int LibraryApiLevel { get; }
string LibraryVersion { get; }
YandexAppMetricaConfig class
YandexAppMetricaConfig(string apiKey);

string ApiKey { get; private set; }
string AppVersion { get; set; }
Coordinates? Location { get; set; }
int? SessionTimeout { get; set; }
bool? CrashReporting { get; set; }
bool? LocationTracking { get; set; }
bool? Logs { get; set; }
bool? InstalledAppCollecting { get; set; }
bool? HandleFirstActivationAsUpdate { get; set; }
YandexAppMetricaPreloadInfo? PreloadInfo { get; set; }
YandexAppMetricaConfig.Coordinates class
double Latitude { get; set; }
double Longitude { get; set; }
YandexAppMetricaPreloadInfo class
YandexAppMetricaPreloadInfo(string trackingId);
            
tring TrackingId { get; private set; }
Dictionary<string, string> AdditionalInfo { get; private set; }
YandexAppMetricaRevenue class
YandexAppMetricaRevenue(double price, string currency);

double Price { get; private set; }
int? Quantity { get; set; }
string Currency { get; private set; }
string ProductID { get; set; }
YandexAppMetricaReceipt? Receipt { get; set; }
string Payload { get; set; }
YandexAppMetricaReceipt class
string Data { get; set; }
string Signature { get; set; }
string TransactionID { get; set; }
YandexAppMetricaUserProfile class
List<YandexAppMetricaUserProfileUpdate> GetUserProfileUpdates();
YandexAppMetricaUserProfile Apply(YandexAppMetricaUserProfileUpdate update);
YandexAppMetricaUserProfile ApplyFromArray(List<YandexAppMetricaUserProfileUpdate> updates);
YandexAppMetricaAttribute class
static YandexAppMetricaBirthDateAttribute BirthDate();
static YandexAppMetricaGenderAttribute Gender();
static YandexAppMetricaNameAttribute Name();
static YandexAppMetricaNotificationsEnabledAttribute NotificationsEnabled();
static YandexAppMetricaBooleanAttribute CustomBoolean(string key);
static YandexAppMetricaCounterAttribute CustomCounter(string key);
static YandexAppMetricaNumberAttribute CustomNumber(string key);
static YandexAppMetricaStringAttribute CustomString(string key);
YandexAppMetricaBirthDateAttribute class
YandexAppMetricaUserProfileUpdate WithAge(int age);
YandexAppMetricaUserProfileUpdate WithBirthDate(DateTime date);
YandexAppMetricaUserProfileUpdate WithBirthDate(int year);
YandexAppMetricaUserProfileUpdate WithBirthDate(int year, int month);
YandexAppMetricaUserProfileUpdate WithBirthDate(int year, int month, int day);
YandexAppMetricaUserProfileUpdate WithValueReset();
YandexAppMetricaBooleanAttribute class
YandexAppMetricaUserProfileUpdate WithValue(bool value);
YandexAppMetricaUserProfileUpdate WithValueIfUndefined(bool value);
YandexAppMetricaUserProfileUpdate WithValueReset();
YandexAppMetricaCounterAttribute class
YandexAppMetricaUserProfileUpdate WithDelta(double value);
YandexAppMetricaGenderAttribute class
YandexAppMetricaUserProfileUpdate WithValue(Gender value);
YandexAppMetricaUserProfileUpdate WithValueReset();
YandexAppMetricaNameAttribute class
YandexAppMetricaUserProfileUpdate WithValue(string value);
YandexAppMetricaUserProfileUpdate WithValueReset();
YandexAppMetricaNotificationsEnabledAttribute class
YandexAppMetricaUserProfileUpdate WithValue(bool value);
YandexAppMetricaUserProfileUpdate WithValueReset();
YandexAppMetricaNumberAttribute class
YandexAppMetricaUserProfileUpdate WithValue(double value);
YandexAppMetricaUserProfileUpdate WithValueIfUndefined(double value);
YandexAppMetricaUserProfileUpdate WithValueReset();
YandexAppMetricaStringAttribute class
YandexAppMetricaUserProfileUpdate WithValue(string value);
YandexAppMetricaUserProfileUpdate WithValueIfUndefined(string value);
YandexAppMetricaUserProfileUpdate WithValueReset();

Information about techniques and integration AppMetrica in the application, see the documentation for Android and iOS.