Skip to content

Conversation

@staskus
Copy link
Contributor

@staskus staskus commented Apr 17, 2025

Description

Add missing analytics events for the POS Coupons implementation.

Specs:

Name Event
Coupon settings enabled. Existing event with _pos prefix when the coupon is enabled. pos_coupon_settings_enabled
Coupon created. Existing event with _pos prefix when the coupon is created. pos_coupon_creation_success
Checkout with coupons Existing pos_checkout_tapped event with a new coupons_in_cart parameter. pos_checkout_tapped New parameter:coupons_in_cart : Integer
Checkout with coupons failed. Existing pos_order_creation_failed with improved error_context. pos_order_creation_failed Update parameter:error_context to specific error woocommerce_rest_invalid_coupon rather than the whole error message since it's difficult to filter it out.

New Events

We will track the new data using the same conventions as products in POS.

Name Event
Products section tapped. pos_products_tapped
Coupons section tapped. pos_coupons_tapped
Coupon creation tapped. pos_coupons_create_tapped
Coupons pull to refresh. pos_coupons_pull_to_refresh
Coupon added to the cart. pos_coupon_added_to_cart
Coupon removed from cart. Track also when "Remove coupon" button is tapped on an error. pos_coupon_removed_from_cart

Steps to reproduce

Prerequisites:

  • Disable Enable the use of coupon codes setting in WooCommerce->Settings
  • Enable enableCouponsInPointOfSale feature flag
  1. Open POS and switch to the Coupons tab -> pos_coupons_tapped should be tracked
  2. Tap 'Enable Coupons' -> pos_coupon_settings_enabled should be tracked
  3. Tap '+' -> pos_coupons_create_tapped should be tracked
  4. Create a coupon -> pos_coupon_creation_success should be tracked
  5. Add coupon to cart -> pos_coupon_added_to_cart should be tracked
  6. Remove coupon from cart -> pos_coupon_removed_from_cart should be tracked
  7. Pull to refresh -> pos_coupons_pull_to_refresh should be tracked
  8. Add coupon and products to cart, tap checkout -> pos_checkout_tapped should be tracked with coupons_in_cart parameter and number of coupons added to cart
  9. Return to edit order, add invalid coupon, checkout -> pos_order_creation_failed should be tracked with error_context set to woocommerce_rest_invalid_coupon

Registration PRs of new events:

Testing information

Tested on iPad Air 11 Inch M2 iOS 18.2 Simulator


  • 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.

@staskus staskus added type: task An internally driven task. feature: POS labels Apr 17, 2025
@staskus staskus added this to the 22.2 milestone Apr 17, 2025
@staskus staskus requested review from Copilot and joshheald April 17, 2025 15:03
@dangermattic
Copy link
Collaborator

dangermattic commented Apr 17, 2025

2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is assigned to the milestone 22.2. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.
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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the missing analytics events for coupon-related actions in the POS flow while updating related tracking calls and analytics event definitions. Key changes include:

  • Adding and applying new analytics events for coupon settings, creation, cart actions, and checkout with coupons.
  • Refactoring tracking methods (e.g. replacing direct tracking calls with helper functions) in views like ItemListView and CartView.
  • Updating analytics event definitions and tracks provider lists to support these new coupon events.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Yosemite/Yosemite/Stores/CouponsError.swift Added a constant property ‘code’ using an error code constant from Constants.
WooCommerce/Classes/POS/Presentation/Order Messages/PointOfSaleOrderSyncCouponsErrorMessageView.swift Added a tracking call for coupon removal inside the retry button action.
WooCommerce/Classes/POS/Presentation/ItemListView.swift Updated various tracking calls to use the new events and helper functions (e.g. trackPullToRefresh and trackSelectedItemListTypeTapped).
WooCommerce/Classes/POS/Presentation/CartView.swift Revised checkout tracking to include counts for both products and coupons; added a tracking call on coupon removal.
WooCommerce/Classes/POS/Controllers/PointOfSaleOrderController.swift Modified the order creation failure tracking to use a helper that differentiates coupon errors using the new CouponsError code property.
WooCommerce/Classes/POS/Analytics/WooAnalyticsEvent+PointOfSale.swift Updated the checkoutTapped event method and added a new event property for coupons in cart.
WooCommerce/Classes/POS/Analytics/WooAnalyticsStat.swift Introduced new analytics stat cases for coupon-related events.
WooCommerce/Classes/Analytics/TracksProvider.swift Added the new coupon event cases to the list of valid POS events.
Comments suppressed due to low confidence (3)

Yosemite/Yosemite/Stores/CouponsError.swift:5

  • [nitpick] Consider adding inline documentation or a brief comment clarifying that the property 'code' is intentionally hard-coded to the invalid coupon constant so that future maintainers understand it is not meant to vary per error instance.
public let code: String = Constants.invalidCouponCode

WooCommerce/Classes/Analytics/TracksProvider.swift:205

  • [nitpick] Double-check that the naming of the newly added coupon event cases (e.g. couponCreationSuccess, couponSettingEnabled) remains consistent with existing naming conventions in the codebase.
WooAnalyticsStat.couponSettingEnabled,

WooCommerce/Classes/POS/Analytics/WooAnalyticsEvent+PointOfSale.swift:37

  • Verify that all callers of the 'checkoutTapped' method have been updated to pass both products and coupons counts to avoid runtime issues.
static func checkoutTapped(productsInCart: Int, couponsInCart: Int) -> WooAnalyticsEvent {

@staskus staskus added the category: tracks Related to analytics, including Tracks Events. label Apr 17, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Apr 17, 2025

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

App NameWooCommerce iOS Prototype
Build Number29376
VersionPR #15516
Bundle IDcom.automattic.alpha.woocommerce
Commit59584f8
Installation URL2ftrp3brmkmf8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Copy link
Contributor

@joshheald joshheald left a comment

Choose a reason for hiding this comment

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

All work well 👍

@staskus staskus enabled auto-merge April 18, 2025 08:29
@staskus staskus force-pushed the woomob-154-woo-pos-coupons-analytics branch from 94dff69 to 59584f8 Compare April 18, 2025 11:15
@staskus staskus merged commit a6789ce into trunk Apr 18, 2025
13 checks passed
@staskus staskus deleted the woomob-154-woo-pos-coupons-analytics branch April 18, 2025 11:35
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.

5 participants