Skip to content

Commit 21976b8

Browse files
wjrosadiegocurbelo
andauthored
Track the reconnect notice and button clicks (#4717)
* Track the reconnect notice and button clicks * Readme and changelog entries * Unit test * Tracking the button click instead of the scrolling * Tracking the re-authenticate banner * Removing inline JS * Update includes/admin/class-wc-stripe-admin-notices.php Co-authored-by: Diego Curbelo <[email protected]> * Update client/settings/payment-settings/account-details-section.js Co-authored-by: Diego Curbelo <[email protected]> * Removing unnecessary changes --------- Co-authored-by: Diego Curbelo <[email protected]>
1 parent 31fd315 commit 21976b8

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 10.1.0 - xxxx-xx-xx =
4+
* Dev - Add track events when clicking the "Reconnect to Stripe" button (both in the settings page and the admin notice)
45
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
56
* Dev - Renames previous Order Helper class methods to use the `_id` suffix
67
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas

client/settings/payment-settings/__tests__/account-details-section.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useAccountKeysTestWebhookSecret,
1313
} from 'wcstripe/data/account-keys/hooks';
1414
import { useAccount } from 'wcstripe/data/account';
15+
import { recordEvent } from 'wcstripe/tracking';
1516

1617
jest.mock( 'wcstripe/data', () => ( {
1718
useIsStripeEnabled: jest.fn(),
@@ -36,6 +37,10 @@ jest.mock( 'wcstripe/data/account', () => ( {
3637
useAccount: jest.fn(),
3738
} ) );
3839

40+
jest.mock( 'wcstripe/tracking', () => ( {
41+
recordEvent: jest.fn(),
42+
} ) );
43+
3944
jest.mock( '@stripe/stripe-js', () => ( {
4045
loadStripe: jest.fn(),
4146
} ) );
@@ -287,5 +292,41 @@ describe( 'AccountDetailsSection', () => {
287292
} );
288293
expect( configureConnectionButton ).toBeInTheDocument();
289294
} );
295+
296+
it( 'should record event when the reconnect button is clicked', async () => {
297+
useAccount.mockReturnValue( {
298+
data: {
299+
webhook_url: 'example.com',
300+
account: {
301+
id: 'acct_123',
302+
303+
testmode: false,
304+
},
305+
configured_webhook_urls: {
306+
live: 'example.com',
307+
test: 'example.com',
308+
},
309+
oauth_connections: {
310+
live: { connected: false },
311+
test: { connected: false },
312+
},
313+
},
314+
} );
315+
316+
render(
317+
<AccountDetailsSection setModalType={ setModalTypeMock } />
318+
);
319+
320+
const editKeysButton = screen.getByRole( 'button', {
321+
name: /Configure connection/i,
322+
} );
323+
324+
await userEvent.click( editKeysButton );
325+
326+
expect( recordEvent ).toHaveBeenCalledWith(
327+
'wcstripe_reconnect_button_click',
328+
{ source: 'account_details_section', mode: 'live' }
329+
);
330+
} );
290331
} );
291332
} );

client/settings/payment-settings/account-details-section.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useDispatch } from '@wordpress/data';
1313
import './style.scss';
1414
import { useTestMode } from 'wcstripe/data';
1515
import { useAccount } from 'wcstripe/data/account';
16+
import { recordEvent } from 'wcstripe/tracking';
1617

1718
const HeaderDetails = styled.div`
1819
display: flex;
@@ -97,6 +98,21 @@ const AccountDetailsSection = ( { setModalType, setKeepModalContent } ) => {
9798
const headingRef = useRef( null );
9899
const [ isTestMode ] = useTestMode();
99100
const { data } = useAccount();
101+
const oauthConnected = isTestMode
102+
? data?.oauth_connections?.test?.connected
103+
: data?.oauth_connections?.live?.connected;
104+
105+
const handleButtonClick = () => {
106+
const mode = isTestMode ? 'test' : 'live';
107+
if ( ! oauthConnected ) {
108+
recordEvent( 'wcstripe_reconnect_button_click', {
109+
source: 'account_details_section',
110+
mode,
111+
} );
112+
}
113+
114+
setModalType( mode );
115+
};
100116

101117
useEffect( () => {
102118
if ( ! headingRef.current ) {
@@ -146,9 +162,7 @@ const AccountDetailsSection = ( { setModalType, setKeepModalContent } ) => {
146162
<Button
147163
variant="secondary"
148164
id="btn-configure-connection"
149-
onClick={ () =>
150-
setModalType( isTestMode ? 'test' : 'live' )
151-
}
165+
onClick={ handleButtonClick }
152166
>
153167
{ __(
154168
'Configure connection',

client/settings/payment-settings/promotional-banner/__tests__/re-connect-account-banner.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,19 @@ describe( 'Reconnect banner', () => {
6262
const reconnectButton = getByText( 'Re-authenticate' );
6363
await userEvent.click( reconnectButton );
6464

65-
expect( recordEvent ).toHaveBeenCalledWith(
65+
expect( recordEvent ).toHaveBeenNthCalledWith(
66+
1,
6667
'wcstripe_create_or_connect_test_account_click',
6768
{}
6869
);
70+
expect( recordEvent ).toHaveBeenNthCalledWith(
71+
2,
72+
'wcstripe_reconnect_button_click',
73+
{
74+
source: 're-connect-account-banner',
75+
mode: 'test',
76+
}
77+
);
6978

7079
expect( window.location.assign ).toHaveBeenCalledWith( oauthUrl );
7180

client/settings/payment-settings/promotional-banner/re-connect-account-banner.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ export const ReConnectAccountBanner = ( { testOauthUrl, oauthUrl } ) => {
2121
const handleButtonClick = () => {
2222
if ( isTestModeEnabled && testOauthUrl ) {
2323
recordEvent( 'wcstripe_create_or_connect_test_account_click', {} );
24+
recordEvent( 'wcstripe_reconnect_button_click', {
25+
source: 're-connect-account-banner',
26+
mode: 'test',
27+
} );
2428
window.location.assign( testOauthUrl );
2529
} else if ( ! isTestModeEnabled && oauthUrl ) {
2630
recordEvent( 'wcstripe_create_or_connect_account_click', {} );
31+
recordEvent( 'wcstripe_reconnect_button_click', {
32+
source: 're-connect-account-banner',
33+
mode: 'live',
34+
} );
2735
window.location.assign( oauthUrl );
2836
} else {
2937
createErrorNotice(

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 10.1.0 - xxxx-xx-xx =
114+
* Dev - Add track events when clicking the "Reconnect to Stripe" button (both in the settings page and the admin notice)
114115
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
115116
* Dev - Renames previous Order Helper class methods to use the `_id` suffix
116117
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas

0 commit comments

Comments
 (0)