Skip to content

Commit b2ee837

Browse files
committed
Tracks when the create button is tapped
1 parent 0475c38 commit b2ee837

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsEvent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,19 +361,19 @@ extension WooAnalyticsEvent {
361361
])
362362
}
363363

364-
static func orderStatusChange(flow: Flow, from oldStatus: OrderStatus, to newStatus: OrderStatus) -> WooAnalyticsEvent {
364+
static func orderStatusChange(flow: Flow, from oldStatus: OrderStatusEnum, to newStatus: OrderStatusEnum) -> WooAnalyticsEvent {
365365
WooAnalyticsEvent(statName: .orderStatusChange, properties: [
366366
Keys.flow: flow.rawValue,
367-
Keys.from: oldStatus.slug,
368-
Keys.to: newStatus.slug
367+
Keys.from: oldStatus.rawValue,
368+
Keys.to: newStatus.rawValue
369369
])
370370
}
371371

372-
static func orderCreateButtonTapped(status: OrderStatus,
372+
static func orderCreateButtonTapped(status: OrderStatusEnum,
373373
productCount: Int,
374374
hasCustomerDetails: Bool) -> WooAnalyticsEvent {
375375
WooAnalyticsEvent(statName: .orderCreateButtonTapped, properties: [
376-
Keys.orderStatus: status.slug,
376+
Keys.orderStatus: status.rawValue,
377377
Keys.productCount: Int64(productCount),
378378
Keys.hasCustomerDetails: hasCustomerDetails
379379
])

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrderViewModel.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ final class NewOrderViewModel: ObservableObject {
224224
}
225225
}
226226
stores.dispatch(action)
227+
trackCreateButtonTapped()
227228
}
228229

229230
/// Assign this closure to be notified when a new order is created
@@ -494,6 +495,18 @@ private extension NewOrderViewModel {
494495
}()
495496
analytics.track(event: WooAnalyticsEvent.Orders.orderCustomerAdd(flow: .creation, hasDifferentShippingDetails: areAddressesDifferent))
496497
}
498+
499+
/// Tracks when the create order button is tapped.
500+
///
501+
/// Warning: This methods assume that `orderDetails.items.count` is equal to the product count,
502+
/// We probably should update this property to something like `itemsCount` or include better way to get the product count as the module evolves.
503+
///
504+
func trackCreateButtonTapped() {
505+
let hasCustomerDetails = orderDetails.billingAddress != nil || orderDetails.shippingAddress != nil
506+
analytics.track(event: WooAnalyticsEvent.Orders.orderCreateButtonTapped(status: orderDetails.status,
507+
productCount: orderDetails.items.count,
508+
hasCustomerDetails: hasCustomerDetails))
509+
}
497510
}
498511

499512
private extension NewOrderViewModel {

0 commit comments

Comments
 (0)