Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Layout: Add usage measures #6619

Merged
merged 5 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Riot/Managers/UserSessions/UserSessionProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UserSessionProperties: NSObject {
// MARK: - Constants
private enum Constants {
static let useCaseKey = "useCase"
static let activeFilterKey = "activeFilter"
}

// MARK: - Properties
Expand Down Expand Up @@ -64,6 +65,25 @@ class UserSessionProperties: NSObject {
case skipped
}

/// The active filter in the All Chats screen.
var allChatsActiveFilter: AllChatsActiveFilter? {
get {
guard let rawValue = dictionary[Constants.activeFilterKey] as? String else { return nil }
return AllChatsActiveFilter(rawValue: rawValue)
} set {
dictionary[Constants.activeFilterKey] = newValue?.rawValue
}
}

/// Represents the active filter in the All Chats screen.
/// Note: The raw string value is used for storage.
public enum AllChatsActiveFilter: String {
case all
case favourites
case people
case unreads
}

// MARK: - Setup

/// Create new properties for the specified user ID.
Expand Down
5 changes: 3 additions & 2 deletions Riot/Modules/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ 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, numFavouriteRooms: Int? = nil, numSpaces: Int? = nil) {
func updateUserProperties(ftueUseCase: UserSessionProperties.UseCase? = nil, numFavouriteRooms: Int? = nil, numSpaces: Int? = nil, allChatsActiveFilter: UserSessionProperties.AllChatsActiveFilter? = nil) {
let userProperties = AnalyticsEvent.UserProperties(ftueUseCaseSelection: ftueUseCase?.analyticsName,
numFavouriteRooms: numFavouriteRooms,
numSpaces: numSpaces)
numSpaces: numSpaces,
allChatsActiveFilter: allChatsActiveFilter?.analyticsName)
client.updateUserProperties(userProperties)
}

Expand Down
11 changes: 10 additions & 1 deletion Riot/Modules/Analytics/AnalyticsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ import AnalyticsEvents
case spaceMembers
case spaceExploreRooms
case dialpad

case spaceBottomSheet
case invites
case createSpace

/// The screen name reported to the AnalyticsEvent.
var screenName: AnalyticsEvent.MobileScreen.ScreenName {
switch self {
Expand Down Expand Up @@ -142,6 +145,12 @@ import AnalyticsEvents
return .SpaceExploreRooms
case .dialpad:
return .Dialpad
case .spaceBottomSheet:
return .SpaceBottomSheet
case .invites:
return .Invites
case .createSpace:
return .CreateSpace
}
}
}
32 changes: 31 additions & 1 deletion Riot/Modules/Analytics/AnalyticsUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ import AnalyticsEvents
case threadListFilterItem
case spacePanelSelectedSpace
case spacePanelSwitchSpace

case spacePanelSwitchSubSpace
case allChatsRecentsEnabled
case allChatsRecentsDisabled
case allChatsFiltersEnabled
case allChatsFiltersDisabled
case allChatsFilterAll
case allChatsFilterFavourites
case allChatsFilterUnreads
case allChatsFilterPeople
case spaceCreationValidated

/// The element name reported to the AnalyticsEvent.
var name: AnalyticsEvent.Interaction.Name {
switch self {
Expand All @@ -40,6 +50,26 @@ import AnalyticsEvents
return .SpacePanelSelectedSpace
case .spacePanelSwitchSpace:
return .SpacePanelSwitchSpace
case .spacePanelSwitchSubSpace:
return .SpacePanelSwitchSubSpace
case .allChatsRecentsEnabled:
return .MobileAllChatsRecentsEnabled
case .allChatsRecentsDisabled:
return .MobileAllChatsRecentsDisabled
case .allChatsFiltersEnabled:
return .MobileAllChatsFiltersEnabled
case .allChatsFiltersDisabled:
return .MobileAllChatsFiltersDisabled
case .allChatsFilterAll:
return .MobileAllChatsFilterAll
case .allChatsFilterFavourites:
return .MobileAllChatsFilterFavourites
case .allChatsFilterUnreads:
return .MobileAllChatsFilterUnreads
case .allChatsFilterPeople:
return .MobileAllChatsFilterPeople
case .spaceCreationValidated:
return .MobileSpaceCreationValidated
}
}
}
3 changes: 3 additions & 0 deletions Riot/Modules/Analytics/AnalyticsViewRoomTrigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import AnalyticsEvents
case linkShare
case exploreRooms
case spaceMembers
case spaceBottomSheet

var trigger: AnalyticsEvent.ViewRoom.Trigger? {
switch self {
Expand Down Expand Up @@ -99,6 +100,8 @@ import AnalyticsEvents
return .MobileExploreRooms
case .spaceMembers:
return .MobileSpaceMembers
case .spaceBottomSheet:
return .MobileSpaceBottomSheet
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// 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
import AnalyticsEvents

extension UserSessionProperties.AllChatsActiveFilter {
var analyticsName: AnalyticsEvent.UserProperties.AllChatsActiveFilter {
switch self {
case .all:
return .All
case .unreads:
return .Unreads
case .favourites:
return .Favourites
case .people:
return .People
}
}
}
3 changes: 2 additions & 1 deletion Riot/Modules/Analytics/Helpers/UserProperties+Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import AnalyticsEvents
extension AnalyticsEvent.UserProperties {

// Initializer for Element. Strips all Web properties.
public init(ftueUseCaseSelection: FtueUseCaseSelection?, numFavouriteRooms: Int?, numSpaces: Int?) {
public init(ftueUseCaseSelection: FtueUseCaseSelection?, numFavouriteRooms: Int?, numSpaces: Int?, allChatsActiveFilter: AllChatsActiveFilter?) {
self.init(WebMetaSpaceFavouritesEnabled: nil,
WebMetaSpaceHomeAllRooms: nil,
WebMetaSpaceHomeEnabled: nil,
WebMetaSpaceOrphansEnabled: nil,
WebMetaSpacePeopleEnabled: nil,
allChatsActiveFilter: allChatsActiveFilter,
ftueUseCaseSelection: ftueUseCaseSelection,
numFavouriteRooms: numFavouriteRooms,
numSpaces: numSpaces)
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Analytics/PostHogAnalyticsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PostHogAnalyticsClient: AnalyticsClientProtocol {
// Merge the updated user properties with the existing ones
self.pendingUserProperties = AnalyticsEvent.UserProperties(ftueUseCaseSelection: userProperties.ftueUseCaseSelection ?? pendingUserProperties.ftueUseCaseSelection,
numFavouriteRooms: userProperties.numFavouriteRooms ?? pendingUserProperties.numFavouriteRooms,
numSpaces: userProperties.numSpaces ?? pendingUserProperties.numSpaces)
numSpaces: userProperties.numSpaces ?? pendingUserProperties.numSpaces, allChatsActiveFilter: userProperties.allChatsActiveFilter ?? pendingUserProperties.allChatsActiveFilter)
gileluard marked this conversation as resolved.
Show resolved Hide resolved
}

// MARK: - Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AllChatsActionProvider {
filters: settings.filters,
sorting: settings.sorting)
AllChatsLayoutSettingsManager.shared.allChatLayoutSettings = newSettings
Analytics.shared.trackInteraction(action.state == .on ? .allChatsRecentsDisabled : .allChatsRecentsEnabled)
}
}

Expand All @@ -62,6 +63,7 @@ class AllChatsActionProvider {
filters: action.state == .on ? [] : [.unreads, .favourites, .people],
sorting: settings.sorting)
AllChatsLayoutSettingsManager.shared.allChatLayoutSettings = newSettings
Analytics.shared.trackInteraction(action.state == .on ? .allChatsFiltersDisabled : .allChatsFiltersEnabled)
}
}

Expand Down
13 changes: 12 additions & 1 deletion Riot/Modules/Home/AllChats/AllChatsFilterOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ class AllChatsFilterOptions: NSObject {
AllChatsLayoutSettingsManager.shared.activeFilters = []
return
}


switch filter {
case .all:
Analytics.shared.trackInteraction(.allChatsFilterAll)
case .favourites:
Analytics.shared.trackInteraction(.allChatsFilterFavourites)
case .people:
Analytics.shared.trackInteraction(.allChatsFilterPeople)
case .unreads:
Analytics.shared.trackInteraction(.allChatsFilterUnreads)
default: break
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved
}
AllChatsLayoutSettingsManager.shared.activeFilters = filter
}

Expand Down
28 changes: 28 additions & 0 deletions Riot/Modules/Home/AllChats/AllChatsLayoutSettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ final class AllChatsLayoutSettingsManager: NSObject {
set {
RiotSettings.defaults.set(newValue.rawValue, forKey: Constants.activeFiltersKey)

track(activeFilters: newValue)

DispatchQueue.main.async {
NotificationCenter.default.post(name: AllChatsLayoutSettingsManager.didUpdateActiveFilters, object: self)
}
Expand All @@ -84,6 +86,12 @@ final class AllChatsLayoutSettingsManager: NSObject {
NotificationCenter.default.post(name: AllChatsLayoutSettingsManager.willUpdateSettings, object: self)
}

if newValue.filters.isEmpty {
track(activeFilters: nil)
} else {
track(activeFilters: activeFilters)
}

guard let data = try? NSKeyedArchiver.archivedData(withRootObject: newValue, requiringSecureCoding: false) else {
MXLog.warning("[AllChatsLayoutSettingsManager] set allChatLayoutSettings: failed to archive settings")
return
Expand All @@ -96,4 +104,24 @@ final class AllChatsLayoutSettingsManager: NSObject {
}
}
}

// MARK: - Private

private func track(activeFilters: AllChatsLayoutFilterType?) {
guard let activeFilters = activeFilters else {
Analytics.shared.updateUserProperties(allChatsActiveFilter: nil)
return
}

switch activeFilters {
case .unreads:
Analytics.shared.updateUserProperties(allChatsActiveFilter: .unreads)
case .favourites:
Analytics.shared.updateUserProperties(allChatsActiveFilter: .favourites)
case .people:
Analytics.shared.updateUserProperties(allChatsActiveFilter: .people)
default:
Analytics.shared.updateUserProperties(allChatsActiveFilter: .all)
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
1 change: 1 addition & 0 deletions Riot/Modules/Home/AllChats/AllChatsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class AllChatsViewController: HomeViewController {
// MARK: - Actions

@objc private func showSpaceSelectorAction(sender: AnyObject) {
Analytics.shared.viewRoomTrigger = .roomList
let currentSpaceId = self.dataSource.currentSpace?.spaceId ?? SpaceSelectorConstants.homeSpaceId
let spaceSelectorBridgePresenter = SpaceSelectorBottomSheetCoordinatorBridgePresenter(session: self.mainSession, selectedSpaceId: currentSpaceId, showHomeSpace: true)
spaceSelectorBridgePresenter.present(from: self, animated: true)
Expand Down
3 changes: 1 addition & 2 deletions Riot/Modules/Home/AllChats/RoomInvitesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class RoomInvitesViewController: RecentsViewController {
super.finalizeInit()

title = VectorL10n.roomRecentsInvitesSection.capitalized
// TODO: add right screen tracker
// self.screenTracker = AnalyticsScreenTracker(screen: .rooms)
self.screenTracker = AnalyticsScreenTracker(screen: .invites)
tableViewPaginationThrottler = MXThrottler(minimumDelay: 0.1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ final class SpaceCreationCoordinator: Coordinator {
func start() {
MXLog.debug("[SpaceCreationCoordinator] did start.")

Analytics.shared.trackScreen(.createSpace)

let rootCoordinator = self.createMenuCoordinator(with: spaceVisibilityMenuParameters)
rootCoordinator.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ final class SpaceSelectorBottomSheetCoordinator: NSObject, Coordinator, Presenta
// MARK: - Public

func start() {
Analytics.shared.trackScreen(.spaceBottomSheet)
push(createSpaceSelectorCoordinator(parentSpaceId: nil))
}

Expand Down Expand Up @@ -135,6 +136,7 @@ final class SpaceSelectorBottomSheetCoordinator: NSObject, Coordinator, Presenta
self.push(self.createSpaceDetailCoordinator(forSpaceWithId: item.id))
}
case .spaceDisclosure(let item):
Analytics.shared.viewRoomTrigger = .spaceBottomSheet
self.push(self.createSpaceSelectorCoordinator(parentSpaceId: item.id))
case .createSpace(let parentSpaceId):
self.completion?(.createSpace(parentSpaceId))
Expand Down Expand Up @@ -181,7 +183,11 @@ final class SpaceSelectorBottomSheetCoordinator: NSObject, Coordinator, Presenta
return
}

Analytics.shared.trackInteraction(.spacePanelSwitchSpace)
if spaceIdStack.isEmpty {
Analytics.shared.trackInteraction(.spacePanelSwitchSpace)
} else {
Analytics.shared.trackInteraction(.spacePanelSwitchSubSpace)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ final class SpaceSelectorCoordinator: Coordinator, Presentable {
// MARK: - Public

func start() {
if let room = parameters.session.room(withRoomId: parameters.parentSpaceId) {
Analytics.shared.trackViewRoom(room)
}

MXLog.debug("[SpaceSelectorCoordinator] did start.")
viewModel.completion = { [weak self] result in
guard let self = self else { return }
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6618.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
App Layout: Added usage measures