-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Woo POS] MVP analytics: Handle card present events from POS #15138
[Woo POS] MVP analytics: Handle card present events from POS #15138
Conversation
…r POS events and use it within the card reader adaptor
Generated by 🚫 Danger |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -149,6 +153,14 @@ extension PointOfSaleAggregateModel { | |||
paymentState = .card(.idle) | |||
cardPresentPaymentInlineMessage = nil | |||
} | |||
|
|||
private func trackCustomerInteractionStarted() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;nit
We can put in these trackings into a different extension for code organization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated! 66141e4
|
||
func trackCustomerInteractionStarted() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit;
Theoretically, we could have
POSCollectOrderPaymentAnalyticsTracking: CollectOrderPaymentAnalyticsTracking
that has func trackCustomerInteractionStarted()
, and POSCollectOrderPaymentAnalytics
would implement POSCollectOrderPaymentAnalyticsTracking
. This way non-POS parts of the code, such as various preflight controllers wouldn't have knowledge of trackCustomerInteractionStarted
. POS aggregate model would expect POSCollectOrderPaymentAnalyticsTracking
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, playing a bit more with the conformances here looks a good idea since we have so much shared logic 🤔
@@ -136,6 +136,7 @@ final class HubMenuViewModel: ObservableObject { | |||
}() | |||
|
|||
private(set) var cardPresentPaymentService: CardPresentPaymentFacade? | |||
private(set) var collectOrderPaymentAnalyticsTracker = POSCollectOrderPaymentAnalytics() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't love that we use HubMenuViewModel
as POS factory but we can deal with both creation of cardPresentPaymentService and collectOrderPaymentAnalyticsTracker in some future improvement PR if needed.
private func trackCustomerInteractionStarted() { | ||
// At the moment we're assumming that an interaction starts simply when the cart is zero | ||
// but a more complex logic will be needed for other cases | ||
if cart.count == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should clearing the cart reset the customer interaction time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I don't think we're clear on that yet. Initially it would seem we would, but I have some doubts about it. Context: pdfdoF-6hn#comment-7582-p2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Lets sync with Android. Otherwise, in some cases we could have inconclusive data.
func trackSuccessfulPayment(capturedPaymentData: CardPresentCapturedPaymentData) { | ||
let elapsedTime = calculateElapsedTimeInMilliseconds(start: customerInteractionStarted, end: Date().timeIntervalSince1970) | ||
ServiceLocator.analytics.track(event: | ||
.PointOfSale.cardPresentCollectPaymentSuccess(millisecondsSinceCustomerIteractionStated: elapsedTime)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We send value such as 16712.467908859253
, should we floor it, and send only the millisecond part 16712
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good to me. Updated here: 4748a30
🔵 Tracked pos_card_present_collect_payment_success, properties: [plan: , site_url: https://indiemelon.mystagingwebsite.com, milliseconds_since_customer_interaction_started: 27589.0, blog_id: -1, is_wpcom_store: false, was_ecommerce_trial: false, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f]
Since we floor the value and we return a Double, we always get the .0
which I don't think it's necessary, perhaps returning an Int here is enough as the event key already tells is milliseconds. I'll iterate on this when adding the rest of properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Lets sync with Android on this.
…-pos # Conflicts: # WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift
Thanks for the review!
Yes, this duplication was triggering me a bit but was the "official" event 😅 (Ref: pdfdoF-6hn#comment-7556-p2 ) , it's resolved now: b5fd2b3 |
Closes: #15128
Description
This PR creates
POSCollectOrderPaymentAnalytics
, a new implementation of theCollectOrderPaymentAnalyticsTracking
protocol. We use this in order to track card-payment related events and their properties from POS without interfering with IPP events. We also need to do so as the event tracking logic is very deeply embedded into the card payment service.Since we have to keep track of time intervals for different operations (order creation, card readiness, transaction successful), we also DI this instance into the aggregate model in order to be able to pass starting and ending time for these intervals.
Only the
pos_card_present_collect_payment_success
and one property (milliseconds_since_customer_interaction_started
) is tracked on this PR, there are more properties that we need to track for this single event, but these will come on a following PR:Testing information
pos_card_present_collect_payment_success
with propertymilliseconds_since_customer_interaction_started
is captured:card_present_collect_payment_success
instead.RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: