Skip to content

Commit

Permalink
added analytics for message pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Sep 16, 2024
1 parent 6efbf61 commit beeef85
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7775,7 +7775,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-analytics-events";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.23.1;
minimumVersion = 0.25.0;
};
};
C13F55E4518415CB4C278E73 /* XCRemoteSwiftPackageReference "DTCoreText" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-analytics-events",
"state" : {
"revision" : "de0cac487e5e7f607ee17045882204c91585461f",
"version" : "0.23.1"
"revision" : "c9b40120a5f7b8ce1bab3f09f8417fdc9407f006",
"version" : "0.25.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class PinnedEventsTimelineScreenCoordinator: CoordinatorProtocol {
init(parameters: PinnedEventsTimelineScreenCoordinatorParameters) {
self.parameters = parameters

viewModel = PinnedEventsTimelineScreenViewModel()
viewModel = PinnedEventsTimelineScreenViewModel(analyticsService: ServiceLocator.shared.analytics)
timelineViewModel = TimelineViewModel(roomProxy: parameters.roomProxy,
timelineController: parameters.timelineController,
mediaProvider: parameters.mediaProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import SwiftUI
typealias PinnedEventsTimelineScreenViewModelType = StateStoreViewModel<PinnedEventsTimelineScreenViewState, PinnedEventsTimelineScreenViewAction>

class PinnedEventsTimelineScreenViewModel: PinnedEventsTimelineScreenViewModelType, PinnedEventsTimelineScreenViewModelProtocol {
private let analyticsService: AnalyticsService

private let actionsSubject: PassthroughSubject<PinnedEventsTimelineScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<PinnedEventsTimelineScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}

init() {
init(analyticsService: AnalyticsService) {
self.analyticsService = analyticsService
super.init(initialViewState: PinnedEventsTimelineScreenViewState())
}

Expand All @@ -27,6 +30,7 @@ class PinnedEventsTimelineScreenViewModel: PinnedEventsTimelineScreenViewModelTy

switch viewAction {
case .close:
analyticsService.trackInteraction(name: .PinnedMessageBannerCloseListButton)
actionsSubject.send(.dismiss)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct PinnedEventsTimelineScreen: View {
// MARK: - Previews

struct PinnedEventsTimelineScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = PinnedEventsTimelineScreenViewModel()
static let viewModel = PinnedEventsTimelineScreenViewModel(analyticsService: ServiceLocator.shared.analytics)
static let emptyTimelineViewModel: TimelineViewModel = {
let timelineController = MockRoomTimelineController(timelineKind: .pinned)
timelineController.timelineItems = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
case .processTapCall:
actionsSubject.send(.startCall)
case .processTapPinnedEvents:
analyticsService.trackInteraction(name: .PinnedMessageRoomInfoButton)
actionsSubject.send(.displayPinnedEventsTimeline)
}
}
Expand Down
2 changes: 2 additions & 0 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
override func process(viewAction: RoomScreenViewAction) {
switch viewAction {
case .tappedPinnedEventsBanner:
analyticsService.trackInteraction(name: .PinnedMessageBannerClick)
if let eventID = state.pinnedEventsBannerState.selectedPinnedEventID {
actionsSubject.send(.focusEvent(eventID: eventID))
}
state.pinnedEventsBannerState.previousPin()
case .viewAllPins:
analyticsService.trackInteraction(name: .PinnedMessageBannerViewAllButton)
actionsSubject.send(.displayPinnedEventsTimeline)
case .displayRoomDetails:
actionsSubject.send(.displayRoomDetails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,17 @@ class TimelineInteractionHandler {
case .endPoll(let pollStartID):
endPoll(pollStartID: pollStartID)
case .pin:
analyticsService.trackPinUnpinEvent(.init(from: timelineController.timelineKind == .pinned ? .MessagePinningList : .Timeline,
kind: .Pin))
guard let eventID = itemID.eventID else { return }
Task { await timelineController.pin(eventID: eventID) }
case .unpin:
analyticsService.trackPinUnpinEvent(.init(from: timelineController.timelineKind == .pinned ? .MessagePinningList : .Timeline,
kind: .Unpin))
guard let eventID = itemID.eventID else { return }
Task { await timelineController.unpin(eventID: eventID) }
case .viewInRoomTimeline:
analyticsService.trackInteraction(name: .PinnedMessageListViewTimeline)
guard let eventID = itemID.eventID else { return }
actionsSubject.send(.viewInRoomTimeline(eventID: eventID))
}
Expand Down
4 changes: 4 additions & 0 deletions ElementX/Sources/Services/Analytics/AnalyticsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,8 @@ extension AnalyticsService {
func updateUserProperties(_ userProperties: AnalyticsEvent.UserProperties) {
client.updateUserProperties(userProperties)
}

func trackPinUnpinEvent(_ event: AnalyticsEvent.PinUnpinAction) {
capture(event: event)
}
}
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
# path: ../compound-ios
AnalyticsEvents:
url: https://github.com/matrix-org/matrix-analytics-events
minorVersion: 0.23.1
minorVersion: 0.25.0
# path: ../matrix-analytics-events
Emojibase:
url: https://github.com/matrix-org/emojibase-bindings
Expand Down

0 comments on commit beeef85

Please sign in to comment.