Skip to main content

Android tracker

The Android Tracker SDK supports Android 5 (API level 21+).


The Android Tracker SDK can be installed using Gradle.


Add into your build.gradle file:

dependencies {
implementation 'com.snowplowanalytics:snowplow-android-tracker:6.+'

No other dependencies are required to track events. However, some optional dependencies can be added:

Setting upโ€‹

Once the tracker SDK is correctly set as a dependency in your app project you have to instrument the tracker:

  1. In your Application subclass, set up the SDK as follows:

    val tracker = Snowplow.createTracker(
    applicationContext, // Android context (LocalContext.current in Compose apps)
    "appTracker", // namespace
    "" // Event collector URL

    The URL path for your collector endpoint should include the protocol, "http" or "https". If not included in the URL, "https" connection will be used by default.

  1. It creates a tracker instance which can be used to track events like this:

    val event = ScreenView("screen_name")

If you prefer to access the tracker when the reference is not directly accessible, you can use the defaultTracker :


You can override the default configuration with a fine grained configuration when you create the tracker. See the Android API docs for the Configuration classes to see all the options and defaults.

val networkConfig = NetworkConfiguration(
val trackerConfig = TrackerConfiguration("appId")
val sessionConfig = SessionConfiguration(
TimeMeasure(30, TimeUnit.SECONDS),
TimeMeasure(30, TimeUnit.SECONDS)

The trackers created with the above method are configured "locally" only. To create a tracker where the configuration can be updated through downloaded files, read this page about remote configuration.

The Android tracker Github repository includes demo apps in Java, Kotlin, and Kotlin with Jetpack Compose. They are provided as simple reference apps to help you set up the tracker.

Using the tracker with R8 optimizationโ€‹

Depending on your app configuration, you may need to add ProGuard rules to prevent the R8 compiler removing code needed for tracker function. Fetching certain platform context properties - AAID and app set ID - uses reflection. To include the necessary classes, add the following rules to the app's file.

# Reflection for the appSetId
-keep class { *; }
-keep class { *; }
-keep class { *; }
-keep class { *; }

# Reflection for the AAID (AndroidIdfa)
-keep class** { *; }
Was this page helpful?