diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index ad1cdae231..670bdf5b9c 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -295,7 +295,8 @@ class AppCoordinator: AppCoordinatorProtocol { tearDownUserSession() // reset analytics - ServiceLocator.shared.analytics.reset() + ServiceLocator.shared.analytics.optOut() + ServiceLocator.shared.analytics.resetConsentState() stateMachine.processEvent(.completedSigningOut(isSoft: isSoft)) } diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 64d91b9201..b362613fb2 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -23,7 +23,7 @@ final class AppSettings: ObservableObject { case lastVersionLaunched case seenInvites case timelineStyle - case enableAnalytics + case analyticsConsentState case enableInAppNotifications case pusherProfileTag case shouldCollapseRoomStateEvents @@ -109,7 +109,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. @@ -125,16 +125,11 @@ final class AppSettings: ObservableObject { apiKey: "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO", termsURL: URL(staticString: "https://element.io/cookie-policy")) #endif - - /// Whether the user has already been shown the PostHog analytics prompt. - var hasSeenAnalyticsPrompt: Bool { - Self.store.object(forKey: UserDefaultsKeys.enableAnalytics.rawValue) != nil - } - - /// `true` when the user has opted in to send analytics. - @UserPreference(key: UserDefaultsKeys.enableAnalytics, defaultValue: false, storageType: .userDefaults(store)) - var enableAnalytics + /// Whether the user has opted in to send analytics. + @UserPreference(key: UserDefaultsKeys.analyticsConsentState, defaultValue: AnalyticsConsentState.unknown, storageType: .userDefaults(store)) + var analyticsConsentState + // MARK: - Room Screen @UserPreference(key: UserDefaultsKeys.timelineStyle, defaultValue: TimelineStyle.bubbles, storageType: .userDefaults(store)) @@ -145,7 +140,7 @@ final class AppSettings: ObservableObject { // MARK: - Notifications - @UserPreference(key: UserDefaultsKeys.timelineStyle, defaultValue: true, storageType: .userDefaults(store)) + @UserPreference(key: UserDefaultsKeys.enableInAppNotifications, defaultValue: true, storageType: .userDefaults(store)) var enableInAppNotifications /// Tag describing which set of device specific rules a pusher executes. diff --git a/ElementX/Sources/Screens/AnalyticsSettings/AnalyticsSettingsScreenViewModel.swift b/ElementX/Sources/Screens/AnalyticsSettings/AnalyticsSettingsScreenViewModel.swift index d1a933ede5..c0c3f056b3 100644 --- a/ElementX/Sources/Screens/AnalyticsSettings/AnalyticsSettingsScreenViewModel.swift +++ b/ElementX/Sources/Screens/AnalyticsSettings/AnalyticsSettingsScreenViewModel.swift @@ -22,12 +22,13 @@ typealias AnalyticsSettingsScreenViewModelType = StateStoreViewModel