Skip to content

Commit d23c60b

Browse files
committed
Tracks order creation & success
1 parent b2ee837 commit d23c60b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ final class NewOrderViewModel: ObservableObject {
218218
switch result {
219219
case .success(let newOrder):
220220
self.onOrderCreated(newOrder)
221+
self.trackCreateOrderSuccess()
221222
case .failure(let error):
222223
self.notice = NoticeFactory.createOrderCreationErrorNotice()
224+
self.trackCreateOrderFailure(error: error)
223225
DDLogError("⛔️ Error creating new order: \(error)")
224226
}
225227
}
@@ -499,14 +501,27 @@ private extension NewOrderViewModel {
499501
/// Tracks when the create order button is tapped.
500502
///
501503
/// 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.
504+
/// As the module evolves to handle more types of items we should update this property to something like `itemsCount` or figure a better way to get the product count.
503505
///
504506
func trackCreateButtonTapped() {
505507
let hasCustomerDetails = orderDetails.billingAddress != nil || orderDetails.shippingAddress != nil
506508
analytics.track(event: WooAnalyticsEvent.Orders.orderCreateButtonTapped(status: orderDetails.status,
507509
productCount: orderDetails.items.count,
508510
hasCustomerDetails: hasCustomerDetails))
509511
}
512+
513+
/// Tracks an order creation success
514+
///
515+
func trackCreateOrderSuccess() {
516+
analytics.track(event: WooAnalyticsEvent.Orders.orderCreationSuccess())
517+
}
518+
519+
/// Tracks an order creation failure
520+
///
521+
func trackCreateOrderFailure(error: Error) {
522+
analytics.track(event: WooAnalyticsEvent.Orders.orderCreationFailed(errorContext: String(describing: error),
523+
errorDescription: error.localizedDescription))
524+
}
510525
}
511526

512527
private extension NewOrderViewModel {

0 commit comments

Comments
 (0)