Skip to content

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented May 13, 2025

All Submissions:

Changes proposed in this Pull Request:

Introduces the newspackOpenModalCheckout( options ); function so the modal checkout can be initiated programmatically by 3rd parties.

options.title will determine the checkout title, not overriding other modal titles the modal checkout may require (thank you/newsletters).

options.actionType will set a custom action_type for the checkout_completed activity, which currently is either checkout_button or donation.

options.afterSuccess sets the after success url, behavior, and buttonLabel for the checkout.

options.onCheckoutComplete is a callback to be called on the checkout_complete RAS activity with the activity data

options.onClose is a callback to be called on the newly introduced checkout-closed custom event

This required a few changes to the modal checkout structure, which I commented inline.

How to test the changes in this Pull Request:

Follow instructions at Automattic/newspack-plugin#3973, but also make sure this introduces no regressions to regular modal checkout flows by donating and purchasing a subscription as a reader.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@miguelpeixe miguelpeixe self-assigned this May 21, 2025
@miguelpeixe miguelpeixe marked this pull request as ready for review May 21, 2025 15:16
@miguelpeixe miguelpeixe requested a review from a team as a code owner May 21, 2025 15:16
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Very nice refactor! I really like the addition of a global newspackOpenModalCheckout function that allows other plugin code to trigger modal checkouts. I noticed some differences in the data events activity payload for checkouts that we may want to examine more closely to avoid discontinuity in analytics, but other than that this is testing well.

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

@miguelpeixe thank you for these revisions and for starting the standardization of checkout data! In general I like the consolidation of the transaction details into the new Checkout_Data class. I think this will be much more readable and easier to follow in the future compared with how it was handled before.

I'm running into a handful of issues that I think are related to these changes. No big surprise since this is an unexpectedly big refactor of a feature that touches many different areas.

  1. When doing checkouts from a paywall/content gate, the np_modal_checkout_interaction events don't always seem to have gate_post_id params attached. I think this might be due to changes in how URL params are handled/passed from screen to screen within the modal iframe? In particular, the action=open event did have the param, but action=loaded and action=continue when transitioning between checkout screens did not. I tested against trunk and there, all np_modal_checkout_interaction events did have a gate_post_id param.

  2. [NON-BLOCKING, but mentioning here because it's related to the next item] This is not related to these changes, but noting in case we want to handle this edge case in the future. Variable, non-subscription products are not handled by our Checkout Button block. Attaching a variable non-subscription product to a Checkout Button and clicking the button as a reader will always result in a checkout error: Please choose product options by visiting <a href="[product page URL] title="Product Name">Product Name</a>.

  3. Related to the above, on trunk if as a reader I click a Checkout Button with a variable non-subscription product, I'll see the error message in the modal checkout window with a "Go back" button to close. On this branch, the modal checkout window will get stuck in a loading state and the error is logged to Logstash, but never shown to the reader. This is also replicable if you set a product to be limited to one per customer. On trunk, I see the error message below if I try to purchase a subscription product that I already own, but on this branch the modal checkout window hangs in a loading state.

Screenshot 2025-05-27 at 4 06 51 PM Screenshot 2025-05-27 at 3 46 01 PM

Other feedback inline.

'product_id' => strval( $product_id ? $product_id : '' ),
'product_type' => $product_type,
'price_summary' => self::get_price_summary( $name, $amount, $recurrence ),
'summary_template' => self::get_price_summary( $name, '{{PRICE}}', $recurrence ),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a neat way to build the price summary, but it's superfluous to send to GA or any other integrations using this data. Can we strip it once price_summary has been set in the data object?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to keep the price_summary because it'll be reused every time a modal is rendered on the same page.

How about controlling the keys that are sent instead? Implemented in e74c77c

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach! Makes it much easier to see and control which keys ultimately get sent where

@miguelpeixe
Copy link
Member Author

The gate_post_id param has been fixed in 5b08f3d. Because we're now fetching that information from the cart item data, we no longer need to worry about passing it via URL, so this has been removed in d734a65.

I also identified an issue with newspack_popup_id that was also present in trunk. A hotfix is proposed in #2134 and Automattic/newspack-popups#1441. The fix is also implemented here (0a00a46) so it should work in this branch as well.

@miguelpeixe miguelpeixe requested a review from dkoo May 29, 2025 14:35
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

This is all working well now! We're just missing a handful of GA event params in our whitelist—details below. After that this should be good to merge.

*
* @type {string[]}
*/
const eventKeys = [
Copy link
Contributor

Choose a reason for hiding this comment

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

We also need action for the action parameter, e.g. seen, loaded, continue, etc. as well as all custom event params that we add in the main plugin.

Copy link
Member Author

Choose a reason for hiding this comment

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

as well as all custom event params that we add in the main plugin.

Were these part of the payload before? I've never seen them here

Copy link
Member Author

Choose a reason for hiding this comment

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

Added action in 8372718

Copy link
Contributor

Choose a reason for hiding this comment

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

Were these part of the payload before? I've never seen them here

They're only enabled if you add a NEWSPACK_GA_ENABLE_CUSTOM_FE_PARAMS environment constant. Originally we sent them with every event, but because some publishers have custom dimensions and events in their own GA setups, they sometimes caused our GA events to exceed the parameter limit per event. They're now opt-in only via this constant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, gotcha! We don't need to worry about it, then. That's hooked into googlesitekit_gtag_opt, which adds the custom parameters some other way. We don't manually send these via window.gtag( 'event' ).

Seems to work fine for me after enabling the flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, you're right! I thought I wasn't seeing them, but it's just because I was testing on a page without categories. Thanks for looking into this.

@miguelpeixe miguelpeixe requested a review from dkoo May 29, 2025 20:07
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Looking good, thanks for the extensive refactoring here!

@miguelpeixe miguelpeixe merged commit 0c5301b into trunk May 29, 2025
9 checks passed
@miguelpeixe miguelpeixe deleted the feat/modal-checkout-my-account branch May 29, 2025 20:59
@github-actions
Copy link

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Jun 5, 2025
# [4.13.0-alpha.1](v4.12.3...v4.13.0-alpha.1) (2025-06-05)

### Bug Fixes

* donate block formatting ([#2133](#2133)) ([f27cb76](f27cb76))
* update stripe express checkout divider ([#2131](#2131)) ([b907452](b907452))

### Features

* **modal-checkout:** checkout from "My Account" dashboard ([#2121](#2121)) ([0c5301b](0c5301b))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 4.13.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jun 16, 2025
# [4.13.0](v4.12.3...v4.13.0) (2025-06-16)

### Bug Fixes

* donate block formatting ([#2133](#2133)) ([f27cb76](f27cb76))
* update stripe express checkout divider ([#2131](#2131)) ([b907452](b907452))

### Features

* **modal-checkout:** checkout from "My Account" dashboard ([#2121](#2121)) ([0c5301b](0c5301b))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 4.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants