Cleanup and bugfixes: toPostHogProperties() was called twice.

This commit is contained in:
Benoit Marty 2024-03-19 16:21:27 +01:00
parent dafd8d1bed
commit ba2327c57d
3 changed files with 22 additions and 26 deletions

View file

@ -24,6 +24,7 @@ interface AnalyticsTracker {
/**
* Capture an Event.
*
* @param event The event to capture.
* @param extraProperties Some extra properties to attach to the event, that are not part of the events definition
* (https://github.com/matrix-org/matrix-analytics-events/) and specific to this platform.
*/

View file

@ -39,7 +39,7 @@ private data class DecryptionFailure(
val failedEventId: String,
val error: MXCryptoError.ErrorType,
// Was the current session cross signed verified at the time of the error
val isCrossSignedVerified: Boolean = false
val isCrossSignedVerified: Boolean = false,
)
private typealias DetailedErrorName = Pair<String, Error.Name>
@ -146,12 +146,13 @@ class DecryptionFailureTracker @Inject constructor(
.filter { alreadyReported.contains(it.failedEventId).not() }
.forEach { failure ->
analyticsTracker.capture(
Error(
event = Error(
context = aggregation.key.first,
domain = Error.Domain.E2EE,
name = aggregation.key.second,
cryptoModule = currentModule,
), mapOf("is_cross_signed_verified" to failure.isCrossSignedVerified.toString())
),
extraProperties = mapOf("is_cross_signed_verified" to failure.isCrossSignedVerified.toString())
)
alreadyReported.add(failure.failedEventId)
}

View file

@ -47,8 +47,8 @@ class DefaultVectorAnalytics @Inject constructor(
private val analyticsConfig: AnalyticsConfig,
private val analyticsStore: AnalyticsStore,
private val lateInitUserPropertiesFactory: LateInitUserPropertiesFactory,
private val buildMeta: BuildMeta,
@NamedGlobalScope private val globalScope: CoroutineScope
@NamedGlobalScope private val globalScope: CoroutineScope,
buildMeta: BuildMeta,
) : VectorAnalytics {
private var posthog: PostHog? = null
@ -73,27 +73,20 @@ class DefaultVectorAnalytics @Inject constructor(
/**
* Super Properties are properties associated with events that are set once and then sent with every capture call.
*/
private var superProperties: MutableMap<String, String> = HashMap()
private val superProperties: Map<String, String> = mapOf(
// Put the appVersion (e.g 1.6.12).
"appVersion" to buildMeta.versionName,
// The appId (im.vector.app)
"applicationId" to buildMeta.applicationId,
// The app flavor (GooglePlay, FDroid)
"appFlavor" to buildMeta.flavorDescription,
// Parity with other platforms
"cryptoSDK" to "Rust",
)
override fun init() {
observeUserConsent()
observeAnalyticsId()
initSuperProperties()
}
/**
* Init the super properties that will be captured with all events.
*/
private fun initSuperProperties() {
// Put the appVersion (e.g 1.6.12).
superProperties["appVersion"] = buildMeta.versionName
// The appId (im.vector.app)
superProperties["applicationId"] = buildMeta.applicationId
// The app flavor (GooglePlay, FDroid)
superProperties["appFlavor"] = buildMeta.flavorDescription
// Parity with other platforms
superProperties["cryptoSDK"] = "Rust"
}
override fun getUserConsent(): Flow<Boolean> {
@ -200,16 +193,17 @@ class DefaultVectorAnalytics @Inject constructor(
?.takeIf { userConsent == true }
?.capture(
event.getName(),
(this.superProperties + event.getProperties().orEmpty() + extraProperties.orEmpty()).toPostHogProperties()
.toPostHogProperties())
(superProperties + event.getProperties().orEmpty() + extraProperties.orEmpty()).toPostHogProperties()
)
}
override fun screen(screen: VectorAnalyticsScreen) {
Timber.tag(analyticsTag.value).d("screen($screen)")
posthog
?.takeIf { userConsent == true }
?.screen(screen.getName(),
(this.superProperties + screen.getProperties().orEmpty()).toPostHogProperties()
?.screen(
screen.getName(),
(superProperties + screen.getProperties().orEmpty()).toPostHogProperties()
)
}