-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
There was a problem hiding this 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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing these steps:
- Make a new one-time donation using the donation block
- 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:
Note also the empty timestamps of the scheduled actions—not sure if that's a bug or not?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
includes/data-events/listeners.php
Outdated
Data_Events::register_listener( | ||
'woocommerce_subscription_status_updated', | ||
'donation_subscription_cancelled', | ||
function( $subscription, $status_from, $status_to ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
@dkoo, were you able to confirm that the AC integration works as expected while using WooCommerce? It worked without issues for me: |
There was a problem hiding this 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.
Thank you, @dkoo! I noticed the 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. |
There was a problem hiding this 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...)
* 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]>
# [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))
🎉 This PR is included in version 1.102.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [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))
🎉 This PR is included in version 1.103.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [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))
🎉 This PR is included in version 1.103.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 thesync_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
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.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.
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.
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:
[NEWSPACK-DATA-EVENTS][Newspack\Data_Events::dispatch]: Dispatching action "donation_new" via Action Scheduler.
newspack_data_events_as_dispatch
hook withdonation_new
as welldonation_subscription_new
,donation_subscription_changed
(switching frompending
toactive
)Other information: