SDK integration

The AppMetrica SDK for Android is distributed as an AAR library. The library is available in the Maven repository.

The steps below explain how to enable and initialize the AppMetrica SDK:

Step 1. Add the AppMetrica library to your project

If you use Gradle to build your app, add the following dependency to your app's Gradle file:

dependencies {
    // AppMetrica SDK.
    implementation("io.appmetrica.analytics:analytics:7.9.0")
}
dependencies {
    // AppMetrica SDK.
    implementation 'io.appmetrica.analytics:analytics:7.9.0'
}

Step 2. Initialize the AppMetrica library

During initialization, consider AppMetrica library specifics. For more information, see How the AppMetrica library works.

Initialize the AppMetrica library in your app. To do this, extend the Application class and override the onCreate() method as follows:

class YourApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        // Creating an extended library configuration.
        val config = AppMetricaConfig.newConfigBuilder(API_KEY).build()
        // Initializing the AppMetrica SDK.
        AppMetrica.activate(this, config)
    }
}
public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // Creating an extended library configuration.
        AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_KEY).build();
        // Initializing the AppMetrica SDK.
        AppMetrica.activate(this, config);
    }
}
What is the API key?

The API key is a unique app ID issued in the AppMetrica web interface at app registration. You can find it under Settings.

When initializing a library with an extended startup configuration, logging is enabled.

Step 3. (Optional) Configure location detection

Location detection helps you understand where your users are located geographically. By default sending device location is disabled, but can be enabled in the startup configuration. For details, see Using the library to send device location.

Step 4. (Optional) Configure sending of events, profile attributes, and revenue (#send)

To collect information on user actions in the app, set up sending your own events. For more information, see Sending your own events.

To collect information about users, set up sending profile attributes. For more information, see Profiles.

Unlike events, a profile attribute can take only one value. When you send a new attribute value, the old value is overwritten.

To track in-app purchases, set up Revenue sending. For more information, see In-App purchases.

Step 5. Test the library operation

Before testing the library, ensure that the SDK is initialized in compliance with recommendations.

Before starting testing, we recommend setting up data transmission to an additional API key or adding an app with a new API key. This will help you separate test data from your core statistics.

To test how the library works:

  1. Start the app with the AppMetrica SDK and use it for a while.
  2. Make sure your device is connected to the internet.
  3. In the AppMetrica interface, make sure that:
    • There is a new user in the Audience report.
    • The number of sessions in the EngagementSessions report has increased.
    • There are events and profile attributes in the Events and Profiles reports.

Learn more

Troubleshooting

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.

Contact support