From 4a7827792a8b716c2af570398142b981b37b5775 Mon Sep 17 00:00:00 2001 From: JanNiklas Grabowski Date: Wed, 11 Oct 2023 15:07:07 +0200 Subject: [PATCH 1/2] MESSENGER-4821 add dimension for decryption error tracking --- Riot/Modules/Analytics/DecryptionFailure.swift | 7 +++++-- Riot/Modules/Analytics/DecryptionFailureTracker.h | 4 +++- Riot/Modules/Analytics/DecryptionFailureTracker.m | 9 +++++---- Riot/Utils/EventFormatter.m | 4 +++- bwi/MatomoAnalytics/BWIAnalytics.swift | 7 +++---- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Riot/Modules/Analytics/DecryptionFailure.swift b/Riot/Modules/Analytics/DecryptionFailure.swift index bbb26fc4f..670161123 100644 --- a/Riot/Modules/Analytics/DecryptionFailure.swift +++ b/Riot/Modules/Analytics/DecryptionFailure.swift @@ -45,11 +45,14 @@ import AnalyticsEvents let context: String // bwi: tracking information let errorCode: NSInteger - - init(failedEventId: String, reason: DecryptionFailureReason, context: String, errorCode: NSInteger) { + // bwi: #4821 RoomDevicesCount + let deviceCount: NSInteger + + init(failedEventId: String, reason: DecryptionFailureReason, context: String, errorCode: NSInteger, deviceCount: NSInteger) { self.failedEventId = failedEventId self.reason = reason self.context = context self.errorCode = errorCode + self.deviceCount = deviceCount } } diff --git a/Riot/Modules/Analytics/DecryptionFailureTracker.h b/Riot/Modules/Analytics/DecryptionFailureTracker.h index b8f9ca467..14bb14628 100644 --- a/Riot/Modules/Analytics/DecryptionFailureTracker.h +++ b/Riot/Modules/Analytics/DecryptionFailureTracker.h @@ -20,6 +20,7 @@ @class Analytics; @import MatrixSDK; +@class BWIAnalyticsHelper; @interface DecryptionFailureTracker : NSObject @@ -44,8 +45,9 @@ @param event the event. @param roomState the room state when the event was received. @param userId my user id. + @param deviceCount room device count. */ -- (void)reportUnableToDecryptErrorForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState myUser:(NSString*)userId; +- (void)reportUnableToDecryptErrorForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState myUser:(NSString*)userId roomDeviceCount:(NSInteger)deviceCount; /** Flush current data. diff --git a/Riot/Modules/Analytics/DecryptionFailureTracker.m b/Riot/Modules/Analytics/DecryptionFailureTracker.m index f66a61006..44fd2966c 100644 --- a/Riot/Modules/Analytics/DecryptionFailureTracker.m +++ b/Riot/Modules/Analytics/DecryptionFailureTracker.m @@ -77,7 +77,7 @@ NSString *const kDecryptionFailureTrackerAnalyticsCategory = @"e2e.failure"; return self; } -- (void)reportUnableToDecryptErrorForEvent:(MXEvent *)event withRoomState:(MXRoomState *)roomState myUser:(NSString *)userId +- (void)reportUnableToDecryptErrorForEvent:(MXEvent *)event withRoomState:(MXRoomState *)roomState myUser:(NSString *)userId roomDeviceCount:(NSInteger)deviceCount { if (reportedFailures[event.eventId] || [trackedEvents containsObject:event.eventId]) { @@ -117,7 +117,8 @@ NSString *const kDecryptionFailureTrackerAnalyticsCategory = @"e2e.failure"; reportedFailures[event.eventId] = [[DecryptionFailure alloc] initWithFailedEventId:failedEventId reason:reason context:context - errorCode:event.decryptionError.code]; + errorCode:event.decryptionError.code + deviceCount:deviceCount]; } - (void)dispatch @@ -158,8 +159,8 @@ NSString *const kDecryptionFailureTrackerAnalyticsCategory = @"e2e.failure"; NSMutableDictionary *failuresCounts = [NSMutableDictionary dictionary]; for (DecryptionFailure *failure in failuresToTrack) { - if ( failure.reason == DecryptionFailureReasonUnspecified) { - [BWIAnalytics.sharedTracker trackE2EEError:failure.errorCode]; + if (failure.reason == DecryptionFailureReasonUnspecified) { + [BWIAnalytics.sharedTracker trackE2EEErrorWithDimension:failure.errorCode deviceCount:[BWIAnalyticsHelper dimensionForDeviceCount: failure.deviceCount]]; } else { failuresCounts[@(failure.reason)] = @(failuresCounts[@(failure.reason)].unsignedIntegerValue + 1); } diff --git a/Riot/Utils/EventFormatter.m b/Riot/Utils/EventFormatter.m index a16a2857e..53a7da9d4 100644 --- a/Riot/Utils/EventFormatter.m +++ b/Riot/Utils/EventFormatter.m @@ -341,7 +341,9 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm"; { // Track e2e failures dispatch_async(dispatch_get_main_queue(), ^{ - [[DecryptionFailureTracker sharedInstance] reportUnableToDecryptErrorForEvent:event withRoomState:roomState myUser:self->mxSession.myUser.userId]; + [BWIAnalyticsHelper getRoomDeviceCountWithRoom:[self->mxSession roomWithRoomId:roomState.roomId] completion:^(NSInteger deviceCount) { + [[DecryptionFailureTracker sharedInstance] reportUnableToDecryptErrorForEvent:event withRoomState:roomState myUser:self->mxSession.myUser.userId roomDeviceCount:deviceCount]; + }]; }); if (event.decryptionError.code == MXDecryptingErrorUnknownInboundSessionIdCode) diff --git a/bwi/MatomoAnalytics/BWIAnalytics.swift b/bwi/MatomoAnalytics/BWIAnalytics.swift index a4b43efd6..ff63dd296 100644 --- a/bwi/MatomoAnalytics/BWIAnalytics.swift +++ b/bwi/MatomoAnalytics/BWIAnalytics.swift @@ -274,13 +274,12 @@ extension BWIAnalytics : MXAnalyticsDelegate { // dont track NV specific logs } - func trackE2EEError(_ errorCode: Int) { + func trackE2EEErrorWithDimension(_ errorCode: Int, deviceCount: String) { if let errorCode = AnalyticsE2EEErrorCode(rawValue: errorCode) { - self.trackBwiValue(NSNumber(value: 1), "Encryption", "ViewMessage", errorCode.description) + self.trackEventWithDimension(category: "Encryption", action: "ViewMessage", dimension: deviceCount, value: NSNumber(value: 1), name: errorCode.description) } else { - self.trackBwiValue(NSNumber(value: 1), "Encryption", "ViewMessage", "Unknown_Error") + self.trackEventWithDimension(category: "Encryption", action: "ViewMessage", dimension: deviceCount, value: NSNumber(value: 1), name: "Unknown_Error") } - } func trackE2EEErrors(_ reason: DecryptionFailureReason, count: Int) { From 517acba072ed1d1f00e6d80ecca529663e3c5f16 Mon Sep 17 00:00:00 2001 From: JanNiklas Grabowski Date: Wed, 11 Oct 2023 15:26:28 +0200 Subject: [PATCH 2/2] MESSENGER-4821 add missing file to target --- RiotNSE/target.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/RiotNSE/target.yml b/RiotNSE/target.yml index f016d3686..d58ecab24 100644 --- a/RiotNSE/target.yml +++ b/RiotNSE/target.yml @@ -51,6 +51,7 @@ targets: - path: ../bwi/NotificationTimes/NotificationTimesWeekday.swift - path: ../bwi/NotificationTimes/Date+fromHourMinute.swift - path: ../bwi/MatomoAnalytics/BWIAnalytics.swift + - path: ../bwi/MatomoAnalytics/BWIAnalyticsHelper.swift - path: ../bwi/MatomoAnalytics/BWIAnalyticsAccountDataService.swift - path: ../bwi/MatomoAnalytics/AnalyticsConfiguration.swift - path: ../bwi/MatomoAnalytics/E2EEError.swift