Analytics: add PostHog library
This commit is contained in:
parent
8608230fa0
commit
b33cddf0e3
|
@ -462,6 +462,9 @@ dependencies {
|
|||
implementation libs.dagger.hilt
|
||||
kapt libs.dagger.hiltCompiler
|
||||
|
||||
// Analytics
|
||||
implementation 'com.posthog.android:posthog:1.1.2'
|
||||
|
||||
// gplay flavor only
|
||||
gplayImplementation('com.google.firebase:firebase-messaging:23.0.0') {
|
||||
exclude group: 'com.google.firebase', module: 'firebase-core'
|
||||
|
|
|
@ -262,6 +262,15 @@ SOFTWARE.
|
|||
</li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<b>posthog-android</b>
|
||||
<br/>
|
||||
https://github.com/PostHog/posthog-android
|
||||
PostHog Android integration is licensed under the MIT License
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
Apache License
|
||||
<br/>
|
||||
|
|
|
@ -42,6 +42,7 @@ import dagger.hilt.android.HiltAndroidApp
|
|||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.extensions.configureAndStart
|
||||
import im.vector.app.core.extensions.startSyncing
|
||||
import im.vector.app.features.analytics.VectorAnalytics
|
||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||
import im.vector.app.features.configuration.VectorConfiguration
|
||||
import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog
|
||||
|
@ -96,6 +97,7 @@ class VectorApplication :
|
|||
@Inject lateinit var callManager: WebRtcCallManager
|
||||
@Inject lateinit var invitesAcceptor: InvitesAcceptor
|
||||
@Inject lateinit var vectorFileLogger: VectorFileLogger
|
||||
@Inject lateinit var vectorAnalytics: VectorAnalytics
|
||||
|
||||
// font thread handler
|
||||
private var fontThreadHandler: Handler? = null
|
||||
|
@ -113,6 +115,7 @@ class VectorApplication :
|
|||
enableStrictModeIfNeeded()
|
||||
super.onCreate()
|
||||
appContext = this
|
||||
vectorAnalytics.init()
|
||||
invitesAcceptor.initialize()
|
||||
vectorUncaughtExceptionHandler.activate(this)
|
||||
|
||||
|
|
|
@ -53,4 +53,9 @@ interface VectorAnalytics {
|
|||
* To be called when a session is destroyed
|
||||
*/
|
||||
suspend fun onSignOut()
|
||||
|
||||
/**
|
||||
* To be called when application is started
|
||||
*/
|
||||
fun init()
|
||||
}
|
||||
|
|
|
@ -16,14 +16,23 @@
|
|||
|
||||
package im.vector.app.features.analytics.impl
|
||||
|
||||
import android.content.Context
|
||||
import com.posthog.android.PostHog
|
||||
import im.vector.app.features.analytics.AnalyticsConfig
|
||||
import im.vector.app.features.analytics.VectorAnalytics
|
||||
import im.vector.app.features.analytics.store.AnalyticsStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class DefaultVectorAnalytics @Inject constructor(
|
||||
private val context: Context,
|
||||
private val analyticsStore: AnalyticsStore
|
||||
) : VectorAnalytics {
|
||||
private var posthog: PostHog? = null
|
||||
|
||||
override fun getUserConsent(): Flow<Boolean> {
|
||||
return analyticsStore.userConsentFlow
|
||||
}
|
||||
|
@ -52,4 +61,29 @@ class DefaultVectorAnalytics @Inject constructor(
|
|||
// reset the analyticsId
|
||||
setAnalyticsId("")
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
val config: AnalyticsConfig = AnalyticsConfig.getConfig()
|
||||
?: return Unit.also { Timber.w("Analytics is disabled") }
|
||||
|
||||
posthog = PostHog.Builder(context, config.postHogApiKey, config.postHogHost)
|
||||
// Record certain application events automatically! (off/false by default)
|
||||
// .captureApplicationLifecycleEvents()
|
||||
|
||||
// Record screen views automatically! (off/false by default)
|
||||
// .recordScreenViews()
|
||||
|
||||
// Capture deep links as part of the screen call. (off by default)
|
||||
// .captureDeepLinks()
|
||||
|
||||
// Maximum number of events to keep in queue before flushing (20)
|
||||
// .flushQueueSize(20)
|
||||
|
||||
// Max delay before flushing the queue (30 seconds)
|
||||
// .flushInterval(30, TimeUnit.SECONDS)
|
||||
|
||||
// Enable or disable collection of ANDROID_ID (true)
|
||||
.collectDeviceId(false)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue