mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-23 18:12:44 +02:00
merged element 1.8.10
This commit is contained in:
@@ -46,13 +46,15 @@ import AnalyticsEvents
|
||||
/// The service used to interact with account data settings.
|
||||
private var service: AnalyticsService?
|
||||
|
||||
private var viewRoomActiveSpace: AnalyticsViewRoomActiveSpace = .home
|
||||
|
||||
/// Whether or not the object is enabled and sending events to the server.
|
||||
var isRunning: Bool { client.isRunning }
|
||||
|
||||
/// Whether to show the user the analytics opt in prompt.
|
||||
var shouldShowAnalyticsPrompt: Bool {
|
||||
// Only show the prompt once, and when analytics are configured in BuildSettings.
|
||||
!RiotSettings.shared.hasSeenAnalyticsPrompt && PHGPostHogConfiguration.standard != nil
|
||||
// Only show the prompt once, and when analytics are enabled in BuildSettings.
|
||||
!RiotSettings.shared.hasSeenAnalyticsPrompt && BuildSettings.analyticsConfiguration.isEnabled
|
||||
}
|
||||
|
||||
/// Indicates whether the user previously accepted Matomo analytics and should be shown the upgrade prompt.
|
||||
@@ -60,6 +62,31 @@ import AnalyticsEvents
|
||||
RiotSettings.shared.hasAcceptedMatomoAnalytics
|
||||
}
|
||||
|
||||
/// Used to defined the trigger of the next potential `JoinedRoom` event
|
||||
var joinedRoomTrigger: AnalyticsJoinedRoomTrigger = .unknown
|
||||
|
||||
/// Used to defined the trigger of the next potential `ViewRoom` event
|
||||
var viewRoomTrigger: AnalyticsViewRoomTrigger = .unknown
|
||||
|
||||
/// Used to defined the actual space activated by the user.
|
||||
var activeSpace: MXSpace? {
|
||||
didSet {
|
||||
updateViewRoomActiveSpace()
|
||||
}
|
||||
}
|
||||
|
||||
/// Used to defined the currently visible space in explore rooms.
|
||||
var exploringSpace: MXSpace? {
|
||||
didSet {
|
||||
updateViewRoomActiveSpace()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
/// keep an instance of `AnalyticsSpaceTracker` to track space metrics when space graph is built.
|
||||
private let spaceTracker: AnalyticsSpaceTracker = AnalyticsSpaceTracker()
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
/// Opts in to analytics tracking with the supplied session.
|
||||
@@ -95,8 +122,13 @@ import AnalyticsEvents
|
||||
|
||||
MXLog.debug("[Analytics] Started.")
|
||||
|
||||
// Catch and log crashes
|
||||
MXLogger.logCrashes(true)
|
||||
if Bundle.main.isShareExtension {
|
||||
// Don't log crashes in the share extension
|
||||
} else {
|
||||
// Catch and log crashes
|
||||
MXLogger.logCrashes(true)
|
||||
}
|
||||
|
||||
MXLogger.setBuildVersion(AppInfo.current.buildInfo.readableBuildVersion)
|
||||
}
|
||||
|
||||
@@ -166,18 +198,41 @@ import AnalyticsEvents
|
||||
private func capture(event: AnalyticsEventProtocol) {
|
||||
client.capture(event)
|
||||
}
|
||||
|
||||
/// Update `viewRoomActiveSpace` property according to the current value of `exploringSpace` and `activeSpace` properties.
|
||||
private func updateViewRoomActiveSpace() {
|
||||
let space = exploringSpace ?? activeSpace
|
||||
guard let spaceRoom = space?.room else {
|
||||
viewRoomActiveSpace = .home
|
||||
return
|
||||
}
|
||||
|
||||
spaceRoom.state { roomState in
|
||||
self.viewRoomActiveSpace = roomState?.isJoinRulePublic == true ? .public : .private
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Public tracking methods
|
||||
// The following methods are exposed for compatibility with Objective-C as
|
||||
// the `capture` method and the generated events cannot be bridged from Swift.
|
||||
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) {
|
||||
let userProperties = AnalyticsEvent.UserProperties(ftueUseCaseSelection: ftueUseCase?.analyticsName,
|
||||
numFavouriteRooms: numFavouriteRooms,
|
||||
numSpaces: numSpaces)
|
||||
client.updateUserProperties(userProperties)
|
||||
}
|
||||
|
||||
/// Track the presentation of a screen
|
||||
/// - Parameters:
|
||||
/// - screen: The screen that was shown.
|
||||
/// - milliseconds: An optional value representing how long the screen was shown for in milliseconds.
|
||||
func trackScreen(_ screen: AnalyticsScreen, duration milliseconds: Int?) {
|
||||
let event = AnalyticsEvent.Screen(durationMs: milliseconds, screenName: screen.screenName)
|
||||
let event = AnalyticsEvent.MobileScreen(durationMs: milliseconds, screenName: screen.screenName)
|
||||
client.screen(event)
|
||||
}
|
||||
|
||||
@@ -187,19 +242,24 @@ extension Analytics {
|
||||
trackScreen(screen, duration: nil)
|
||||
}
|
||||
|
||||
/// Track an element that has been tapped
|
||||
/// Track an element that has been interacted with
|
||||
/// - Parameters:
|
||||
/// - tap: The element that was tapped
|
||||
/// - uiElement: The element that was interacted with
|
||||
/// - interactionType: The way in with the element was interacted with
|
||||
/// - index: The index of the element, if it's in a list of elements
|
||||
func trackTap(_ tap: AnalyticsUIElement, index: Int?) {
|
||||
|
||||
}
|
||||
|
||||
func trackInteraction(_ uiElement: AnalyticsUIElement, interactionType: AnalyticsEvent.Interaction.InteractionType, index: Int?) {
|
||||
let event = AnalyticsEvent.Interaction(index: index, interactionType: interactionType, name: uiElement.name)
|
||||
client.capture(event)
|
||||
}
|
||||
|
||||
/// Track an element that has been tapped without including an index
|
||||
/// - Parameters:
|
||||
/// - tap: The element that was tapped
|
||||
func trackTap(_ tap: AnalyticsUIElement) {
|
||||
trackTap(tap, index: nil)
|
||||
/// - uiElement: The element that was tapped
|
||||
func trackInteraction(_ uiElement: AnalyticsUIElement) {
|
||||
trackInteraction(uiElement, interactionType: .Touch, index: nil)
|
||||
}
|
||||
|
||||
/// Track an E2EE error that occurred
|
||||
@@ -231,6 +291,27 @@ extension Analytics {
|
||||
func trackIdentityServerAccepted(_ accepted: Bool) {
|
||||
// Do we still want to track this?
|
||||
}
|
||||
|
||||
/// Track view room event triggered when the user changes rooms.
|
||||
/// - Parameters:
|
||||
/// - room: the room being viewed
|
||||
func trackViewRoom(_ room: MXRoom) {
|
||||
trackViewRoom(asDM: room.isDirect, isSpace: room.summary?.roomType == .space)
|
||||
}
|
||||
|
||||
/// Track view room event triggered when the user changes rooms.
|
||||
/// - Parameters:
|
||||
/// - isDM: Whether the room is a DM.
|
||||
/// - isSpace: Whether the room is a Space.
|
||||
func trackViewRoom(asDM isDM: Bool, isSpace: Bool) {
|
||||
let event = AnalyticsEvent.ViewRoom(activeSpace: viewRoomActiveSpace.space,
|
||||
isDM: isDM,
|
||||
isSpace: isSpace,
|
||||
trigger: viewRoomTrigger.trigger,
|
||||
viaKeyboard: nil)
|
||||
viewRoomTrigger = .unknown
|
||||
capture(event: event)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - MXAnalyticsDelegate
|
||||
@@ -267,18 +348,29 @@ extension Analytics: MXAnalyticsDelegate {
|
||||
capture(event: event)
|
||||
}
|
||||
|
||||
func trackJoinedRoom(asDM isDM: Bool, memberCount: UInt) {
|
||||
func trackJoinedRoom(asDM isDM: Bool, isSpace: Bool, memberCount: UInt) {
|
||||
guard let roomSize = AnalyticsEvent.JoinedRoom.RoomSize(memberCount: memberCount) else {
|
||||
MXLog.warning("[Analytics] Attempt to capture joined room with invalid member count: \(memberCount)")
|
||||
return
|
||||
}
|
||||
|
||||
let event = AnalyticsEvent.JoinedRoom(isDM: isDM, roomSize: roomSize)
|
||||
let event = AnalyticsEvent.JoinedRoom(isDM: isDM, isSpace: isSpace, roomSize: roomSize, trigger: joinedRoomTrigger.trigger)
|
||||
capture(event: event)
|
||||
|
||||
self.joinedRoomTrigger = .unknown
|
||||
}
|
||||
|
||||
/// **Note** This method isn't currently implemented.
|
||||
func trackContactsAccessGranted(_ granted: Bool) {
|
||||
// Do we still want to track this?
|
||||
}
|
||||
|
||||
func trackComposerEvent(inThread: Bool, isEditing: Bool, isReply: Bool, startsThread: Bool) {
|
||||
let event = AnalyticsEvent.Composer(inThread: inThread,
|
||||
isEditing: isEditing,
|
||||
isReply: isReply,
|
||||
startsThread: startsThread)
|
||||
capture(event: event)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user