mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Init or stop posthog based on user consent
This commit is contained in:
+4
-3
@@ -115,15 +115,16 @@ class DefaultAnalyticsService @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initOrStop() {
|
private fun initOrStop() {
|
||||||
userConsent?.let { _userConsent ->
|
userConsent?.let { userConsent ->
|
||||||
when (_userConsent) {
|
when (userConsent) {
|
||||||
true -> {
|
true -> {
|
||||||
|
analyticsProviders.onEach { it.init() }
|
||||||
pendingUserProperties?.let {
|
pendingUserProperties?.let {
|
||||||
analyticsProviders.onEach { provider -> provider.updateUserProperties(it) }
|
analyticsProviders.onEach { provider -> provider.updateUserProperties(it) }
|
||||||
pendingUserProperties = null
|
pendingUserProperties = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false -> {}
|
false -> analyticsProviders.onEach { it.stop() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ interface AnalyticsProvider: AnalyticsTracker, ErrorTracker {
|
|||||||
*/
|
*/
|
||||||
val name: String
|
val name: String
|
||||||
|
|
||||||
suspend fun init()
|
fun init()
|
||||||
|
|
||||||
fun stop()
|
fun stop()
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -42,7 +42,7 @@ class PosthogAnalyticsProvider @Inject constructor(
|
|||||||
private var posthog: PostHog? = null
|
private var posthog: PostHog? = null
|
||||||
private var analyticsId: String? = null
|
private var analyticsId: String? = null
|
||||||
|
|
||||||
override suspend fun init() {
|
override fun init() {
|
||||||
posthog = createPosthog()
|
posthog = createPosthog()
|
||||||
posthog?.optOut(false)
|
posthog?.optOut(false)
|
||||||
identifyPostHog()
|
identifyPostHog()
|
||||||
@@ -66,10 +66,10 @@ class PosthogAnalyticsProvider @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun updateUserProperties(userProperties: UserProperties) {
|
override fun updateUserProperties(userProperties: UserProperties) {
|
||||||
posthog?.identify(
|
// posthog?.identify(
|
||||||
REUSE_EXISTING_ID, userProperties.getProperties()?.toPostHogUserProperties(),
|
// REUSE_EXISTING_ID, userProperties.getProperties()?.toPostHogUserProperties(),
|
||||||
IGNORED_OPTIONS
|
// IGNORED_OPTIONS
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun trackError(throwable: Throwable) {
|
override fun trackError(throwable: Throwable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user