Skip to content

Commit

Permalink
Stepper: Ensure calypso_signup_start doesn't get recorded over and …
Browse files Browse the repository at this point in the history
…over / 50 times (#95028)
  • Loading branch information
chriskmnds authored Oct 1, 2024
1 parent 24d0ea8 commit f52e1eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export const useSignUpStartTracking = ( { flow }: Props ) => {
adTrackSignupStart( flowName );
}, [ isSignupFlow, flowName ] );

if ( ! isSignupFlow ) {
return;
}
useEffect( () => {
if ( ! isSignupFlow ) {
return;
}

recordSignupStart( { flow: flowName, ref, optionalProps: extraProps || {} } );
recordSignupStart( { flow: flowName, ref, optionalProps: extraProps || {} } );
}, [ isSignupFlow, flowName, ref, extraProps ] );
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ describe( 'useSignUpTracking', () => {
} );
} );

it( 'records the calypso_signup_start event a single time if dependencies are stable', () => {
const { rerender } = render( {
flow: {
...signUpFlow,
} satisfies Flow,
} );

rerender();
expect( recordSignupStart ).toHaveBeenCalledTimes( 1 );
} );

it( 'records the calypso_signup_start event multiple times when dependencies change', () => {
const { rerender } = render( {
flow: {
...signUpFlow,
useSignupStartEventProps: () => ( { extra: 'props' } ),
} satisfies Flow,
} );

rerender();
expect( recordSignupStart ).toHaveBeenCalledTimes( 2 );
} );

it( 'sets the signup-start timer only on initial mount (assuming static flowName and isSignupFlow)', () => {
const { rerender } = render( {
flow: {
Expand Down

0 comments on commit f52e1eb

Please sign in to comment.