Skip to content
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

Track user clicks on Links/Buttons in disconnect modal footer #22467

Merged
merged 10 commits into from
Jan 31, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Added user click tracking to disconnect dialog modal
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ const DisconnectDialog = props => {
e => {
e && e.preventDefault();

jetpackAnalytics.tracks.recordEvent(
'jetpack_disconnect_dialog_click_disconnect',
defaultTracksArgs
);

jim-coffey marked this conversation as resolved.
Show resolved Hide resolved
setDisconnectError( false );
setIsDisconnecting( true );

Expand All @@ -217,7 +222,24 @@ const DisconnectDialog = props => {
// Default to making the disconnect API call here.
_disconnect();
},
[ setDisconnectError, setIsDisconnecting, pluginScreenDisconnectCallback, context, _disconnect ]
[
setDisconnectError,
setIsDisconnecting,
pluginScreenDisconnectCallback,
context,
_disconnect,
defaultTracksArgs,
]
);

const trackModalClick = useCallback(
target => {
jetpackAnalytics.tracks.recordEvent(
`jetpack_disconnect_dialog_click_${ target }`,
jim-coffey marked this conversation as resolved.
Show resolved Hide resolved
defaultTracksArgs
);
},
[ defaultTracksArgs ]
);

/**
Expand Down Expand Up @@ -321,6 +343,7 @@ const DisconnectDialog = props => {
disconnectError={ disconnectError }
context={ context } // Where is the modal showing? ( most important for when it loads on the plugins page )
disconnectingPlugin={ disconnectingPlugin } // Which plugin is initiating the disconnect.
trackModalClick={ trackModalClick }
/>
);
} else if ( isDisconnected && ! isProvidingFeedback && ! isFeedbackProvided ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External Dependencies
*/
import React from 'react';
import React, { useCallback } from 'react';

/**
* Internal Dependencies
Expand Down Expand Up @@ -30,8 +30,18 @@ const StepDisconnect = props => {
disconnectingPlugin,
closeModal,
context,
trackModalClick,
} = props;

const trackLearnClick = useCallback( () => trackModalClick( 'learn_about' ), [
jim-coffey marked this conversation as resolved.
Show resolved Hide resolved
trackModalClick,
] );
const trackSupportClick = useCallback( () => trackModalClick( 'support' ), [ trackModalClick ] );
const trackStayConnectedClick = useCallback( () => {
jim-coffey marked this conversation as resolved.
Show resolved Hide resolved
trackModalClick( 'stay_connected' );
closeModal();
}, [ trackModalClick, closeModal ] );

/**
* Render the disconnect button, allows for some variance based on context.
*
Expand Down Expand Up @@ -109,6 +119,7 @@ const StepDisconnect = props => {
rel="noopener noreferrer"
target="_blank"
className="jp-connection__disconnect-dialog__link"
onClick={ trackLearnClick }
/>
),
jpSupportLink: (
Expand All @@ -117,6 +128,7 @@ const StepDisconnect = props => {
rel="noopener noreferrer"
target="_blank"
className="jp-connection__disconnect-dialog__link"
onClick={ trackSupportClick }
/>
),
}
Expand All @@ -127,7 +139,7 @@ const StepDisconnect = props => {
<Button
isPrimary
disabled={ isDisconnecting }
onClick={ closeModal }
onClick={ trackStayConnectedClick }
className="jp-connection__disconnect-dialog__btn-dismiss"
>
{ __( 'Stay connected', 'jetpack' ) }
Expand Down Expand Up @@ -162,6 +174,8 @@ StepDisconnect.propTypes = {
closeModal: PropTypes.func,
/** Where this modal is being rendered. */
context: PropTypes.string,
/** Callback tracks link/btn clicks (onDisconnect handles it's own tracks) */
trackModalClick: PropTypes.func,
};

export default StepDisconnect;
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ describe( 'StepDisconnect', () => {
title: 'Test Title',
onDisconnect: spy(),
closeModal: spy(),
trackModalClick: spy(),
};

afterEach( () => {
testProps.trackModalClick.resetHistory();
} );

describe( 'Initially', () => {
const wrapper = shallow( <StepDisconnect { ...testProps } /> );

Expand Down Expand Up @@ -47,13 +52,37 @@ describe( 'StepDisconnect', () => {

describe( 'When the dismiss button is clicked', () => {
const wrapper = shallow( <StepDisconnect { ...testProps } /> );

wrapper
.find( '.jp-connection__disconnect-dialog__btn-dismiss' )
.simulate( 'click', { preventDefault: () => undefined } );
const dismissBtn = wrapper.find( '.jp-connection__disconnect-dialog__btn-dismiss' );

it( 'calls the closeModal callback', () => {
dismissBtn.simulate( 'click', { preventDefault: () => undefined } );

expect( testProps.closeModal.called ).to.be.true;
} );

it( 'calls the trackModalClick callback with stay_connected', () => {
dismissBtn.simulate( 'click', { preventDefault: () => undefined } );

expect( testProps.trackModalClick.calledOnceWith( 'stay_connected' ) ).to.be.true;
} );
} );

describe( 'When help links are clicked', () => {
const learnAboutLink = 0;
const supportLink = 1;
const wrapper = shallow( <StepDisconnect { ...testProps } /> );
const links = wrapper.find( '.jp-connection__disconnect-dialog__link' );

it( 'the connection link calls the trackModalClick with learn_about', () => {
links.at( learnAboutLink ).simulate( 'click', { preventDefault: () => undefined } );
jim-coffey marked this conversation as resolved.
Show resolved Hide resolved

expect( testProps.trackModalClick.calledOnceWith( 'learn_about' ) ).to.be.true;
} );

it( 'the support link calls the trackModalClick with support', () => {
links.at( supportLink ).simulate( 'click', { preventDefault: () => undefined } );

expect( testProps.trackModalClick.calledOnceWith( 'support' ) ).to.be.true;
} );
} );
} );