Removed unused swipe gesture (+3 squashed commits)

Squashed commits:
[d64bb3bb] Stop using the ServiceLocator directly in the ScreenTrackerViewModifier
[37c46ab9] Rename Analytics to AnalyticsService
[8852a371] #920 - Cleanup ServiceLocator usages
This commit is contained in:
Stefan Ceriu
2023-06-23 09:56:22 +03:00
committed by Stefan Ceriu
parent b4cd58b209
commit e6711a0236
104 changed files with 720 additions and 366 deletions
@@ -22,7 +22,7 @@ protocol AnalyticsClientProtocol {
var isRunning: Bool { get }
/// Starts the analytics client reporting data.
func start()
func start(analyticsConfiguration: AnalyticsConfiguration)
/// Reset all stored properties and any event queues on the client. Note that
/// the client will remain active, but in a fresh unidentified state.
@@ -30,12 +30,16 @@ import PostHog
/// To add a new event create a PR to that repo with the new/updated schema. Once merged
/// into `main`, update the AnalyticsEvents Swift package in `project.yml`.
///
class Analytics {
class AnalyticsService {
/// The analytics client to send events with.
private let client: AnalyticsClientProtocol
private let appSettings: AppSettings
private let bugReportService: BugReportServiceProtocol
init(client: AnalyticsClientProtocol) {
init(client: AnalyticsClientProtocol, appSettings: AppSettings, bugReportService: BugReportServiceProtocol) {
self.client = client
self.appSettings = appSettings
self.bugReportService = bugReportService
}
/// Whether or not the object is enabled and sending events to the server.
@@ -44,27 +48,27 @@ class Analytics {
/// Whether to show the user the analytics opt in prompt.
var shouldShowAnalyticsPrompt: Bool {
// Only show the prompt once, and when analytics are enabled in BuildSettings.
ServiceLocator.shared.settings.analyticsConsentState == .unknown && ServiceLocator.shared.settings.analyticsConfiguration.isEnabled
appSettings.analyticsConsentState == .unknown && appSettings.analyticsConfiguration.isEnabled
}
var isEnabled: Bool {
ServiceLocator.shared.settings.analyticsConsentState == .optedIn
appSettings.analyticsConsentState == .optedIn
}
/// Opts in to analytics tracking with the supplied user session.
func optIn() {
ServiceLocator.shared.settings.analyticsConsentState = .optedIn
appSettings.analyticsConsentState = .optedIn
startIfEnabled()
}
/// Stops analytics tracking and calls `reset` to clear any IDs and event queues.
func optOut() {
ServiceLocator.shared.settings.analyticsConsentState = .optedOut
appSettings.analyticsConsentState = .optedOut
// The order is important here. PostHog ignores the reset if stopped.
reset()
client.stop()
ServiceLocator.shared.bugReportService.stop()
bugReportService.stop()
MXLog.info("Stopped.")
}
@@ -72,8 +76,8 @@ class Analytics {
func startIfEnabled() {
guard isEnabled, !isRunning else { return }
client.start()
ServiceLocator.shared.bugReportService.start()
client.start(analyticsConfiguration: appSettings.analyticsConfiguration)
bugReportService.start()
// Sanity check in case something went wrong.
guard client.isRunning else { return }
@@ -87,14 +91,14 @@ class Analytics {
/// Note: **MUST** be called before stopping PostHog or the reset is ignored.
func reset() {
client.reset()
ServiceLocator.shared.bugReportService.reset()
bugReportService.reset()
MXLog.info("Reset.")
}
/// Reset the consent state for analytics
func resetConsentState() {
MXLog.warning("Resetting consent state for analytics.")
ServiceLocator.shared.settings.analyticsConsentState = .unknown
appSettings.analyticsConsentState = .unknown
}
/// Flushes the event queue in the analytics client, uploading all pending events.
@@ -116,7 +120,7 @@ class Analytics {
// MARK: - Public tracking methods
extension Analytics {
extension AnalyticsService {
/// Track the presentation of a screen
/// - Parameter screen: The screen that was shown
/// - Parameter duration: An optional value representing how long the screen was shown for in milliseconds.
@@ -0,0 +1,28 @@
//
// Copyright 2023 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 SwiftUI
private struct AnalyticsServiceKey: EnvironmentKey {
static let defaultValue: AnalyticsService = ServiceLocator.shared.analytics
}
extension EnvironmentValues {
var analyticsService: AnalyticsService {
get { self[AnalyticsServiceKey.self] }
set { self[AnalyticsServiceKey.self] = newValue }
}
}
@@ -17,8 +17,7 @@
import PostHog
extension PHGPostHogConfiguration {
static var standard: PHGPostHogConfiguration? {
let analyticsConfiguration = ServiceLocator.shared.settings.analyticsConfiguration
static func standard(analyticsConfiguration: AnalyticsConfiguration) -> PHGPostHogConfiguration? {
guard analyticsConfiguration.isEnabled else { return nil }
let postHogConfiguration = PHGPostHogConfiguration(apiKey: analyticsConfiguration.apiKey, host: analyticsConfiguration.host)
@@ -27,9 +27,9 @@ class PostHogAnalyticsClient: AnalyticsClientProtocol {
var isRunning: Bool { postHog?.enabled ?? false }
func start() {
func start(analyticsConfiguration: AnalyticsConfiguration) {
// Only start if analytics have been configured in BuildSettings
guard let configuration = PHGPostHogConfiguration.standard else { return }
guard let configuration = PHGPostHogConfiguration.standard(analyticsConfiguration: analyticsConfiguration) else { return }
if postHog == nil {
postHog = PHGPostHog(configuration: configuration)