---
title: "How to add analytics to Android apps"
description: "Add privacy-first analytics to Android applications using OpenPanel's Kotlin SDK. Track events, identify users, and analyze behavior."
type: guide
difficulty: intermediate
timeToComplete: 10
date: 2025-12-15
lastUpdated: 2025-12-15
team: OpenPanel Team
steps:
- name: "Add the dependency"
anchor: "install"
- name: "Initialize OpenPanel"
anchor: "setup"
- name: "Track events"
anchor: "events"
- name: "Identify users"
anchor: "identify"
- name: "Track screen views"
anchor: "screenviews"
- name: "Verify your setup"
anchor: "verify"
---
# How to add analytics to Android apps
This guide walks you through adding OpenPanel analytics to an Android application using the Kotlin SDK. You'll learn how to track events, identify users, and monitor screen views across your app.
OpenPanel works well for Android apps because it provides a lightweight, privacy-focused SDK that handles offline queuing and automatic system information collection. Unlike web SDKs, native apps require a client secret for authentication since CORS headers aren't available.
## Prerequisites
- An Android project (minSdkVersion 21+)
- An OpenPanel account
- Your Client ID and Client Secret from the [dashboard](https://dashboard.openpanel.dev)
## Add the dependency [#install]
Start by adding the OpenPanel SDK to your app's `build.gradle.kts` file. The SDK is available through standard Gradle dependency management.
```kotlin
dependencies {
implementation("dev.openpanel:openpanel:0.0.1")
}
```
The Kotlin SDK is currently in development, so check the [GitHub repository](https://github.com/Openpanel-dev/kotlin-sdk) for the latest version number before adding it to your project.
## Initialize OpenPanel [#setup]
Before you can track events, you need to initialize OpenPanel in your Application class. This ensures the SDK is available throughout your app and can properly manage its lifecycle.
```kotlin
import android.app.Application
import dev.openpanel.OpenPanel
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
OpenPanel.create(
context = this,
options = OpenPanel.Options(
clientId = "YOUR_CLIENT_ID",
clientSecret = "YOUR_CLIENT_SECRET"
)
)
}
}
```
You also need to register your Application class in the Android manifest so the system knows to use it.
```xml
```
If you're using dependency injection with Hilt or Dagger, you can provide OpenPanel as a singleton instead. This approach integrates better with modern Android architecture patterns.
```kotlin
import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import dev.openpanel.OpenPanel
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides
@Singleton
fun provideOpenPanel(@ApplicationContext context: Context): OpenPanel {
return OpenPanel.create(
context,
OpenPanel.Options(
clientId = "YOUR_CLIENT_ID",
clientSecret = "YOUR_CLIENT_SECRET"
)
)
}
}
```
## Track events [#events]
Once OpenPanel is initialized, you can track events anywhere in your app by getting the SDK instance and calling the `track` method. Each event has a name and an optional map of properties.
```kotlin
import dev.openpanel.OpenPanel
class MainActivity : AppCompatActivity() {
private lateinit var op: OpenPanel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
op = OpenPanel.getInstance(this)
findViewById