1
0
mirror of https://github.com/vector-im/riotX-android synced 2025-10-05 15:52:47 +02:00

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. * 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 * @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. * (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 failedEventId: String,
val error: MXCryptoError.ErrorType, val error: MXCryptoError.ErrorType,
// Was the current session cross signed verified at the time of the error // 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> private typealias DetailedErrorName = Pair<String, Error.Name>
@@ -146,12 +146,13 @@ class DecryptionFailureTracker @Inject constructor(
.filter { alreadyReported.contains(it.failedEventId).not() } .filter { alreadyReported.contains(it.failedEventId).not() }
.forEach { failure -> .forEach { failure ->
analyticsTracker.capture( analyticsTracker.capture(
Error( event = Error(
context = aggregation.key.first, context = aggregation.key.first,
domain = Error.Domain.E2EE, domain = Error.Domain.E2EE,
name = aggregation.key.second, name = aggregation.key.second,
cryptoModule = currentModule, 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) alreadyReported.add(failure.failedEventId)
} }

View File

@@ -47,8 +47,8 @@ class DefaultVectorAnalytics @Inject constructor(
private val analyticsConfig: AnalyticsConfig, private val analyticsConfig: AnalyticsConfig,
private val analyticsStore: AnalyticsStore, private val analyticsStore: AnalyticsStore,
private val lateInitUserPropertiesFactory: LateInitUserPropertiesFactory, private val lateInitUserPropertiesFactory: LateInitUserPropertiesFactory,
private val buildMeta: BuildMeta, @NamedGlobalScope private val globalScope: CoroutineScope,
@NamedGlobalScope private val globalScope: CoroutineScope buildMeta: BuildMeta,
) : VectorAnalytics { ) : VectorAnalytics {
private var posthog: PostHog? = null 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. * 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() { override fun init() {
observeUserConsent() observeUserConsent()
observeAnalyticsId() 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> { override fun getUserConsent(): Flow<Boolean> {
@@ -200,16 +193,17 @@ class DefaultVectorAnalytics @Inject constructor(
?.takeIf { userConsent == true } ?.takeIf { userConsent == true }
?.capture( ?.capture(
event.getName(), event.getName(),
(this.superProperties + event.getProperties().orEmpty() + extraProperties.orEmpty()).toPostHogProperties() (superProperties + event.getProperties().orEmpty() + extraProperties.orEmpty()).toPostHogProperties()
.toPostHogProperties()) )
} }
override fun screen(screen: VectorAnalyticsScreen) { override fun screen(screen: VectorAnalyticsScreen) {
Timber.tag(analyticsTag.value).d("screen($screen)") Timber.tag(analyticsTag.value).d("screen($screen)")
posthog posthog
?.takeIf { userConsent == true } ?.takeIf { userConsent == true }
?.screen(screen.getName(), ?.screen(
(this.superProperties + screen.getProperties().orEmpty()).toPostHogProperties() screen.getName(),
(superProperties + screen.getProperties().orEmpty()).toPostHogProperties()
) )
} }