Skip to content

Commit

Permalink
updated analytics and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Mar 14, 2024
1 parent fb4fa52 commit f9ad5bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7124,7 +7124,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-analytics-events";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.11.0;
minimumVersion = 0.14.0;
};
};
C13F55E4518415CB4C278E73 /* XCRemoteSwiftPackageReference "DTCoreText" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-analytics-events",
"state" : {
"revision" : "354562b5cabf2b9aec6cbb12e3a614490b3cc6e8",
"version" : "0.11.0"
"revision" : "f756bf0756b7349a1d3ccee0d038790d1ab2ec56",
"version" : "0.14.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,18 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
userSession.clientProxy.actionsPublisher
.receive(on: DispatchQueue.main)
.sink { action in
guard case .receivedDecryptionError = action else {
guard case let .receivedDecryptionError(info) = action else {
return
}

analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError)
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)
}
Expand Down
11 changes: 9 additions & 2 deletions ElementX/Sources/Services/Analytics/AnalyticsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,15 @@ extension AnalyticsService {
capture(event: AnalyticsEvent.Interaction(index: index, interactionType: .Touch, name: name))
}

func trackError(context: String?, domain: AnalyticsEvent.Error.Domain, name: AnalyticsEvent.Error.Name) {
capture(event: AnalyticsEvent.Error(context: context, cryptoModule: .Rust, domain: domain, 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
Expand Down
6 changes: 3 additions & 3 deletions UnitTests/Sources/LoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ class LoggingTests: XCTestCase {
formatted: FormattedBody(format: .html, body: "<b>\(emoteString)</b>"))

let pointer = Unmanaged.passRetained(NSURL(fileURLWithPath: "/tmp/file")).toOpaque()
let rustImageMessage = ImageMessageContent(body: "ImageString", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustVideoMessage = VideoMessageContent(body: "VideoString", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustFileMessage = FileMessageContent(body: "FileString", filename: "FileName", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustImageMessage = ImageMessageContent(body: "ImageString", formatted: nil, filename: nil, source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustVideoMessage = VideoMessageContent(body: "VideoString", formatted: nil, filename: nil, source: MediaSource(unsafeFromRawPointer: pointer), info: nil)
let rustFileMessage = FileMessageContent(body: "FileString", formatted: nil, filename: "FileName", source: MediaSource(unsafeFromRawPointer: pointer), info: nil)

// When logging that value
MXLog.info(rustTextMessage)
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ packages:
# path: ../compound-ios
AnalyticsEvents:
url: https://github.com/matrix-org/matrix-analytics-events
minorVersion: 0.11.0
minorVersion: 0.14.0
Emojibase:
url: https://github.com/matrix-org/emojibase-bindings
minorVersion: 1.0.0
Expand Down

0 comments on commit f9ad5bd

Please sign in to comment.