Analytics: add screen API

This commit is contained in:
Benoit Marty 2021-11-23 16:08:27 +01:00 committed by Benoit Marty
parent 5c5a547aeb
commit 995e1e3d49
2 changed files with 21 additions and 5 deletions

View File

@ -63,4 +63,9 @@ interface VectorAnalytics {
* Capture an Event
*/
fun capture(event: String, properties: Map<String, Any>? = null)
/**
* Track a displayed screen
*/
fun screen(name: String, properties: Map<String, Any>? = null)
}

View File

@ -93,11 +93,22 @@ class DefaultVectorAnalytics @Inject constructor(
override fun capture(event: String, properties: Map<String, Any>?) {
posthog?.capture(
event,
properties?.let { props ->
Properties().apply {
props.forEach { putValue(it.key, it.value) }
}
}
properties.toPostHogProperties()
)
}
override fun screen(name: String, properties: Map<String, Any>?) {
posthog?.screen(
name,
properties.toPostHogProperties()
)
}
private fun Map<String, Any>?.toPostHogProperties(): Properties? {
if (this == null) return null
return Properties().apply {
this@toPostHogProperties.forEach { putValue(it.key, it.value) }
}
}
}