Skip to content

Commit

Permalink
Add analytics tracking for room creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Johennes committed Jun 19, 2023
1 parent 4de3920 commit 6ff816c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
userIDs: state.selectedUsers.map(\.userID),
avatarURL: avatarURL) {
case .success(let roomId):
ServiceLocator.shared.analytics.trackCreatedRoom(isDM: false)
actionsSubject.send(.openRoom(withIdentifier: roomId))
case .failure(let failure):
displayError(failure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct CreateRoomScreen: View {
securitySection
}
.elementFormStyle()
.track(screen: .createRoom)
.scrollDismissesKeyboard(.immediately)
.navigationTitle(L10n.screenCreateRoomTitle)
.navigationBarTitleDisplayMode(.inline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
showLoadingIndicator()
switch await clientProxy.createDirectRoom(with: user.userID, expectedRoomName: user.displayName) {
case .success(let roomId):
ServiceLocator.shared.analytics.trackCreatedRoom(isDM: true)
actionsSubject.send(.openRoom(withIdentifier: roomId))
case .failure(let failure):
displayError(failure)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct StartChatScreen: View {
}
}
.elementFormStyle()
.track(screen: .startChat)
.scrollDismissesKeyboard(.immediately)
.navigationTitle(L10n.actionStartChat)
.navigationBarTitleDisplayMode(.inline)
Expand Down
8 changes: 6 additions & 2 deletions ElementX/Sources/Services/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ class Analytics {
client.flush()
}

// MARK: - Private

/// Capture an event in the `client`.
/// - Parameter event: The event to capture.
private func capture(event: AnalyticsEventProtocol) {
Expand All @@ -125,4 +123,10 @@ extension Analytics {
let event = AnalyticsEvent.MobileScreen(durationMs: milliseconds, screenName: screen.screenName)
client.screen(event)
}

/// Track the creation of a room
/// - Parameter isDM: true if the created room is a direct message, false otherwise
func trackCreatedRoom(isDM: Bool) {
capture(event: AnalyticsEvent.CreatedRoom(isDM: isDM))
}
}
1 change: 1 addition & 0 deletions changelog.d/pr-1100.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add analytics tracking for room creation

0 comments on commit 6ff816c

Please sign in to comment.