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

feat(data-events): donation listeners #2225

Merged
merged 10 commits into from
Jan 18, 2023

Conversation

miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Jan 11, 2023

All Submissions:

Changes proposed in this Pull Request:

This PR tweaks the hook into woocommerce_checkout_order_processed so it's more easily accessible for other parts of the code that might want to reach donation processing. There shouldn't be any change into how the sync_reader_from_order() behaves.

The following donation-related listeners are added:

donation_new

When there's a new donation, either through Stripe or Newspack (WooCommerce) platforms.

Data

Name Type
user_id int
email string
amount float
currency string
recurrence string
platform string
platform_data array

donation_subscription_new

When there's a new WooCommerce Subscription. This action does not replace the donation_new that create the subscription.

Name Type
user_id int
email string
amount float
currency string
recurrence string
platform string
platform_data array

donation_subscription_cancelled

When a WooCommerce Subscription is cancelled.

Name Type
subscription_id int
user_id int
email string
amount float
currency string
recurrence string
platform string

donation_subscription_changed

When a WooCommerce Subscription status changes.

Name Type
subscription_id int
user_id int
email string
status_before string
status_after string
amount float
currency string
recurrence string
platform string

How to test the changes in this Pull Request:

  1. Make sure you have the following constants:
define( 'NEWSPACK_AMP_PLUS_ENABLED', true );
define( 'NEWSPACK_EXPERIMENTAL_READER_ACTIVATION', true );
define( 'NEWSPACK_LOG_LEVEL', 2 );
  1. Make sure you have the Reader Revenue Newspack (WooCommerce) platform configured
  2. Make a new one-time donation using the donation block
  3. Confirm you see the logs with [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::dispatch]: Dispatching action "donation_new" via Action Scheduler.
  4. Visit WooCommerce's Status -> Scheduled Actions
  5. Confirm you see the newspack_data_events_as_dispatch hook with donation_new as well
  6. Now make a recurring donation (subscription) and confirm you see the same with: donation_subscription_new, donation_subscription_changed (switching from pending to active)
  7. WIth Reader Activation enabled, make sure you have ActiveCampaign configured with a master list
  8. Make a donation with a new email and confirm the contact data with donation details is being updated to ActiveCampaign as expected
  9. Switch the platform to Stripe and repeats steps from 3 to 7

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?

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
@miguelpeixe miguelpeixe self-assigned this Jan 12, 2023
@miguelpeixe miguelpeixe marked this pull request as ready for review January 12, 2023 20:07
@miguelpeixe miguelpeixe requested a review from a team as a code owner January 12, 2023 20:07
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Jan 12, 2023
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.

Ran into one issue where the donation_subscription_new action is getting dispatched upon a new single donation order, and a couple of questions which may or may not be issues.

*/
Data_Events::register_listener(
'newspack_data_event_dispatch_donation_new',
'donation_subscription_new',
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing these steps:

  1. Make a new one-time donation using the donation block
  2. Confirm you see the logs with [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::dispatch]: Dispatching action "donation_new" via Action Scheduler.

Making a one-time donation, I see both donation_subscription_new and donation_new actions being dispatched.

[12-Jan-2023 23:31:07 UTC] [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::dispatch]: Dispatching action "donation_subscription_new" via Action Scheduler.
[12-Jan-2023 23:31:07 UTC] [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::dispatch]: Dispatching action "donation_new" via Action Scheduler.

I also see this in the Scheduled Actions log:

Screen Shot 2023-01-12 at 5 17 26 PM

Note also the empty timestamps of the scheduled actions—not sure if that's a bug or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for catching that! The product recurrence check was failing because it was bailing if it was once, but the product does not store this value for the one-time donation product, just the month or year for recurring ones.

829c2ea fixes that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can confirm that the donation_subscription_new is only fired on new subscriptions now, not one-time donations.

The timestamps still look like 0000-00-00, but I'm not sure if this is a bug.

Data_Events::register_listener(
'woocommerce_subscription_status_updated',
'donation_subscription_cancelled',
function( $subscription, $status_from, $status_to ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking from an analytics POV, it would make sense to also have the subscription details here: amount, currency, recurrence and platform.

In case we are triggering non identifiable events and analyzing them, we could then compare to see what kind of subscriptions are being cancelled.

Copy link
Contributor

Choose a reason for hiding this comment

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

same for status_update.

makes sense?

Copy link
Member Author

@miguelpeixe miguelpeixe Jan 16, 2023

Choose a reason for hiding this comment

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

Good call! 47e5039 expands the data for both events

'donation_subscription_new',
function( $timestamp, $data ) {
if ( 'once' === $data['recurrence'] ) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! That's a great use of listeners I haven't thought about... same hook but dispatching different actions depending on the params

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
@miguelpeixe
Copy link
Member Author

@dkoo, were you able to confirm that the AC integration works as expected while using WooCommerce? It worked without issues for me:

image

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
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.

The updates look good to me, and I note the additional data on the events based on @leogermani's suggestion. I'd wait until @leogermani gives approval too before merging, though.

I did still have one question about the timestamps of scheduled actions looking like 0000-00-00 00:00:00, but I'm not sure if this is an issue because the proper timestamp is logged in the "Log" column. So, I'll approve this at your and @leogermani's discretion.

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Jan 17, 2023
@miguelpeixe
Copy link
Member Author

Thank you, @dkoo! I noticed the 0000-00-00 00:00:00 timestamp as well. It looks like the default behavior when enqueueing a new task without scheduling, so it executes as soon as possible.

Taking a look at the AS repo, I noticed this recently merged PR. Looks like it changes this default behavior also to improve the scheduling so overdue tasks are processed before the enqueued ones.

Copy link
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

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

This looks good to me.

In the future I'll check if it's possible to add some more data to the events to be used in the analytics, like where the donation came from? (from a prompt, sdb, etc...)

@miguelpeixe miguelpeixe merged commit 9c5d4aa into master Jan 18, 2023
@miguelpeixe miguelpeixe deleted the feat/data-events-donation-listener branch January 18, 2023 13:23
dkoo added a commit that referenced this pull request Jan 19, 2023

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
* chore(deps): bump stripe/stripe-php from 10.2.0 to 10.3.0

Bumps [stripe/stripe-php](https://github.com/stripe/stripe-php) from 10.2.0 to 10.3.0.
- [Release notes](https://github.com/stripe/stripe-php/releases)
- [Changelog](https://github.com/stripe/stripe-php/blob/master/CHANGELOG.md)
- [Commits](stripe/stripe-php@v10.2.0...v10.3.0)

---
updated-dependencies:
- dependency-name: stripe/stripe-php
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(data-events): switch wp hooks priority (#2216)

As a WordPress standard, the more specific hook should be called first.

* chore(deps-dev): bump @wordpress/browserslist-config from 5.6.0 to 5.7.0

Bumps [@wordpress/browserslist-config](https://github.com/WordPress/gutenberg/tree/HEAD/packages/browserslist-config) from 5.6.0 to 5.7.0.
- [Release notes](https://github.com/WordPress/gutenberg/releases)
- [Changelog](https://github.com/WordPress/gutenberg/blob/trunk/packages/browserslist-config/CHANGELOG.md)
- [Commits](https://github.com/WordPress/gutenberg/commits/@wordpress/[email protected]/packages/browserslist-config)

---
updated-dependencies:
- dependency-name: "@wordpress/browserslist-config"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* feat(data-events): use WC's Action Scheduler if available (#2217)

* docs: data events (#2215)

* fix(stripe): WC Subs scheduled actions errors suppression

* fix(stripe): webhooks list edge-cases (#2209)

* feat(donations): remove donation products from cart if WC is not the donations platform (#2224)

* chore(deps-dev): bump phpunit/phpunit from 9.5.27 to 9.5.28

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.27 to 9.5.28.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.5.28/ChangeLog-9.5.md)
- [Commits](sebastianbergmann/phpunit@9.5.27...9.5.28)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix(wc-to-esp): total amount field value

* feat(perfmatters): add newspack theme files to unused CSS exclusions list

* feat(perfmatters): add some scripts to script delay list

* feat(data-events): donation listeners (#2225)

* feat(stripe): disable WC emails sent on sub. renewal for Stripe sync'd subs.

* feat: optimise the HP block that renders first on a page

* fix: only enqueue salesforce admin JS when appropriate

* fix: merge conflicts with master

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Miguel Peixe <[email protected]>
Co-authored-by: matticbot <[email protected]>
Co-authored-by: Adam Borowski <[email protected]>
matticbot pushed a commit that referenced this pull request Jan 26, 2023

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
# [1.102.0-alpha.1](v1.101.0...v1.102.0-alpha.1) (2023-01-26)

### Bug Fixes

* add template versions to Woo templates ([#2240](#2240)) ([38f75b4](38f75b4))
* **wc-to-esp:** total amount field value ([83e6a42](83e6a42))

### Features

* **ads:** optimise inline JS of newspack-ads ([#2238](#2238)) ([7d02837](7d02837))
* **data-events:** donation listeners ([#2225](#2225)) ([9c5d4aa](9c5d4aa))
* optimise the HP block that renders first on a page ([7559986](7559986))
* **perfmatters:** add newspack theme files to unused CSS exclusions list ([4571387](4571387))
* **perfmatters:** add some scripts to script delay list ([989c9fd](989c9fd))
* **stripe:** disable WC emails sent on sub. renewal for Stripe sync'd subs. ([2e75135](2e75135))
@matticbot
Copy link
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 26, 2023

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
# [1.103.0-alpha.1](v1.102.0...v1.103.0-alpha.1) (2023-01-26)

### Bug Fixes

* add template versions to Woo templates ([#2240](#2240)) ([38f75b4](38f75b4))
* merge conflicts ([8dd0e87](8dd0e87))
* **wc-to-esp:** total amount field value ([83e6a42](83e6a42))

### Features

* **ads:** optimise inline JS of newspack-ads ([#2238](#2238)) ([7d02837](7d02837))
* **data-events:** donation listeners ([#2225](#2225)) ([9c5d4aa](9c5d4aa))
* optimise the HP block that renders first on a page ([7559986](7559986))
* **perfmatters:** add newspack theme files to unused CSS exclusions list ([4571387](4571387))
* **perfmatters:** add some scripts to script delay list ([989c9fd](989c9fd))
* **stripe:** disable WC emails sent on sub. renewal for Stripe sync'd subs. ([2e75135](2e75135))
@matticbot
Copy link
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 17, 2023

Verified

This commit was signed with the committer’s verified signature.
miguelpeixe Miguel Peixe
# [1.103.0](v1.102.0...v1.103.0) (2023-02-17)

### Bug Fixes

* add template versions to Woo templates ([#2240](#2240)) ([38f75b4](38f75b4))
* merge conflicts ([8dd0e87](8dd0e87))
* trigger release ([0c8471b](0c8471b))
* update package.json to resolve a merge conflict with master ([f2408a3](f2408a3))
* **wc-to-esp:** total amount field value ([83e6a42](83e6a42))

### Features

* **ads:** optimise inline JS of newspack-ads ([#2238](#2238)) ([7d02837](7d02837))
* **data-events:** donation listeners ([#2225](#2225)) ([9c5d4aa](9c5d4aa))
* optimise the HP block that renders first on a page ([7559986](7559986))
* **perfmatters:** add newspack theme files to unused CSS exclusions list ([4571387](4571387))
* **perfmatters:** add some scripts to script delay list ([989c9fd](989c9fd))
* **stripe:** disable WC emails sent on sub. renewal for Stripe sync'd subs. ([2e75135](2e75135))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.103.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants