Send UTD occurences to Posthog (#2575)

Co-authored-by: Stefan Ceriu <stefan.ceriu@gmail.com>
This commit is contained in:
Mauro
2024-03-15 00:42:44 +01:00
committed by GitHub
parent c68ec2c382
commit 7611123ae1
8 changed files with 55 additions and 12 deletions
@@ -139,6 +139,24 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}
}
.store(in: &cancellables)
userSession.clientProxy.actionsPublisher
.receive(on: DispatchQueue.main)
.sink { action in
guard case let .receivedDecryptionError(info) = action else {
return
}
let timeToDecryptMs: Int
if let unsignedTimeToDecryptMs = info.timeToDecryptMs {
timeToDecryptMs = Int(unsignedTimeToDecryptMs)
} else {
timeToDecryptMs = -1
}
analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError, timeToDecryptMillis: timeToDecryptMs)
}
.store(in: &cancellables)
}
func start() {
@@ -130,7 +130,18 @@ extension AnalyticsService {
func trackInteraction(index: Int? = nil, name: AnalyticsEvent.Interaction.Name) {
capture(event: AnalyticsEvent.Interaction(index: index, interactionType: .Touch, name: name))
}
/// Track the presentation of a screen
/// - Parameter context: To provide additional context or description for the error
/// - Parameter domain: The domain to which the error belongs to.
/// - Parameter name: The name of the error
/// - Parameter timeToDecryptMillis: The time it took to decrypt the event in milliseconds, needs to be used only to track UTD errors, otherwise if the error is nort related to UTD it should be nil.
/// Can be found in `UnableToDecryptInfo`. In case the `UnableToDecryptInfo` contains the value as nil, pass it as `-1`
func trackError(context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name, timeToDecryptMillis: Int? = nil) {
// CryptoModule is deprecated
capture(event: AnalyticsEvent.Error(context: context, cryptoModule: nil, cryptoSDK: .Rust, domain: domain, name: name, timeToDecryptMillis: timeToDecryptMillis))
}
/// Track the creation of a room
/// - Parameter isDM: true if the created room is a direct message, false otherwise
func trackCreatedRoom(isDM: Bool) {
@@ -589,6 +589,7 @@ class ClientProxy: ClientProxyProtocol {
let syncService = try await client
.syncService()
.withCrossProcessLock(appIdentifier: "MainApp")
.withUtdHook(delegate: ClientDecryptionErrorDelegate(actionsSubject: actionsSubject))
.finish()
let roomListService = syncService.roomListService()
@@ -803,6 +804,18 @@ private class ClientDelegateWrapper: ClientDelegate {
}
}
private class ClientDecryptionErrorDelegate: UnableToDecryptDelegate {
private let actionsSubject: PassthroughSubject<ClientProxyAction, Never>
init(actionsSubject: PassthroughSubject<ClientProxyAction, Never>) {
self.actionsSubject = actionsSubject
}
func onUtd(info: UnableToDecryptInfo) {
actionsSubject.send(.receivedDecryptionError(info))
}
}
private class IgnoredUsersListenerProxy: IgnoredUsersListener {
private let onUpdateClosure: ([String]) -> Void
@@ -21,6 +21,7 @@ import MatrixRustSDK
enum ClientProxyAction {
case receivedSyncUpdate
case receivedAuthError(isSoftLogout: Bool)
case receivedDecryptionError(UnableToDecryptInfo)
var isSyncUpdate: Bool {
if case .receivedSyncUpdate = self {