Installation and initialization

AppMetrica Xamarin is a plugin for using AppMetrica features if you are developing apps using Xamarin for Android and iOS.

The general flow of using the plugin is shown below:

The plugin is provided as projects containing the following libraries:

Connecting AppMetrica to a project

To integrate AppMetrica in your project, you need to:

  1. Download and enable the plugin libraries. There are several ways to do this:

    • Connect the projects YandexMetrica.Xamarin.PCL, YandexMetrica.Xamarin.iOSBinding and YandexMetrica.Xamarin.AndroidBinding.

    • Build and enable the libraries from the projects. After building, the libraries will be available in the directories:

      • YandexMetrica.Xamarin.PCL/bin/(Debug|Release)/YandexMetrica.Xamarin.PCL.dll
      • YandexMetrica.Xamarin.iOSBinding/bin/(Debug|Release)/YandexMetrica.Xamarin.iOS.dll
      • YandexMetrica.Xamarin.AndroidBinding/bin/(Debug|Release)/YandexMetrica.Xamarin.Android.dll
  2. Initialize the AppMetrica library using the Activate() method of the YandexMetricaImplementation class. This method also performs registration of the IYandexMetrica interface implementation.

    public static void Activate(Context context, YandexMetricaConfig config, Application app = null) {...}
    ParameterDefault valueDescription

    Extended startup configuration. To create it, pass apiKey: YandexMetricaConfig(string apiKey)


    Allows enabling or disabling automatic app lifecycle tracking. By default, tracking is disabled.

    If this parameter takes the null value, for correct displays of sessions, use the OnPause() and OnResume() methods of the YandexMetricaImplementation class in the corresponding sections of the project

    What is the API key?

    The API key is a unique application identifier that is issued in the AppMetrica web interface during app registration.

    Make sure you have entered it correctly.

Connection examples

Examples of working with demonstration projects are shown below.

The YandexMetricaPCL library is connected. The YandexMetrica.Implementation is used for working with AppMetrica.

using System;
using YandexMetricaPCL;
using System.Collections.Generic;

namespace Metrica.Xamarin.CrossPlatform
    public class SharedLogic
        public static void LogClick(int clickNumber)
            var dict = new Dictionary<string, string>{ { "click", clickNumber.ToString() } };
            YandexMetrica.Implementation.ReportEvent("Click from shared logic", dict);

API methods

IYandexMetrica interface
// Event tracking.void ReportEvent(string message);void ReportEvent(string message, IDictionary<string, string> parameters);void ReportError(string message, Exception exception);// AppMetrica settings.void SetLocation(Coordinates coordinates);void SetLocationTracking(bool enabled);// Information about the version of AppMetrica 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; }
YandexAppMetricaPreloadInfo? PreloadInfo { get; set; }
YandexAppMetricaConfig.Coordinates class
double Latitude { get; set; }
double Longitude { get; set; }
YandexAppMetricaPreloadInfo class
YandexAppMetricaPreloadInfo(string trackingId);
string TrackingId { get; private set; }
Dictionary<string, string> AdditionalInfo { get; private set; }

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