diff --git a/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt b/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt index 333450d0d8..dbf1970a46 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/AnalyticsTracker.kt @@ -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. */ diff --git a/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt b/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt index 5da3618ead..5d47ab89c7 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt @@ -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 @@ -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) } diff --git a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt index 5dcec27fa1..01dd8dff33 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt @@ -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 = HashMap() + private val superProperties: Map = 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 { @@ -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() ) }