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.
kotlin1data class ButtonClick(2 val buttonId: String,3 override val createdAt: Instant = Instant.nowUtc(),4) : AnalyticsEvent {56 override val name = "button_click"78 override val eventProperties = mapOf(9 EventAnalyticsProperty.ButtonId to buttonId10 )1112 override val contextProperties: Set<ContextAnalyticsProperty> = setOf(13 ContextAnalyticsProperty.AppVersion,14 ContextAnalyticsProperty.Platform,15 ContextAnalyticsProperty.CurrentPage,16 )17}1819analyticsTracker.track(ButtonClick("submit"))
Collect Context Properties
Collect properties that should persist and attach to future events.
kotlin1// Set global properties (e.g., on app start)2analyticsTracker.track(3 ContextAnalyticsProperty.AppVersion to "1.0.0",4 ContextAnalyticsProperty.Platform to "Android"5)67// 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.
kotlin1// Clear specific user properties on logout2analyticsTracker.clear(AnalyticsPropertyScope.USER)