mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
adding ability to update the user properties (identity) via the vector analytics
This commit is contained in:
parent
84e23e1911
commit
515c8ce7c2
@ -16,6 +16,7 @@
|
||||
|
||||
package im.vector.app.features.analytics
|
||||
|
||||
import im.vector.app.features.analytics.plan.Identity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface VectorAnalytics : AnalyticsTracker {
|
||||
@ -58,4 +59,9 @@ interface VectorAnalytics : AnalyticsTracker {
|
||||
* To be called when application is started
|
||||
*/
|
||||
fun init()
|
||||
|
||||
/**
|
||||
* Update user specific properties
|
||||
*/
|
||||
fun updateUserProperties(identity: Identity)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package im.vector.app.features.analytics.impl
|
||||
|
||||
import android.content.Context
|
||||
import com.posthog.android.Options
|
||||
import com.posthog.android.PostHog
|
||||
import com.posthog.android.Properties
|
||||
import im.vector.app.BuildConfig
|
||||
@ -25,6 +26,7 @@ import im.vector.app.features.analytics.VectorAnalytics
|
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent
|
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen
|
||||
import im.vector.app.features.analytics.log.analyticsTag
|
||||
import im.vector.app.features.analytics.plan.Identity
|
||||
import im.vector.app.features.analytics.store.AnalyticsStore
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@ -34,6 +36,9 @@ import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
private val REUSE_EXISTING_ID: String? = null
|
||||
private val IGNORED_OPTIONS: Options? = null
|
||||
|
||||
@Singleton
|
||||
class DefaultVectorAnalytics @Inject constructor(
|
||||
private val context: Context,
|
||||
@ -170,6 +175,10 @@ class DefaultVectorAnalytics @Inject constructor(
|
||||
?.screen(screen.getName(), screen.getProperties()?.toPostHogProperties())
|
||||
}
|
||||
|
||||
override fun updateUserProperties(identity: Identity) {
|
||||
posthog?.identify(REUSE_EXISTING_ID, identity.getProperties().toPostHogProperties(), IGNORED_OPTIONS)
|
||||
}
|
||||
|
||||
private fun Map<String, Any>?.toPostHogProperties(): Properties? {
|
||||
if (this == null) return null
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user