Requirements
Installation
Add the SDK from Maven Central.
// build.gradle.kts (app)
dependencies {
implementation("com.himetrica.tracker:himetrica-android:<version>")
}Repository Setup
Make sure mavenCentral() is in your repositories (in settings.gradle.kts).
Install with AI
Copy this prompt and paste it into ChatGPT, Claude, or any AI assistant to install the Android SDK for you.
Install Himetrica analytics in my Android app using Kotlin. Himetrica is a native Android analytics SDK.
1. Add the Maven Central dependency to build.gradle.kts (app):
dependencies {
implementation("com.himetrica.tracker:himetrica-android:<version>")
}
Make sure mavenCentral() is in your repositories.
2. In your Application class, configure the SDK:
import com.himetrica.tracker.Himetrica
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
Himetrica.configure(this, "YOUR_API_KEY")
}
}
3. Track screen views (automatic with autoTrackScreenViews, or manual):
Himetrica.shared.trackScreen("HomeScreen")
4. Track custom events:
Himetrica.shared.track("purchase_completed", mapOf(
"product_id" to "pro_plan",
"price" to 9.99
))
5. Identify users after login:
Himetrica.shared.identify(
userId = user.externalId,
email = user.email,
metadata = mapOf("plan" to user.subscriptionPlan)
)
The userId parameter is optional but enables cross-device visitor merging — when two visitors identify with the same userId, they are automatically merged into one.
6. For Jetpack Compose, use the TrackScreen composable:
import com.himetrica.tracker.compose.TrackScreen
@Composable
fun HomeScreen() {
TrackScreen("HomeScreen")
// your content
}
7. If your app has login/logout, call reset() on logout to start a fresh visitor before identifying the next user:
Himetrica.shared.reset()
The SDK requires minSdk 21 (Android 5.0), compileSdk 35. It handles offline queuing, session management, and connectivity monitoring automatically.Initialization
Configure the SDK in your Application class.
// Application.kt
import com.himetrica.tracker.Himetrica
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
Himetrica.configure(this, "YOUR_API_KEY")
}
}Or with full configuration:
import com.himetrica.tracker.Himetrica
import com.himetrica.tracker.HimetricaConfig
val config = HimetricaConfig(
apiKey = "YOUR_API_KEY",
apiUrl = "https://app.himetrica.com",
sessionTimeoutMs = 30 * 60 * 1000L,
autoTrackScreenViews = true,
enableLogging = BuildConfig.DEBUG,
)
Himetrica.configure(this, config)Screen Tracking
Screens are tracked automatically via ActivityLifecycleCallbacks. You can also track manually.
// Screens are tracked automatically when autoTrackScreenViews = true.
// For manual tracking:
Himetrica.shared.trackScreen("HomeScreen", mapOf("section" to "featured"))Screen duration is automatically tracked when users navigate away or the app goes to background.
Event Tracking
Track custom events and user interactions.
Himetrica.shared.track("purchase_completed", mapOf(
"product_id" to "pro_plan",
"price" to 9.99,
"currency" to "USD"
))User Identification
Associate analytics with a user after authentication.
Himetrica.shared.identify(
userId = "user_123", // optional — stable external user ID
email = "user@example.com",
metadata = mapOf("plan" to "pro")
)The userId parameter is optional but enables cross-device visitor merging. When two visitors identify with the same userId, they are automatically merged into one.
Error Tracking
Capture errors manually in your catch blocks. Errors are rate-limited (max 10/minute) and deduplicated (5-minute window).
// Capture errors manually in catch blocks
try {
// risky operation
} catch (e: Exception) {
Himetrica.shared.captureError(e, mapOf("screen" to "checkout"))
}
// Capture a warning or info message
Himetrica.shared.captureMessage(
"User exceeded rate limit",
ErrorSeverity.WARNING
)Deep Link Attribution
Track where users came from via deep links.
Himetrica.shared.setReferrer("https://campaign.example.com/spring-sale")Jetpack Compose
Use the TrackScreen composable to track screens in Compose.
import com.himetrica.tracker.compose.TrackScreen
@Composable
fun HomeScreen() {
TrackScreen("HomeScreen")
// ... your content
}Note
Compose extensions are optional — apps without Jetpack Compose work fine without them. The Compose dependencies are compileOnly.
Configuration
Full configuration options for the SDK.
val config = HimetricaConfig(
apiKey = "YOUR_API_KEY",
apiUrl = "https://app.himetrica.com",
sessionTimeoutMs = 30 * 60 * 1000L,
autoTrackScreenViews = true,
enableLogging = false,
maxQueueSize = 1000,
flushIntervalMs = 30_000L,
)
Himetrica.configure(this, config)| Property | Default | Description |
|---|---|---|
| apiKey | required | Your Himetrica API key |
| apiUrl | app.himetrica.com | Custom API endpoint |
| sessionTimeoutMs | 1800000 | Session expiry in ms (30 min) |
| autoTrackScreenViews | true | Auto-track Activity screens |
| enableLogging | false | Enable debug logging |
| maxQueueSize | 1000 | Max queued events for offline |
| flushIntervalMs | 30000 | Queue flush interval in ms |
Features
Offline Support
Events are queued to a file-based queue when offline and flushed when connectivity is restored.
Session Management
Automatic session handling with configurable timeout and lifecycle awareness.
Duration Tracking
Automatic time-on-screen measurement for each Activity or Compose screen.
Jetpack Compose
TrackScreen composable for easy integration with Compose-based apps.
API Reference
| Method | Description |
|---|---|
| configure(context, apiKey) | Initialize with API key |
| configure(context, config) | Initialize with full config |
| trackScreen(name, properties?) | Track a screen view |
| track(event, properties?) | Track a custom event |
| identify(userId?, email?, metadata?) | Identify the current user. Pass userId for cross-device merging. |
| captureError(error, context?) | Manually capture an error |
| captureMessage(msg, severity) | Capture a log message |
| setReferrer(url) | Set deep link referrer |
| reset() | Clear all stored data and start a fresh visitor. Call on logout before identifying a new user. |
| flush() | Force flush event queue |
| destroy() | Clean up resources |