Skip to content

Commit

Permalink
Merge pull request #4020 from element-hq/rav/more_posthog_props
Browse files Browse the repository at this point in the history
Support new properties in posthog UTD reports
  • Loading branch information
bmarty authored Dec 13, 2024
2 parents 3643ec3 + f29dd29 commit c36ac5d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class UtdTracker(
timeToDecryptMillis = info.timeToDecryptMs?.toInt() ?: -1,
domain = Error.Domain.E2EE,
name = name,
eventLocalAgeMillis = info.eventLocalAgeMillis.toInt(),
userTrustsOwnIdentity = info.userTrustsOwnIdentity,
isFederated = info.ownHomeserver != info.senderHomeserver,
isMatrixDotOrg = info.ownHomeserver == "matrix.org",
)
analyticsService.capture(event)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class UtdTrackerTest {
eventId = AN_EVENT_ID.value,
timeToDecryptMs = null,
cause = UtdCause.UNKNOWN,
eventLocalAgeMillis = 100L,
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Expand All @@ -34,7 +35,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError
name = Error.Name.OlmKeysNotSentError,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 100,
)
)
assertThat(fakeAnalyticsService.screenEvents).isEmpty()
Expand All @@ -59,7 +64,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError
name = Error.Name.OlmKeysNotSentError,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
assertThat(fakeAnalyticsService.screenEvents).isEmpty()
Expand All @@ -84,7 +93,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.ExpectedDueToMembership
name = Error.Name.ExpectedDueToMembership,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
assertThat(fakeAnalyticsService.screenEvents).isEmpty()
Expand All @@ -109,7 +122,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.ExpectedSentByInsecureDevice
name = Error.Name.ExpectedSentByInsecureDevice,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}
Expand All @@ -132,7 +149,90 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.ExpectedVerificationViolation
name = Error.Name.ExpectedVerificationViolation,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}

@Test
fun `when onUtd is called with different sender and receiver servers, the expected analytics Event is sent`() {
val fakeAnalyticsService = FakeAnalyticsService()
val sut = UtdTracker(fakeAnalyticsService)
sut.onUtd(
aRustUnableToDecryptInfo(
eventId = AN_EVENT_ID.value,
ownHomeserver = "example.com",
senderHomeserver = "matrix.org",
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Error(
context = null,
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError,
isFederated = true,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}

@Test
fun `when onUtd is called from a matrix-org user, the expected analytics Event is sent`() {
val fakeAnalyticsService = FakeAnalyticsService()
val sut = UtdTracker(fakeAnalyticsService)
sut.onUtd(
aRustUnableToDecryptInfo(
eventId = AN_EVENT_ID.value,
ownHomeserver = "matrix.org",
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Error(
context = null,
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError,
isFederated = true,
isMatrixDotOrg = true,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}

@Test
fun `when onUtd is called from a verified device, the expected analytics Event is sent`() {
val fakeAnalyticsService = FakeAnalyticsService()
val sut = UtdTracker(fakeAnalyticsService)
sut.onUtd(
aRustUnableToDecryptInfo(
eventId = AN_EVENT_ID.value,
userTrustsOwnIdentity = true,
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Error(
context = null,
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = true,
eventLocalAgeMillis = 0,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import uniffi.matrix_sdk_crypto.UtdCause

internal fun aRustUnableToDecryptInfo(
eventId: String,
timeToDecryptMs: ULong?,
cause: UtdCause,
timeToDecryptMs: ULong? = null,
cause: UtdCause = UtdCause.UNKNOWN,
eventLocalAgeMillis: Long = 0L,
userTrustsOwnIdentity: Boolean = false,
senderHomeserver: String = "",
Expand Down

0 comments on commit c36ac5d

Please sign in to comment.