Skip to content

feat(analytics): "My Account" dashboard interactions#3949

Merged
miguelpeixe merged 18 commits into
trunkfrom
feat/analytics-my-account-interactions
May 9, 2025
Merged

feat(analytics): "My Account" dashboard interactions#3949
miguelpeixe merged 18 commits into
trunkfrom
feat/analytics-my-account-interactions

Conversation

@miguelpeixe

@miguelpeixe miguelpeixe commented Apr 23, 2025

Copy link
Copy Markdown
Member

All Submissions:

Changes proposed in this Pull Request:

Dispatch reader data activities and GA4 events on My Account interactions:

Activity Params Interaction
subscription_cancelled subscription_id Click and confirm the "Cancel" button on an active subscription page.
subscription_reactivated subscription_id Click the "Reactivate" button on a subscription pending cancellation.
subscription_switched -- Complete the checkout after clicking "Upgrade or Downgrade" on an active variable subscription
payment_method_deleted -- Click "Delete" on a payment method in the "Payment methods" page
payment_method_added payment_method: the method gateway (stripe, woocommerce_payments, etc) Submit a new payment method via the "Payment methods" page
payment_method_changed subscription_id, update_all_subscriptions Submit a new payment method for an active subscription.
address_updated* address_type: Either billing or shipping Submit an address update via the "Addresses" page
product_reordered -- Complete the checkout after clicking "Order again" on a past order from the "Orders" page

The GA event for each activity above is np_{activity}

Update*: The address_updated was removed in favor of GA's native form_submit. For accuracy, the form_name should be billing_address, shipping_address, and edit_account.

This PR also refactors the analytics approach to introduce a few utility functions and reduce repetition.

How to test the changes in this Pull Request:

  1. Confirm the reader_registered and reader_logged_in events continue to work as proposed in fix(analytics): migrate back-end GA4 events to front-end #3895
  2. Test each event described above, following the "Interaction" column of the table, and confirm the activities are dispatched and the GA4 events are pushed

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 Apr 24, 2025
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Apr 24, 2025
@miguelpeixe miguelpeixe marked this pull request as ready for review April 24, 2025 19:14
@miguelpeixe miguelpeixe requested a review from a team as a code owner April 24, 2025 19:14
@miguelpeixe miguelpeixe requested a review from dkoo April 24, 2025 19:14

@dkoo dkoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@miguelpeixe I really like the abstractions you've put in place like registerElementActivity, registerCheckoutActivity, and registerActivityEvent which should make the Reader Data API even more robust and extensible. Thanks for making these changes.

Feedback is inline. I think you mentioned that we should do a review of the event params we want to collect in a separate PR, so I marked a couple of my items as non-blocking.

Comment thread includes/reader-revenue/my-account/class-woocommerce-my-account.php
Comment thread includes/reader-revenue/my-account/class-woocommerce-my-account.php Outdated
Comment thread includes/reader-revenue/my-account/class-woocommerce-my-account.php Outdated
Comment thread src/reader-activation/analytics.js Outdated
@dkoo

dkoo commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

Also, I neglected to include this interaction in the original proposal, but should we add an activity/event for updating account details?

@miguelpeixe

Copy link
Copy Markdown
Member Author

Also, I neglected to include this interaction in the original proposal, but should we add an activity/event for updating account details?

We could, and that reminds me that this and the address updates are already trackable via GA's form_submit:

image

Would it be worth looking into enhancing the existing event by populating form_id and form_name instead of a custom event?

@miguelpeixe miguelpeixe requested a review from dkoo May 7, 2025 21:16
@dkoo

dkoo commented May 8, 2025

Copy link
Copy Markdown
Contributor

Would it be worth looking into enhancing the existing event by populating form_id and form_name instead of a custom event?

That sounds like a solid idea to me, and this could help us cover other form submissions throughout My Account even if we don't write custom events for them.

@miguelpeixe

miguelpeixe commented May 8, 2025

Copy link
Copy Markdown
Member Author

Switched the address update strategy to use form_submit with the form_name as billing_address and shipping_address. Also added a form_name for edit_account. 48552e3

Also updated the PR description

@dkoo dkoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@miguelpeixe this is working great, and the use of form_submit to capture edit account and address updates is an excellent idea. A couple of minor things I saw and one thing that I think we need to refactor (below, inline).

  • Not sure if this is related to this changeset, but when submitting updates to Edit Account and Address forms, I see a PHP warning: PHP Warning: Undefined variable $field_values in /var/www/html/wp-content/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFieldsFrontend.php on line 312. This doesn't seem to affect anything functionally, AFAICT.
  • Renewing an active subscription from the My Account > My Subscription page fires the same np_product_reordered event as if clicking "Order again" on a past order from the "Orders" page. Should we consider a separate event for subscription renewals, or is it okay to conflate these two actions?

Comment thread src/utils/index.js Outdated
@miguelpeixe

miguelpeixe commented May 8, 2025

Copy link
Copy Markdown
Member Author

Not sure if this is related to this changeset, but when submitting updates to Edit Account and Address forms, I see a PHP warning: PHP Warning: Undefined variable $field_values in /var/www/html/wp-content/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFieldsFrontend.php on line 312. This doesn't seem to affect anything functionally, AFAICT.

This seems unrelated to this PR and I'm unable to reproduce (on either trunk or this branch). I think this should be looked at separately.

Renewing an active subscription from the My Account > My Subscription page fires the same np_product_reordered event as if clicking "Order again" on a past order from the "Orders" page. Should we consider a separate event for subscription renewals, or is it okay to conflate these two actions?

Oh, that's unexpected. Great find! I guess we can track that as well then 😄
Added the subscription_renewal_early activity/event containing the subscription_id in 21306c8

@miguelpeixe miguelpeixe requested a review from dkoo May 8, 2025 22:12

@dkoo dkoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems unrelated to this PR and I'm unable to reproduce (on either trunk or this branch). I think this should be looked at separately.

👍

Added the subscription_renewal_early activity/event containing the subscription_id in 21306c8

Really close now! I'm seeing multiple instances of the np_subscription_renewal_early event when I click "Renew now", load the checkout page with the early renewal, and then finally complete the renewal. I think we should maybe fire only one event when you click the button to complete the renewal transaction, right?

@miguelpeixe

Copy link
Copy Markdown
Member Author

Hm... that's strange, it should be the case because it's implemented via registerCheckoutActivity(), just like the other ones. Taking a closer look.

@miguelpeixe

Copy link
Copy Markdown
Member Author

I'm unable to reproduce the issue. There's no activity attached to the "Renew Now" button, only the checkout. Can you log something at the sendEvent() so we can see exactly at which point multiple events are fired at once?

@dkoo dkoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@miguelpeixe I think I see what's happening. If passing element as a string to registerElementActivity(), element becomes an array due to the querySelectorAll, but then the condition for defining the event to listen for assumes element is a single item. What's happening for me is that event is being redefined as click, so every time I click on an input inside the form[name="checkout"] element, it's firing the checkout activity. I think the suggested changes should solve this.

Comment thread src/utils/index.js Outdated
@miguelpeixe miguelpeixe requested a review from dkoo May 9, 2025 18:49

@dkoo dkoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good, now! Thanks for the changes!

@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 May 9, 2025
@miguelpeixe miguelpeixe merged commit 22e9590 into trunk May 9, 2025
10 checks passed
@miguelpeixe miguelpeixe deleted the feat/analytics-my-account-interactions branch May 9, 2025 19:37
@github-actions

github-actions Bot commented May 9, 2025

Copy link
Copy Markdown

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 May 23, 2025
# [6.7.0-alpha.1](v6.6.2...v6.7.0-alpha.1) (2025-05-23)

### Bug Fixes

* **404-images:** use JS without modifying content ([#3963](#3963)) ([9f5646b](9f5646b))
* add missing namespace ([#3980](#3980)) ([6d58793](6d58793))
* **emails:** add missing HTML markup in the change-email-cancel template ([#3981](#3981)) ([040ae30](040ae30))
* **ga4:** fire login/registration activities via SSO ([#3965](#3965)) ([8c97515](8c97515))
* hide modal content gate when modal checkout is opened ([#3953](#3953)) ([a503973](a503973))
* **jetpack:** handle the related posts max age option ([#3964](#3964)) ([8aad2b8](8aad2b8))
* make sure fix duplcate fields apply filters ([#3971](#3971)) ([f361a4e](f361a4e))
* namespace Lite Site ([#3975](#3975)) ([e4665ae](e4665ae))
* sync correction status with parent post status ([#3978](#3978)) ([dcd5a12](dcd5a12))

### Features

* add compatibility to network in custom bylines ([#3972](#3972)) ([199a993](199a993))
* add icons repository and remove custom icons ([#3883](#3883)) ([e56d2e0](e56d2e0))
* **analytics:** "My Account" dashboard interactions ([#3949](#3949)) ([22e9590](22e9590))
* **donations:** update notice style and type ([#3962](#3962)) ([3f60ef3](3f60ef3))
* **email-change:** remove env constant requirement ([#3943](#3943)) ([4158bf1](4158bf1))
* **my-account:** apply Newspack UI styles to My Account w/ env constant ([#3951](#3951)) ([e4aa5a2](e4aa5a2))
* **my-account:** full-site takeover template and custom nav menu ([#3974](#3974)) ([5cf8403](5cf8403))
* **woocommerce:** log error notices ([#3952](#3952)) ([1654007](1654007))
@matticbot

Copy link
Copy Markdown
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jun 2, 2025
# [6.7.0](v6.6.4...v6.7.0) (2025-06-02)

### Bug Fixes

* **404-images:** use JS without modifying content ([#3963](#3963)) ([9f5646b](9f5646b))
* add missing namespace ([#3980](#3980)) ([6d58793](6d58793))
* **emails:** add missing HTML markup in the change-email-cancel template ([#3981](#3981)) ([040ae30](040ae30))
* **ga4:** fire login/registration activities via SSO ([#3965](#3965)) ([8c97515](8c97515))
* hide modal content gate when modal checkout is opened ([#3953](#3953)) ([a503973](a503973))
* **jetpack:** handle the related posts max age option ([#3964](#3964)) ([8aad2b8](8aad2b8))
* make sure fix duplcate fields apply filters ([#3971](#3971)) ([f361a4e](f361a4e))
* namespace Lite Site ([#3975](#3975)) ([e4665ae](e4665ae))
* prevent auto-publishing corrections when scheduling posts ([#4006](#4006)) ([7531832](7531832))
* sync correction status with parent post status ([#3978](#3978)) ([dcd5a12](dcd5a12))

### Features

* add compatibility to network in custom bylines ([#3972](#3972)) ([199a993](199a993))
* add icons repository and remove custom icons ([#3883](#3883)) ([e56d2e0](e56d2e0))
* **analytics:** "My Account" dashboard interactions ([#3949](#3949)) ([22e9590](22e9590))
* **donations:** update notice style and type ([#3962](#3962)) ([3f60ef3](3f60ef3))
* **email-change:** remove env constant requirement ([#3943](#3943)) ([4158bf1](4158bf1))
* **my-account:** apply Newspack UI styles to My Account w/ env constant ([#3951](#3951)) ([e4aa5a2](e4aa5a2))
* **my-account:** full-site takeover template and custom nav menu ([#3974](#3974)) ([5cf8403](5cf8403))
* **woocommerce:** log error notices ([#3952](#3952)) ([1654007](1654007))
@matticbot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.7.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.

3 participants