Skip to content

Commit

Permalink
use the new updated analytics events
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed Mar 27, 2024
1 parent 28eead7 commit 4d04b27
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ import im.vector.app.features.analytics.plan.UserProperties
interface AnalyticsTracker {
/**
* Capture an Event.
*
* @param customProperties Some custom properties to attach to the event.
*/
fun capture(event: VectorAnalyticsEvent, customProperties: Map<String, Any>? = null)
fun capture(event: VectorAnalyticsEvent)

/**
* Track a displayed screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,17 @@ fun DecryptionFailure.toAnalyticsEvent(): Error {
domain = Error.Domain.E2EE,
name = this.error.toAnalyticsErrorName(),
// this is deprecated keep for backward compatibility
cryptoModule = Error.CryptoModule.Rust
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
eventLocalAgeMillis = eventLocalAgeAtDecryptionFailure?.toInt(),
isFederated = isFederated,
isMatrixDotOrg = isMatrixDotOrg,
timeToDecryptMillis = timeToDecryptMillis?.toInt() ?: -1,
wasVisibleToUser = wasVisibleOnScreen,
userTrustsOwnIdentity = ownIdentityTrustedAtTimeOfDecryptionFailure,
)
}

fun DecryptionFailure.toCustomProperties(): Map<String, Any> {
val properties = mutableMapOf<String, Any>()
if (timeToDecryptMillis != null) {
properties["timeToDecryptMillis"] = timeToDecryptMillis
} else {
properties["timeToDecryptMillis"] = -1
}
isFederated?.let {
properties["isFederated"] = it
}
properties["isMatrixDotOrg"] = isMatrixDotOrg
properties["wasVisibleToUser"] = wasVisibleOnScreen
properties["userTrustsOwnIdentity"] = ownIdentityTrustedAtTimeOfDecryptionFailure
eventLocalAgeAtDecryptionFailure?.let {
properties["eventLocalAgeAtDecryptionFailure"] = it
}
return properties
}

private fun MXCryptoError.toAnalyticsErrorName(): Error.Name {
return if (this is MXCryptoError.Base) {
when (errorType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,8 @@ class DecryptionFailureTracker @Inject constructor(
private fun reportFailure(decryptionFailure: DecryptionFailure) {
Timber.v("Report failure for event ${decryptionFailure.failedEventId}")
val error = decryptionFailure.toAnalyticsEvent()
val properties = decryptionFailure.toCustomProperties()

Timber.v("capture error $error with properties $properties")
analyticsTracker.capture(error, properties)
analyticsTracker.capture(error)

// now remove from tracked
trackedEventsMap.remove(decryptionFailure.failedEventId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,13 @@ class DefaultVectorAnalytics @Inject constructor(
}
}

override fun capture(event: VectorAnalyticsEvent, customProperties: Map<String, Any>?) {
override fun capture(event: VectorAnalyticsEvent) {
Timber.tag(analyticsTag.value).d("capture($event)")
posthog
?.takeIf { userConsent == true }
?.capture(
event.getName(),
(customProperties.orEmpty() +
event.getProperties().orEmpty()).toPostHogProperties()
event.getProperties().orEmpty().toPostHogProperties()
)
}

Expand Down
Loading

0 comments on commit 4d04b27

Please sign in to comment.