Add extra properties "cryptoSDK" to Error.CryptoSDK.Rust to all events and screen sent to PostHog.
This commit is contained in:
@@ -20,6 +20,7 @@ import com.posthog.PostHogInterface
|
||||
import com.squareup.anvil.annotations.ContributesMultibinding
|
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent
|
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen
|
||||
import im.vector.app.features.analytics.plan.Error
|
||||
import im.vector.app.features.analytics.plan.UserProperties
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.services.analyticsproviders.api.AnalyticsProvider
|
||||
@@ -56,11 +57,17 @@ class PosthogAnalyticsProvider @Inject constructor(
|
||||
}
|
||||
|
||||
override fun capture(event: VectorAnalyticsEvent) {
|
||||
posthog?.capture(event.getName(), properties = event.getProperties()?.keepOnlyNonNullValues())
|
||||
posthog?.capture(
|
||||
event = event.getName(),
|
||||
properties = event.getProperties()?.keepOnlyNonNullValues().withExtraProperties(),
|
||||
)
|
||||
}
|
||||
|
||||
override fun screen(screen: VectorAnalyticsScreen) {
|
||||
posthog?.screen(screen.getName(), properties = screen.getProperties())
|
||||
posthog?.screen(
|
||||
screenTitle = screen.getName(),
|
||||
properties = screen.getProperties().withExtraProperties(),
|
||||
)
|
||||
}
|
||||
|
||||
override fun updateUserProperties(userProperties: UserProperties) {
|
||||
@@ -98,3 +105,14 @@ private fun Map<String, Any?>.keepOnlyNonNullValues(): Map<String, Any> {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties which will be added to all Events and Screens.
|
||||
*/
|
||||
private val extraProperties: Map<String, Any> = mapOf(
|
||||
"cryptoSDK" to Error.CryptoSDK.Rust
|
||||
)
|
||||
|
||||
private fun Map<String, Any>?.withExtraProperties(): Map<String, Any> {
|
||||
return orEmpty() + extraProperties
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user