Skip to content

Commit f43fb21

Browse files
committed
track elapsed time
1 parent 3e3424a commit f43fb21

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ extension PointOfSaleAggregateModel {
155155
}
156156

157157
private func trackCustomerInteractionStarted() {
158-
// TODO: Only track if no cart items yet
159-
collectOrderPaymentAnalyticsTracker.trackCustomerInteractionStarted()
158+
// At the moment we're assumming that an interaction starts simply when the cart is zero
159+
// but a more complex logic will be needed for other cases
160+
if cart.count == 0 {
161+
collectOrderPaymentAnalyticsTracker.trackCustomerInteractionStarted()
162+
}
160163
}
161164
}
162165

WooCommerce/Classes/ViewRelated/Orders/Collect Payments/CollectOrderPaymentAnalytics.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ final class POSCollectOrderPaymentAnalytics: CollectOrderPaymentAnalyticsTrackin
3737
func trackProcessingCompletion(intent: Yosemite.PaymentIntent) { }
3838

3939
func trackSuccessfulPayment(capturedPaymentData: CardPresentCapturedPaymentData) {
40-
let customerInteractionFinished = Date().timeIntervalSince1970 - customerInteractionStarted
41-
debugPrint("end at \(customerInteractionFinished)")
42-
ServiceLocator.analytics.track(event: WooAnalyticsEvent.PointOfSale.cardPresentCollectPaymentSuccess(millisecondsSinceCustomerIteractionStated: customerInteractionFinished))
40+
let elapsedTime = calculateElapsedTimeInMilliseconds(start: customerInteractionStarted, end: Date().timeIntervalSince1970)
41+
ServiceLocator.analytics.track(event: WooAnalyticsEvent.PointOfSale.cardPresentCollectPaymentSuccess(millisecondsSinceCustomerIteractionStated: elapsedTime))
4342
}
4443

4544
func trackPaymentFailure(with error: any Error) { }
@@ -52,7 +51,10 @@ final class POSCollectOrderPaymentAnalytics: CollectOrderPaymentAnalyticsTrackin
5251

5352
func trackCustomerInteractionStarted() {
5453
customerInteractionStarted = Date().timeIntervalSince1970
55-
debugPrint("started at \(customerInteractionStarted)")
54+
}
55+
56+
private func calculateElapsedTimeInMilliseconds(start: Double, end: Double) -> Double {
57+
(end - start) * 1000
5658
}
5759
}
5860

0 commit comments

Comments
 (0)