Analytics: add capture API

This commit is contained in:
Benoit Marty 2021-11-23 16:03:46 +01:00 committed by Benoit Marty
parent b33cddf0e3
commit 5c5a547aeb
2 changed files with 19 additions and 0 deletions

View file

@ -58,4 +58,9 @@ interface VectorAnalytics {
* To be called when application is started
*/
fun init()
/**
* Capture an Event
*/
fun capture(event: String, properties: Map<String, Any>? = null)
}

View file

@ -18,6 +18,7 @@ package im.vector.app.features.analytics.impl
import android.content.Context
import com.posthog.android.PostHog
import com.posthog.android.Properties
import im.vector.app.features.analytics.AnalyticsConfig
import im.vector.app.features.analytics.VectorAnalytics
import im.vector.app.features.analytics.store.AnalyticsStore
@ -60,6 +61,8 @@ class DefaultVectorAnalytics @Inject constructor(
override suspend fun onSignOut() {
// reset the analyticsId
setAnalyticsId("")
// reset the library
posthog?.reset()
}
override fun init() {
@ -86,4 +89,15 @@ class DefaultVectorAnalytics @Inject constructor(
.collectDeviceId(false)
.build()
}
override fun capture(event: String, properties: Map<String, Any>?) {
posthog?.capture(
event,
properties?.let { props ->
Properties().apply {
props.forEach { putValue(it.key, it.value) }
}
}
)
}
}