Installation and Setup
Requirements
- Snowplow pipeline running
- Android Studio installed
Installation and Setup
To begin tracking events using Snowplow Analytics' Android tracker, you'll need to set up your project and initialize the tracker. We’ll be following the modern JetPack Compose framework using Kotlin as our langauge.
Clone the official Android JetSurvey example app here, or import it from Android Studio as described here.
git clone https://github.com/android/compose-samples/tree/main
cd jetsurveyAdd the Snowplow Android tracker dependency to your project-level
libs.versions.toml
file (Replacex.x.x
with the latest version of the tracker.)snowplow = "x.x.x"
Add the dependency to your
build.gradle.kts
fileimplementation(libs.snowplow.analytics)
Create a new package in your project for analytics-related code, and create a
Analytics.kt
file inside it.Now we’ll create the
Analytics
object in thatAnalytics.kt
file by adding the following code. Replace"YOUR_NAMESPACE"
with a unique identifier for your tracker and"YOUR_COLLECTOR_URL"
with your Snowplow collector endpoint.package com.example.compose.jetsurvey.analytics
import android.content.Context
object Analytics {
fun start(context: Context) {
Snowplow.createTracker(
context,
namespace: "YOUR_NAMESPACE",
endpoint: "YOUR_COLLECTOR_URL"
)
}
}In the entrypoint for your app, you’ll now want to initialize the tracker. In this case the first composable function called is the
JetsurveyNavHost()
, inside theNavigation.kt
file. Add this line to the start of the function, before theNavHost
instantiation: