Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions Experiments/Experiments/ABTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
}
}
6 changes: 2 additions & 4 deletions WooCommerce/Classes/Analytics/WooAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down