Extending the Framework

Adding a New Sink

To send data to a new provider (e.g., Mixpanel), implement AnalyticsSink. Make sure to add @Inject and @ContributesIntoSet(AppScope::class) to get it injected into the pipeline.

kotlin
1@Inject
2@ContributesIntoSet(AppScope::class)
3class MixpanelSink(private val mixpanel: MixpanelAPI) : AnalyticsSink {
4 override fun track(event: AnalyticsEvent, contextProperties: Map<ContextAnalyticsProperty, String>) {
5 val props = JSONObject()
6 // Add event properties
7 event.eventProperties.forEach { (k, v) -> props.put(k.name, v) }
8 // Add context properties
9 contextProperties.forEach { (k, v) -> props.put(k.name, v) }
10
11 mixpanel.track(event.name, props)
12 }
13}

Defining New Properties

Define strongly-typed keys for your properties to maintain consistency.

kotlin
1// In AnalyticsProperty.kt or a feature-specific extensions file
2data object UserTier : ContextAnalyticsProperty(
3 name = "user_tier",
4 scope = AnalyticsPropertyScope.USER
5)