Skip to content

Conversation

wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Oct 8, 2025

Fixes STRIPE-740

Changes proposed in this Pull Request:

To complement #4669, this PR will add tracking for the "Reconnect to Stripe" button clicks (for both the admin notice and the main button in the settings screen).

Testing instructions

  • Checkout and build this branch on your test environment (add/tracking-account-reconnect-notice-click)
  • Connect your Stripe account
  • Set up your store to behave as if it did not connect via OAuth by removing the connection_type (or test_connection_type attr from the settings:
wp option patch delete woocommerce_stripe_settings test_connection_type
  • Click the "Reconnect to Stripe" button (either from the admin notice or the main button in the Stripe settings screen)
  • In about 5 minutes, check MC Tracks Live events page for the presence of a wcstripe_reconnect_button_click event

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@wjrosa wjrosa self-assigned this Oct 8, 2025
@wjrosa wjrosa marked this pull request as ready for review October 8, 2025 19:14
@wjrosa wjrosa added this to the 10.0.0 milestone Oct 8, 2025
@wjrosa wjrosa requested review from a team, diegocurbelo and malithsen and removed request for a team October 8, 2025 19:21
@malithsen
Copy link
Contributor

malithsen commented Oct 9, 2025

@wjrosa I might need some additional help testing this. I tried deleting the test_connection_type key/value pair from the settings option. That forced me to reconnect via the initial connection screen (No "Reconnect to Stripe" button)

I also tried hard-coding oauthConnected = false but I couldn't get account-details-section.js component to get called at all. I might be looking at the wrong views. Do you mind sharing a screenshot?

EDIT:
nvm, I was making changes on my local site while looking at a separate JN site 🤦

Copy link
Member

@diegocurbelo diegocurbelo 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 working as indicated, my only nitpick is that we are not actually tracking the click in the admin notice button, but the page load it triggers (&highlight=account-details), so page refreshes will count towards it 🤷🏼

Image

Also, maybe we should also track the Re-authenticate button to get the full picture:

Image

Copy link
Contributor

@malithsen malithsen left a comment

Choose a reason for hiding this comment

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

Code looks good, agreeing with Diego's feedback.

@wjrosa
Copy link
Contributor Author

wjrosa commented Oct 10, 2025

Thanks for the review, folks!

This is working as indicated, my only nitpick is that we are not actually tracking the click in the admin notice button, but the page load it triggers (&highlight=account-details), so page refreshes will count towards it 🤷🏼

That's a good point. I refactored the code in f348c35 to actually track the click instead of the page scroll. I had to use raw JS since I could not import the existing Tracks component there.

Also, maybe we should also track the Re-authenticate button to get the full picture:

Added tracking for that in 79025c6

Copy link
Contributor

@malithsen malithsen left a comment

Choose a reason for hiding this comment

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

Changes look good to me

Comment on lines 439 to 440
$onclick .= 'window.wcTracks.recordEvent( \'wcstripe_reconnect_button_click\', { source: \'admin_notice\', mode: ' . ( $testmode ? '\'test\'' : '\'live\'' ) . ' } );';
$onclick .= 'window.location = \'admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings&highlight=account-details\'; return false;';
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of this series of inline JS, but I also don't see a significantly better approach compared to this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not add a JS snippet that wraps all of this logic? It feels like manually generating the onclick handling here is going to be really messy to get right in the long run. Also, is it possible for us to keep the href and simply let the onclick trigger the tracking?

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 working as indicated, my only nitpick is that we are not actually tracking the click in the admin notice button, but the page load it triggers (&highlight=account-details), so page refreshes will count towards it 🤷🏼
~ Diego

Another option to address the original issue that this in-line JS is trying to solve is that we pass in a URL fragment here, and in the frontend record the event if the fragment is present. Once the event is recorded, remove the fragment so that page refreshes don't result in duplicate events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, folks. I refactored it again in b18cc9c, using Malith's suggestion above (thanks!)

@wjrosa wjrosa requested a review from daledupreez October 14, 2025 18:09
@wjrosa wjrosa requested a review from diegocurbelo October 14, 2025 20:49
@daledupreez daledupreez removed this from the 10.0.0 milestone Oct 15, 2025
@daledupreez daledupreez added this to the 10.1.0 milestone Oct 15, 2025
Copy link
Member

@diegocurbelo diegocurbelo left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes @wjrosa. It's working as expected now!

@wjrosa wjrosa enabled auto-merge (squash) October 15, 2025 17:04
Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

I removed the reconnection logic yesterday in #4730. I think we need to take a step back to assess how and when we show the reconnection notices due to some of the issues we saw in the 10.0.0 release.

@wjrosa
Copy link
Contributor Author

wjrosa commented Oct 16, 2025

I removed all code related to the admin notice yesterday. I kept only the code tracking the existing buttons and links. Still, do you want to put this on hold anyway?

@wjrosa wjrosa merged commit 21976b8 into develop Oct 16, 2025
40 checks passed
@wjrosa wjrosa deleted the add/tracking-account-reconnect-notice-click branch October 16, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants