diff --git a/Experiments/Experiments/ABTest.swift b/Experiments/Experiments/ABTest.swift index 9dc3d0f0c55..15cd6179c36 100644 --- a/Experiments/Experiments/ABTest.swift +++ b/Experiments/Experiments/ABTest.swift @@ -45,19 +45,15 @@ public extension ABTest { @MainActor static func start(for context: ExperimentContext) async { let experiments = ABTest.allCases.filter { $0.context == context } + await start(experiments: experiments) + } - await withCheckedContinuation { continuation in - guard !experiments.isEmpty else { - return continuation.resume(returning: ()) - } - - let experimentNames = experiments.map { $0.rawValue } - ExPlat.shared?.register(experiments: experimentNames) - - ExPlat.shared?.refresh { - continuation.resume(returning: ()) - } - } as Void + /// Start the AB Testing platform for all experiments + /// + @MainActor + static func start() async { + let experiments = ABTest.allCases + await start(experiments: experiments) } } @@ -82,3 +78,23 @@ public enum ExperimentContext: Equatable { case loggedIn case none // For the `null` experiment case } + +private extension ABTest { + /// Start the AB Testing platform using the given `experiments` + /// + @MainActor + static func start(experiments: [ABTest]) async { + await withCheckedContinuation { continuation in + guard !experiments.isEmpty else { + return continuation.resume(returning: ()) + } + + let experimentNames = experiments.map { $0.rawValue } + ExPlat.shared?.register(experiments: experimentNames) + + ExPlat.shared?.refresh { + continuation.resume(returning: ()) + } + } as Void + } +} diff --git a/WooCommerce/Classes/Analytics/WooAnalytics.swift b/WooCommerce/Classes/Analytics/WooAnalytics.swift index 2523201a6df..fd05c379a33 100644 --- a/WooCommerce/Classes/Analytics/WooAnalytics.swift +++ b/WooCommerce/Classes/Analytics/WooAnalytics.swift @@ -65,10 +65,8 @@ public extension WooAnalytics { // Refreshes A/B experiments since `ExPlat.shared` is reset after each `TracksProvider.refreshUserData` call // and any A/B test assignments that come back after the shared instance is reset won't be saved for later // access. - let context: ExperimentContext = ServiceLocator.stores.isAuthenticated ? - .loggedIn: .loggedOut - Task { @MainActor in - await ABTest.start(for: context) + Task { + await ABTest.start() } }