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

Update how Cart/Checkout is tracked to be realtime. #35139

Merged
merged 3 commits into from
Feb 9, 2024

Conversation

senadir
Copy link
Contributor

@senadir senadir commented Jan 19, 2024

Proposed changes:

This PR changes how we're tracking Checkout block events. Instead of firing the event when Checkout loads, and assuming whatever is in the Checkout page is that, we now only react to Checkout events (shortcode and Block), and dynamically edit the checkout_page_contains_checkout_block and checkout_page_contains_checkout_shortcode values.

This is done by hooking into Checkout events.

This PR also adds a from_checkout prop to indicate if the event came from Checkout page or not.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Setup a new website That's running Checkout Block on the Checkout page. Install One Page Checkout, and mark a product a single page product.
  • Create a new page called Checkout Shortcode and add Shortcode Checkout to it.
  • Add a product to your cart, open track vigilante, and go to Checkout page (with Block), make sure the checkout_page_contains_checkout_block value is 1 and checkout_page_contains_checkout_shortcode is 0 on product_checkout event, make sure that from_checkout is 1.
  • Place the order, make sure the values are still correct in the product_purshase event.
  • Do the same from the one page checkout product page, make sure the values are reversed, so shortcode is 1 and block is 0, and that from_checkout is 0.
  • Do the same from the extra page you create and make sure the values are still correct.
  • Now change your default Checkout to shortcode, run the flow again the Checkout page and make sure the values are correct in both events.

Copy link
Contributor

github-actions bot commented Jan 19, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the add/move-woo-event-tracking-frontend branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/move-woo-event-tracking-frontend
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Feature] WooCommerce Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Jan 19, 2024
Copy link
Contributor

github-actions bot commented Jan 19, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for March 5, 2024 (scheduled code freeze on March 4, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@senadir senadir marked this pull request as ready for review January 22, 2024 12:21
@senadir senadir self-assigned this Jan 22, 2024
@senadir senadir requested a review from opr January 22, 2024 12:21
@senadir senadir force-pushed the add/move-woo-event-tracking-frontend branch from 94f34bd to 509aebb Compare February 1, 2024 15:24
@senadir senadir requested review from opr and removed request for opr February 1, 2024 16:03
@senadir
Copy link
Contributor Author

senadir commented Feb 1, 2024

@anomiex let us know that the failing E2E test above is happening to all issues and it shouldn't prevent us from merging given everything else is passing.

Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

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

As a logged-in user, in woocommerceanalytics_checkout_view and woocommerceanalytics_product_checkout events the guest_checkout property is Yes for me but in woocommerceanalytics_order_confirmation_view it becomes No.

In the testing instructions:

Do the same from the extra page you create and make sure the values are still correct.

Just noting that in this case woocommerceanalytics_checkout_view is showing the incorrect values. Only woocommerceanalytics_product_checkout and woocommerceanalytics_product_purchase are correct.

}

const checkoutDataStore = wp.data.select( 'wc/store/checkout' );
if ( undefined !== checkoutDataStore && checkoutDataStore.getOrderId() !== 0 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would check if ( 'undefined' !== typeof checkoutDataStore && checkoutDataStore.getOrderId() !== 0 ) rather than using undefined for consistency with the above uses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is outdated I think, because I already removed the checkoutDataStore check because we're subscribing to it so it's always there.

@senadir senadir requested a review from opr February 7, 2024 15:45
@senadir senadir force-pushed the add/move-woo-event-tracking-frontend branch from 509aebb to 318f2a8 Compare February 7, 2024 15:45
@senadir
Copy link
Contributor Author

senadir commented Feb 7, 2024

@opr I addressed the review points, added tracking to the Checkout view event as well (while trying to keep it PHP only) and made sure the event triggers regardless (previously it required you to interact with Checkout for it to run, now it should run on mount).

@@ -147,18 +147,27 @@ public function capture_checkout_view() {
$is_checkout = $checkout_page_id && is_page( $checkout_page_id )
|| wc_post_content_has_shortcode( 'woocommerce_checkout' )
|| has_block( 'woocommerce/checkout', $post )
|| has_block( 'woocommerce/classic-shortcode', $post )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no way to check if the block is Cart or Checkout.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, this is OK though. It's based on the template as far as I can tel. If someone has set up their Checkout page to use the Cart template then it will be an edge case, don't think we can or should try to solve for this.

Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

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

Happy to say this is testing OK for me, tried with several different configs and all seem to be fine for me.

🤞🏼

@senadir senadir force-pushed the add/move-woo-event-tracking-frontend branch from 318f2a8 to 5a8ca44 Compare February 9, 2024 13:15
@senadir senadir enabled auto-merge (squash) February 9, 2024 13:15
@senadir senadir merged commit 30544af into trunk Feb 9, 2024
52 checks passed
@senadir senadir deleted the add/move-woo-event-tracking-frontend branch February 9, 2024 13:26
@github-actions github-actions bot added this to the jetpack/13.2 milestone Feb 9, 2024
spsiddarthan pushed a commit that referenced this pull request Feb 15, 2024
* Update how Cart/Checkout is tracked

* add extra to see from checkout is coming

* address changes
if ( true === cartItem_{$cart_item_key}_logged ) {
return;
}
wp.hooks.addAction( 'wcpay.payment-request.availability', 'wcpay', function ( args ) {
Copy link

@jjcoffee jjcoffee Mar 25, 2024

Choose a reason for hiding this comment

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

wp.hooks is not guaranteed to be available. If it's not available, this blocks a lot of JS on the checkout from working, including coupons, "Click here to login", etc. See here.

Copy link
Contributor

@opr opr Mar 25, 2024

Choose a reason for hiding this comment

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

Thanks for raising this @jjcoffee - I agree we should add a check to ensure it's available before using.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jjcoffee - I have opened #36560 to solve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WooCommerce Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants