Skip to content

Commit 9305045

Browse files
committed
Merge branch 'trunk' into issue/7850-ios-15
2 parents db914ff + dfbdb2d commit 9305045

File tree

26 files changed

+325
-29
lines changed

26 files changed

+325
-29
lines changed

Experiments/Experiments/ABTest.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public enum ABTest: String, CaseIterable {
1010
/// A/A test for ExPlat integration in the logged in state.
1111
/// Experiment ref: pbxNRc-1QS-p2
1212
///
13-
case aaTest202209 = "woocommerceios_explat_aa_test_logged_in_202209"
13+
case aaTestLoggedIn202210 = "woocommerceios_explat_aa_test_logged_in_202210"
1414

1515
/// A/A test to make sure there is no bias in the logged out state.
1616
/// Experiment ref: pbxNRc-1S0-p2
@@ -24,18 +24,34 @@ public enum ABTest: String, CaseIterable {
2424
public var variation: Variation {
2525
ExPlat.shared?.experiment(rawValue) ?? .control
2626
}
27+
28+
/// Returns the context for the given experiment.
29+
///
30+
/// When adding a new experiment, add it to the appropriate case depending on its context (logged-in or logged-out experience).
31+
public var context: ExperimentContext {
32+
switch self {
33+
case .aaTestLoggedIn202210:
34+
return .loggedIn
35+
case .aaTestLoggedOut202209, .loginPrologueButtonOrder:
36+
return .loggedOut
37+
case .null:
38+
return .none
39+
}
40+
}
2741
}
2842

2943
public extension ABTest {
30-
/// Start the AB Testing platform if any experiment exists
44+
/// Start the AB Testing platform if any experiment exists for the provided context
3145
///
32-
static func start() async {
46+
static func start(for context: ExperimentContext) async {
47+
let experiments = ABTest.allCases.filter { $0.context == context }
48+
3349
await withCheckedContinuation { continuation in
34-
guard ABTest.allCases.count > 1 else {
50+
guard !experiments.isEmpty else {
3551
return continuation.resume(returning: ())
3652
}
3753

38-
let experimentNames = ABTest.allCases.filter { $0 != .null }.map { $0.rawValue }
54+
let experimentNames = experiments.map { $0.rawValue }
3955
ExPlat.shared?.register(experiments: experimentNames)
4056

4157
ExPlat.shared?.refresh {
@@ -56,3 +72,11 @@ public extension Variation {
5672
}
5773
}
5874
}
75+
76+
/// The context for an A/B testing experiment (where the experience being tested occurs).
77+
///
78+
public enum ExperimentContext: Equatable {
79+
case loggedOut
80+
case loggedIn
81+
case none // For the `null` experiment case
82+
}

Experiments/Experiments/DefaultFeatureFlagService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
3737
return buildConfig == .localDeveloper || buildConfig == .alpha
3838
case .wpcomSignup:
3939
return buildConfig == .localDeveloper || buildConfig == .alpha
40+
case .inAppPurchases:
41+
return buildConfig == .localDeveloper || buildConfig == .alpha
4042
default:
4143
return true
4244
}

Experiments/Experiments/FeatureFlag.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,8 @@ public enum FeatureFlag: Int {
7777
/// Enables signing up for a WP.com account.
7878
///
7979
case wpcomSignup
80+
81+
/// Enables In-app purchases for buying Hosted WooCommerce plans
82+
///
83+
case inAppPurchases
8084
}

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-----
55
- [***] Stats: Now you can add a Today's Stats Widget to your lock screen (iOS 16 only) to monitor your sales. [https://github.com/woocommerce/woocommerce-ios/pull/7839]
66
- [***] Dropped iOS 14 support. From now we support iOS 15 and later. [https://github.com/woocommerce/woocommerce-ios/pull/7851]
7-
7+
- [internal] In-Person Payments: add UTM parameters to card reader purchase URLs to allow attribution [https://github.com/woocommerce/woocommerce-ios/pull/7858]
88

99
10.7
1010
-----

WooCommerce/Classes/Analytics/TracksProvider.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,19 @@ private extension TracksProvider {
7373
UserDefaults.standard[.analyticsUsername] = account.username
7474
tracksService.switchToAuthenticatedUser(withUsername: account.username,
7575
userID: String(account.userID),
76-
anonymousID: anonymousID,
7776
wpComToken: credentials.authToken,
7877
skipAliasEventCreation: false)
7978
} else if currentAnalyticsUsername == account.username {
8079
// Username did not change - just make sure Tracks client has it
8180
tracksService.switchToAuthenticatedUser(withUsername: account.username,
8281
userID: String(account.userID),
83-
anonymousID: anonymousID,
8482
wpComToken: credentials.authToken,
8583
skipAliasEventCreation: true)
8684
} else {
8785
// Username changed for some reason - switch back to anonymous first
8886
tracksService.switchToAnonymousUser(withAnonymousID: anonymousID)
8987
tracksService.switchToAuthenticatedUser(withUsername: account.username,
9088
userID: String(account.userID),
91-
anonymousID: anonymousID,
9289
wpComToken: credentials.authToken,
9390
skipAliasEventCreation: false)
9491
}

WooCommerce/Classes/AppDelegate.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,11 @@ private extension AppDelegate {
372372
}
373373
}
374374

375-
/// Starts the AB testing platform
375+
/// Starts the AB testing platform and fetches test assignments for the current context
376376
///
377377
func startABTesting() async {
378-
await ABTest.start()
378+
let context: ExperimentContext = ServiceLocator.stores.isAuthenticated ? .loggedIn : .loggedOut
379+
await ABTest.start(for: context)
379380
}
380381

381382
/// Tracks if the application was opened via a widget tap.

WooCommerce/Classes/Authentication/AuthenticatedWebViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private extension AuthenticatedWebViewController {
128128
guard let url = viewModel.initialURL else {
129129
return
130130
}
131+
131132
if let credentials = ServiceLocator.stores.sessionManager.defaultCredentials {
132133
webView.authenticateForWPComAndRedirect(to: url, credentials: credentials)
133134
} else {

WooCommerce/Classes/Authentication/Epilogue/StorePickerViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ private extension StorePickerViewController {
524524
return
525525
}
526526
Task { @MainActor in
527-
await ABTest.start()
527+
await ABTest.start(for: .loggedIn)
528528
}
529529
}
530530
}

WooCommerce/Classes/Notifications/PushNotificationsManager.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,19 @@ private extension PushNotificationsManager {
446446
func handleRemoteNotificationInAllAppStates(_ userInfo: [AnyHashable: Any]) {
447447
DDLogVerbose("📱 Push Notification Received: \n\(userInfo)\n")
448448

449-
// Badge: Update
450449
if let typeString = userInfo.string(forKey: APNSKey.type),
451450
let type = Note.Kind(rawValue: typeString),
452451
let siteID = siteID,
453452
let notificationSiteID = userInfo[APNSKey.siteID] as? Int64 {
453+
// Badge: Update
454454
incrementNotificationCount(siteID: notificationSiteID, type: type, incrementCount: 1) { [weak self] in
455455
self?.loadNotificationCountAndUpdateApplicationBadgeNumber(siteID: siteID, type: type, postNotifications: true)
456456
}
457+
458+
// Update related product when review notification is received
459+
if type == .comment, let productID = userInfo[APNSKey.postID] as? Int64 {
460+
updateProduct(productID, siteID: notificationSiteID)
461+
}
457462
}
458463

459464
// Badge: Reset
@@ -483,6 +488,16 @@ private extension PushNotificationsManager {
483488

484489
inactiveNotificationsSubject.send(notification)
485490
}
491+
492+
/// Reload related product when review notification is received
493+
///
494+
func updateProduct(_ productID: Int64, siteID: Int64) {
495+
let action = ProductAction.retrieveProduct(siteID: siteID,
496+
productID: productID) { _ in
497+
// ResultsController<StorageProduct> will reload the Product List (ProductsViewController)
498+
}
499+
stores.dispatch(action)
500+
}
486501
}
487502

488503
private extension PushNotificationsManager {
@@ -657,6 +672,7 @@ private enum APNSKey {
657672
static let identifier = "note_id"
658673
static let type = "type"
659674
static let siteID = "blog"
675+
static let postID = "post_id"
660676
}
661677

662678
private enum AnalyticKey {

WooCommerce/Classes/ViewModels/Feature Announcement Cards/FeatureAnnouncementCardViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import UIKit
33
import Yosemite
4+
import WooFoundation
45

56
private typealias FeatureCardEvent = WooAnalyticsEvent.FeatureCard
67

0 commit comments

Comments
 (0)