Merge branch 'develop' into gil/5769_add_trigger_to_join_and_view_room_metrics_event

# Conflicts:
#	Riot/Modules/Analytics/Analytics.swift
This commit is contained in:
Gil Eluard
2022-03-17 13:59:24 +01:00
32 changed files with 422 additions and 139 deletions
+8 -3
View File
@@ -80,6 +80,11 @@ import AnalyticsEvents
updateViewRoomActiveSpace()
}
}
// MARK: - Private
/// keep an instance of `AnalyticsSpaceTracker` to track space metrics when space graph is built.
private let spaceTracker: AnalyticsSpaceTracker = AnalyticsSpaceTracker()
// MARK: - Public
@@ -209,10 +214,10 @@ extension Analytics {
/// Updates any user properties to help with creating cohorts.
///
/// Only non-nil properties will be updated when calling this method.
func updateUserProperties(ftueUseCase: UserSessionProperties.UseCase? = nil) {
func updateUserProperties(ftueUseCase: UserSessionProperties.UseCase? = nil, numFavouriteRooms: Int? = nil, numSpaces: Int? = nil) {
let userProperties = AnalyticsEvent.UserProperties(ftueUseCaseSelection: ftueUseCase?.analyticsName,
numFavouriteRooms: nil,
numSpaces: nil)
numFavouriteRooms: numFavouriteRooms,
numSpaces: numSpaces)
client.updateUserProperties(userProperties)
}
@@ -0,0 +1,47 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
class AnalyticsSpaceTracker {
// MARK: - Setup
init() {
NotificationCenter.default.addObserver(self, selector: #selector(self.spaceGraphDidUpdate(notification:)), name: MXSpaceService.didBuildSpaceGraph, object: nil)
}
@objc private func spaceGraphDidUpdate(notification: Notification) {
guard let spaceService = notification.object as? MXSpaceService else {
return
}
trackSpaceNumber(with: spaceService)
}
// MARK: - Private
private func trackSpaceNumber(with spaceService: MXSpaceService) {
let spaceNumber = spaceService.spaceSummaries.filter { $0.membership == .join }.count
guard RiotSettings.shared.lastNumberOfTrackedSpaces != spaceNumber else {
return
}
Analytics.shared.updateUserProperties(numSpaces: spaceNumber)
RiotSettings.shared.lastNumberOfTrackedSpaces = spaceNumber
}
}
@@ -22,6 +22,8 @@ import AnalyticsEvents
case roomThreadSummaryItem
case threadListThreadItem
case threadListFilterItem
case spacePanelSelectedSpace
case spacePanelSwitchSpace
/// The element name reported to the AnalyticsEvent.
var name: AnalyticsEvent.Interaction.Name {
@@ -34,6 +36,10 @@ import AnalyticsEvents
return .MobileThreadListThreadItem
case .threadListFilterItem:
return .MobileThreadListFilterItem
case .spacePanelSelectedSpace:
return .SpacePanelSelectedSpace
case .spacePanelSwitchSpace:
return .SpacePanelSwitchSpace
}
}
}