mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Set up Analytics to track data per session (#780)
This commit is contained in:
@@ -42,7 +42,6 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
private var userSessionFlowCoordinator: UserSessionFlowCoordinator?
|
||||
private var authenticationCoordinator: AuthenticationCoordinator?
|
||||
|
||||
private let bugReportService: BugReportServiceProtocol
|
||||
private let backgroundTaskService: BackgroundTaskServiceProtocol
|
||||
|
||||
private var userSessionCancellables = Set<AnyCancellable>()
|
||||
@@ -56,11 +55,11 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
|
||||
Self.setupServiceLocator(navigationRootCoordinator: navigationRootCoordinator)
|
||||
Self.setupLogging()
|
||||
|
||||
stateMachine = AppCoordinatorStateMachine()
|
||||
|
||||
bugReportService = BugReportService(withBaseURL: ServiceLocator.shared.settings.bugReportServiceBaseURL, sentryURL: ServiceLocator.shared.settings.bugReportSentryURL)
|
||||
|
||||
ServiceLocator.shared.analytics.startIfEnabled()
|
||||
|
||||
stateMachine = AppCoordinatorStateMachine()
|
||||
|
||||
navigationRootCoordinator.setRootCoordinator(SplashScreenCoordinator())
|
||||
|
||||
backgroundTaskService = UIKitBackgroundTaskService {
|
||||
@@ -84,7 +83,7 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
wipeUserData(includingSettings: true)
|
||||
}
|
||||
ServiceLocator.shared.settings.lastVersionLaunched = currentVersion.description
|
||||
|
||||
|
||||
setupStateMachine()
|
||||
|
||||
observeApplicationState()
|
||||
@@ -114,6 +113,9 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
ServiceLocator.shared.register(userIndicatorController: UserIndicatorController(rootCoordinator: navigationRootCoordinator))
|
||||
ServiceLocator.shared.register(appSettings: AppSettings())
|
||||
ServiceLocator.shared.register(networkMonitor: NetworkMonitor())
|
||||
ServiceLocator.shared.register(bugReportService: BugReportService(withBaseURL: ServiceLocator.shared.settings.bugReportServiceBaseURL,
|
||||
sentryURL: ServiceLocator.shared.settings.bugReportSentryURL))
|
||||
ServiceLocator.shared.register(analytics: Analytics(client: PostHogAnalyticsClient()))
|
||||
}
|
||||
|
||||
private static func setupLogging() {
|
||||
@@ -248,7 +250,7 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
let navigationSplitCoordinator = NavigationSplitCoordinator(placeholderCoordinator: SplashScreenCoordinator())
|
||||
let userSessionFlowCoordinator = UserSessionFlowCoordinator(userSession: userSession,
|
||||
navigationSplitCoordinator: navigationSplitCoordinator,
|
||||
bugReportService: bugReportService,
|
||||
bugReportService: ServiceLocator.shared.bugReportService,
|
||||
roomTimelineControllerFactory: RoomTimelineControllerFactory())
|
||||
|
||||
userSessionFlowCoordinator.callback = { [weak self] action in
|
||||
@@ -292,6 +294,9 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
userSessionStore.logout(userSession: userSession)
|
||||
tearDownUserSession()
|
||||
|
||||
// reset analytics
|
||||
ServiceLocator.shared.analytics.reset()
|
||||
|
||||
stateMachine.processEvent(.completedSigningOut(isSoft: isSoft))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ class AppCoordinatorStateMachine {
|
||||
private func configure() {
|
||||
stateMachine.addRoutes(event: .startWithAuthentication, transitions: [.initial => .signedOut])
|
||||
stateMachine.addRoutes(event: .createdUserSession, transitions: [.signedOut => .signedIn])
|
||||
|
||||
stateMachine.addRoutes(event: .startWithExistingSession, transitions: [.initial => .restoringSession])
|
||||
stateMachine.addRoutes(event: .createdUserSession, transitions: [.restoringSession => .signedIn])
|
||||
stateMachine.addRoutes(event: .failedRestoringSession, transitions: [.restoringSession => .signedOut])
|
||||
|
||||
@@ -23,7 +23,6 @@ final class AppSettings: ObservableObject {
|
||||
case lastVersionLaunched
|
||||
case timelineStyle
|
||||
case enableAnalytics
|
||||
case isIdentifiedForAnalytics
|
||||
case enableInAppNotifications
|
||||
case pusherProfileTag
|
||||
case shouldCollapseRoomStateEvents
|
||||
@@ -104,7 +103,7 @@ final class AppSettings: ObservableObject {
|
||||
let bugReportUISIId = "element-auto-uisi"
|
||||
|
||||
// MARK: - Analytics
|
||||
|
||||
|
||||
#if DEBUG
|
||||
/// The configuration to use for analytics during development. Set `isEnabled` to false to disable analytics in debug builds.
|
||||
/// **Note:** Analytics are disabled by default for forks. If you are maintaining a fork, set custom configurations.
|
||||
@@ -129,13 +128,7 @@ final class AppSettings: ObservableObject {
|
||||
/// `true` when the user has opted in to send analytics.
|
||||
@UserSetting(key: UserDefaultsKeys.enableAnalytics.rawValue, defaultValue: false, persistIn: store)
|
||||
var enableAnalytics
|
||||
|
||||
/// Indicates if the device has already called identify for this session to PostHog.
|
||||
/// This is separate to `enableAnalytics` as logging out leaves analytics
|
||||
/// enabled, but requires the next account to be identified separately.
|
||||
@UserSetting(key: UserDefaultsKeys.isIdentifiedForAnalytics.rawValue, defaultValue: false, persistIn: store)
|
||||
var isIdentifiedForAnalytics
|
||||
|
||||
|
||||
// MARK: - Room Screen
|
||||
|
||||
@UserSettingRawRepresentable(key: UserDefaultsKeys.timelineStyle.rawValue, defaultValue: TimelineStyle.bubbles, persistIn: store)
|
||||
|
||||
@@ -38,4 +38,16 @@ class ServiceLocator {
|
||||
func register(networkMonitor: NetworkMonitor) {
|
||||
self.networkMonitor = networkMonitor
|
||||
}
|
||||
|
||||
private(set) var analytics: Analytics!
|
||||
|
||||
func register(analytics: Analytics) {
|
||||
self.analytics = analytics
|
||||
}
|
||||
|
||||
private(set) var bugReportService: BugReportServiceProtocol!
|
||||
|
||||
func register(bugReportService: BugReportServiceProtocol) {
|
||||
self.bugReportService = bugReportService
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user