Skip to content

Commit 30bc4e9

Browse files
authored
Merge pull request #7907 from woocommerce/issue/7741-add-customer-search-tracks
Add tracks for Customer Search
2 parents d12e538 + 169094d commit 30bc4e9

File tree

9 files changed

+61
-17
lines changed

9 files changed

+61
-17
lines changed

Experiments/Experiments/DefaultFeatureFlagService.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
3333
return true
3434
case .searchProductsBySKU:
3535
return true
36-
case .orderCreationSearchCustomers:
37-
return buildConfig == .localDeveloper || buildConfig == .alpha
3836
case .wpcomSignup:
3937
guard isFeatureFlagEnabled(.simplifiedLoginFlowI1) else {
4038
return buildConfig == .localDeveloper || buildConfig == .alpha

Experiments/Experiments/FeatureFlag.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ public enum FeatureFlag: Int {
7070
///
7171
case searchProductsBySKU
7272

73-
/// Enables the Search Customers functionality in the Order Creation screen
74-
///
75-
case orderCreationSearchCustomers
76-
7773
/// Enables signing up for a WP.com account.
7874
///
7975
case wpcomSignup

RELEASE-NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
11.1
44
-----
5-
5+
- [**] You can now search customers when creating or editing an order. [https://github.com/woocommerce/woocommerce-ios/issues/7741]
66

77
11.0
88
-----

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ public enum WooAnalyticsStat: String {
265265
case orderCreateButtonTapped = "order_create_button_tapped"
266266
case orderCreationSuccess = "order_creation_success"
267267
case orderCreationFailed = "order_creation_failed"
268+
case orderCreationCustomerAdded = "order_creation_customer_added"
269+
case orderCreationCustomerSearch = "order_creation_customer_search"
268270
case orderContactAction = "order_contact_action"
269271
case orderCustomerAdd = "order_customer_add"
270272
case orderEditButtonTapped = "order_edit_button_tapped"

WooCommerce/Classes/ViewRelated/Orders/Order Creation/CustomerSection/CustomerSearchUICommand.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ final class CustomerSearchUICommand: SearchUICommand {
2121

2222
private let siteID: Int64
2323

24-
init(siteID: Int64, onDidSelectSearchResult: @escaping ((Customer) -> Void)) {
24+
private let analytics: Analytics
25+
26+
init(siteID: Int64,
27+
analytics: Analytics = ServiceLocator.analytics,
28+
onDidSelectSearchResult: @escaping ((Customer) -> Void)) {
2529
self.siteID = siteID
30+
self.analytics = analytics
2631
self.onDidSelectSearchResult = onDidSelectSearchResult
2732
}
2833

@@ -59,6 +64,7 @@ final class CustomerSearchUICommand: SearchUICommand {
5964
}
6065

6166
func synchronizeModels(siteID: Int64, keyword: String, pageNumber: Int, pageSize: Int, onCompletion: ((Bool) -> Void)?) {
67+
analytics.track(.orderCreationCustomerSearch)
6268
let action = CustomerAction.searchCustomers(siteID: siteID, keyword: keyword) { result in
6369
switch result {
6470
case .success(_):

WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/AddressFormViewModelProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ open class AddressFormViewModel: ObservableObject {
405405
/// Fills Order AddressFormFields with Customer details
406406
///
407407
func customerSelectedFromSearch(customer: Customer) {
408+
analytics.track(.orderCreationCustomerAdded)
408409
fillCustomerFields(customer: customer)
409410
let addressesDiffer = customer.billing != customer.shipping
410411
showDifferentAddressForm = addressesDiffer

WooCommerce/Classes/ViewRelated/Orders/Order Details/Address Edit/EditOrderAddressForm.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ struct EditOrderAddressForm<ViewModel: AddressFormViewModelProtocol>: View {
9191
@Environment(\.safeAreaInsets) var safeAreaInsets: EdgeInsets
9292
@State private var showingCustomerSearch: Bool = false
9393

94-
let isSearchCustomersEnabled = DefaultFeatureFlagService().isFeatureFlagEnabled(.orderCreationSearchCustomers)
95-
9694
var body: some View {
9795
Group {
9896
ScrollView {
@@ -151,13 +149,11 @@ struct EditOrderAddressForm<ViewModel: AddressFormViewModelProtocol>: View {
151149
})
152150
}
153151
ToolbarItem(placement: .automatic) {
154-
if isSearchCustomersEnabled {
155-
Button(action: {
156-
showingCustomerSearch = true
157-
}, label: {
158-
Image(systemName: "magnifyingglass")
159-
})
160-
}
152+
Button(action: {
153+
showingCustomerSearch = true
154+
}, label: {
155+
Image(systemName: "magnifyingglass")
156+
})
161157
}
162158
ToolbarItem(placement: .confirmationAction) {
163159
navigationBarTrailingItem()

WooCommerce/WooCommerceTests/ViewRelated/Orders/Order Details/Addresses/EditOrderAddressFormViewModelTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,25 @@ final class EditOrderAddressFormViewModelTests: XCTestCase {
701701
assertEqual(analyticsProvider.receivedProperties.first?["subject"] as? String, "billing_address")
702702
}
703703

704+
func test_view_model_when_customerSelectedFromSearch_then_tracks_orderCreationCustomerAdded() {
705+
// Given
706+
let analyticsProvider = MockAnalyticsProvider()
707+
let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing, analytics: WooAnalytics(analyticsProvider: analyticsProvider))
708+
let customer = Customer.fake().copy(
709+
710+
firstName: "Johnny",
711+
lastName: "Appleseed",
712+
billing: sampleAddressWithEmptyNullableFields(),
713+
shipping: sampleAddressWithEmptyNullableFields()
714+
)
715+
716+
// When
717+
viewModel.customerSelectedFromSearch(customer: customer)
718+
719+
// Then
720+
XCTAssert(analyticsProvider.receivedEvents.contains("order_creation_customer_added"))
721+
}
722+
704723
func test_view_model_fires_error_notice_when_providing_an_invalid_email() {
705724
// Given
706725
let viewModel = EditOrderAddressFormViewModel(order: Order.fake(), type: .billing)

WooCommerce/WooCommerceTests/ViewRelated/Search/Customer/CustomerSearchUICommandTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import Yosemite
44

55
final class CustomerSearchUICommandTests: XCTestCase {
66
private let sampleSiteID: Int64 = 123
7+
private var analyticsProvider: MockAnalyticsProvider!
8+
private var analytics: Analytics!
9+
10+
override func setUp() {
11+
analyticsProvider = MockAnalyticsProvider()
12+
analytics = WooAnalytics(analyticsProvider: analyticsProvider)
13+
}
714

815
func test_searchResultsPredicate_includes_siteID_and_keyword_when_keyword() {
916
// Given
@@ -35,4 +42,23 @@ final class CustomerSearchUICommandTests: XCTestCase {
3542
XCTAssertEqual(cellViewModel.title, "\(customer.firstName ?? "") \(customer.lastName ?? "")")
3643
XCTAssertEqual(cellViewModel.subtitle, String(customer.email))
3744
}
45+
46+
func test_CustomerSearchUICommand_when_synchronizeModels_then_tracks_orderCreationCustomerSearch_event() {
47+
// Given
48+
let command = CustomerSearchUICommand(
49+
siteID: sampleSiteID,
50+
analytics: analytics) { _ in }
51+
52+
// When
53+
command.synchronizeModels(
54+
siteID: sampleSiteID,
55+
keyword: "",
56+
pageNumber: 1,
57+
pageSize: 1,
58+
onCompletion: { _ in }
59+
)
60+
61+
// Then
62+
XCTAssert(analyticsProvider.receivedEvents.contains("order_creation_customer_search"))
63+
}
3864
}

0 commit comments

Comments
 (0)