Skip to content
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: Card payment success event properties #15148

Merged
merged 13 commits into from
Feb 18, 2025

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Feb 14, 2025

Description

This PR it's a continuation of #15138, and adds the following missing properties to pos_card_present_collect_payment_success event:

milliseconds_since_order_creation_success
milliseconds_since_reader_ready_to_collect_payment
milliseconds_since_card_tapped
checkout_tap_count

In order to track these we follow the same design that the existing milliseconds_since_customer_interaction_started property, as we need to keep track of the elapsed time between the action starts and ends, before sending the event.

Testing information

  • In POS, add some items to cart, tap checkout, go back to the cart (make some edits or not) and tap checkout again, then follow the card payment flow. At the end, observe that the event has been tracked with elapsed times and a correct number of checkout_tap_count.
🔵 Tracked pos_card_present_collect_payment_success, properties: [is_wpcom_store: false, milliseconds_since_card_tapped: 5625.0, plan: , site_url: https://indiemelon.mystagingwebsite.com, checkout_tap_count: 3, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, was_ecommerce_trial: false, milliseconds_since_customer_interaction_started: 27118.0, milliseconds_since_order_creation_success: 19099.0, blog_id: -1, milliseconds_since_reader_ready_to_collect_payment: 9861.0]
  • Repeat the flow just tapping checkout once, observe the count is 1.

While I have a specific issue logged for adding more testing around tracks, in general I found very tricky to add unit tests due to how "invasive" these are in POS, and how much we'd need to mock.


  • I have considered if this change warrants user-facing release notes and have added them to 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:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

We can add this event closer to order creation if we add it inside the OrderController sync function, however this couples both objects tighter. I think it’s fine to add the track event to the aggregate model as:

- It will not track the event as a side effect of order sync, as this is only called on checkout, and we always create a new order when this happens

- It would log the start time internally for both card and cash flows, however doesn’t matter as the event is only populated and sent for card events later on, and at this point we do not know how the customer is going to pay, as happens later in the flow.
@iamgabrielma iamgabrielma added type: task An internally driven task. category: tracks Related to analytics, including Tracks Events. feature: POS labels Feb 14, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Feb 14, 2025

1 Message
📖

This PR contains changes to Tracks-related logic. Please ensure (author and reviewer) the following are completed:

  • The tracks events must be validated in the Tracks system.
  • Verify the internal Tracks spreadsheet has also been updated.
  • Please consider registering any new events.
  • The PR must be assigned the category: tracks label.

Generated by 🚫 Danger

@iamgabrielma iamgabrielma added this to the 21.8 milestone Feb 14, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 14, 2025

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr15148-af7ce8f
Version21.7
Bundle IDcom.automattic.alpha.woocommerce
Commitaf7ce8f
App Center BuildWooCommerce - Prototype Builds #13013
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@iamgabrielma iamgabrielma marked this pull request as ready for review February 14, 2025 11:49
Copy link
Contributor

@staskus staskus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It works well! However, there are a few concerns to address:

  1. If we consider order creation always when we checkout or only when the new order is actually created?
  2. Processing event happens multiple times, even a couple of seconds after the tap.
  3. Checkout tracker is not reset if POS is closed and reopened.

The Stripe SDK returns multiple `.processing` events, but we want to capture the first one in the stream only. This flag is reset as soon as the payment has been successful
@iamgabrielma
Copy link
Contributor Author

Thanks for the review @staskus ! This is ready for another round. Just a recap as per slack:

If we consider order creation always when we checkout or only when the new order is actually created?

When it's actually created we trigger the event as soon as possible. At the moment we track the orderCreationSuccess event in the order controller, but we milliseconds for "order success" just after we exit the function in the aggregate model. Ideally we would track those two at the same time but it's going to make everything very messy, so it doesn't seem to be worth it.

Processing event happens multiple times, even a couple of seconds after the tap.

We resolved this by having a flag in the analytics tracker, as we couldn't rely on .cardRemoved. the flag resets on payment success and on user interaction starts. This also helps to reset it when there's a cash payment as a side-effect, but we can trigger it explicitly in the next PR when handling those.

Checkout tracker is not reset if POS is closed and reopened.

That's alright, we reset trackers on user interaction start 👍

@iamgabrielma iamgabrielma requested a review from staskus February 18, 2025 12:19
Copy link
Contributor

@staskus staskus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fixes!

Left one comment about syncOrder state

let posCartItems = cartItems.map {
POSCartItem(item: $0.item, quantity: Decimal($0.quantity))
}

guard !orderState.isSyncing,
!posCartItems.matches(order: order) else {
return
return .failure(SyncOrderStateError.syncFailure)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If posCartItems.matches(order: order) it means that that .success(.orderNotChanged) not shat syncing failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciated, I got confused with the negative guard 🙇 fixed here and added a new case and test: af7ce8f

@iamgabrielma iamgabrielma merged commit 06b9022 into trunk Feb 18, 2025
12 checks passed
@iamgabrielma iamgabrielma deleted the task/collect-payment-success-event-properties branch February 18, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tracks Related to analytics, including Tracks Events. feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants