Analytics Usage Guide

Tracking an Event

To track an event, define it by implementing AnalyticsEvent, then pass it to the tracker. Optionally, define context properties you want to be collected and sent with the event.

kotlin
1data class ButtonClick(
2 val buttonId: String,
3 override val createdAt: Instant = Instant.nowUtc(),
4) : AnalyticsEvent {
5
6 override val name = "button_click"
7
8 override val eventProperties = mapOf(
9 EventAnalyticsProperty.ButtonId to buttonId
10 )
11
12 override val contextProperties: Set<ContextAnalyticsProperty> = setOf(
13 ContextAnalyticsProperty.AppVersion,
14 ContextAnalyticsProperty.Platform,
15 ContextAnalyticsProperty.CurrentPage,
16 )
17}
18
19analyticsTracker.track(ButtonClick("submit"))

Collect Context Properties

Collect properties that should persist and attach to future events.

kotlin
1// Set global properties (e.g., on app start)
2analyticsTracker.track(
3 ContextAnalyticsProperty.AppVersion to "1.0.0",
4 ContextAnalyticsProperty.Platform to "Android"
5)
6
7// Set user properties (e.g., on login)
8analyticsTracker.track(
9 ContextAnalyticsProperty.UserId to "user_12345"
10)

Clearing Context Properties

Clear properties when they are no longer valid to prevent data pollution.

kotlin
1// Clear specific user properties on logout
2analyticsTracker.clear(AnalyticsPropertyScope.USER)