From cd32454d5f539f3a5d36dc535079d8bce63c5467 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 1 Feb 2023 08:52:04 +0530 Subject: [PATCH 1/2] `ABTest` - Add a way to start all ABTest experiments. --- Experiments/Experiments/ABTest.swift | 40 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) 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 + } +} From c6320ab36d9ac31d0e061b0b25ef3c7886427227 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Wed, 1 Feb 2023 08:53:28 +0530 Subject: [PATCH 2/2] Restart ABTest for all experiments irrespective of the logged in/out context. --- WooCommerce/Classes/Analytics/WooAnalytics.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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() } }