diff --git a/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt index 538508b0de..b5752942e4 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt @@ -58,4 +58,9 @@ interface VectorAnalytics { * To be called when application is started */ fun init() + + /** + * Capture an Event + */ + fun capture(event: String, properties: Map? = null) } diff --git a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt index 1d3447efbb..09eeb47070 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt @@ -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?) { + posthog?.capture( + event, + properties?.let { props -> + Properties().apply { + props.forEach { putValue(it.key, it.value) } + } + } + ) + } }