Skip to content

Commit

Permalink
Add event stats_feedback_action_directly_close_form_modal only
Browse files Browse the repository at this point in the history
  • Loading branch information
dognose24 committed Sep 20, 2024
1 parent 740eade commit 56ca77d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
8 changes: 1 addition & 7 deletions client/my-sites/stats/feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,8 @@ function StatsFeedbackController( { siteId }: FeedbackProps ) {
}
};

const onModalClose = ( isAfterSubmission: boolean ) => {
const onModalClose = () => {
setIsOpen( false );

if ( isAfterSubmission ) {
trackStatsAnalyticsEvent( 'stats_feedback_action_close_form_modal_after_submission' );
} else {
trackStatsAnalyticsEvent( 'stats_feedback_action_close_form_modal' );
}
};

if ( ! supportCommercialUse ) {
Expand Down
24 changes: 14 additions & 10 deletions client/my-sites/stats/feedback/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './style.scss';

interface ModalProps {
siteId: number;
onClose: ( isAfterSubmission: boolean ) => void;
onClose: () => void;
}

const FEEDBACK_SHOULD_SHOW_PANEL_API_KEY = NOTICES_KEY_SHOW_FLOATING_USER_FEEDBACK_PANEL;
Expand Down Expand Up @@ -54,9 +54,13 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
useSubmitProductFeedback( siteId );

const handleClose = useCallback(
( isAfterSubmission: boolean ) => {
( isDirectClose: boolean = false ) => {
setTimeout( () => {
onClose( isAfterSubmission );
onClose();

if ( isDirectClose ) {
trackStatsAnalyticsEvent( 'stats_feedback_action_directly_close_form_modal' );
}
}, 200 );
},
[ onClose ]
Expand All @@ -67,17 +71,17 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
return;
}

trackStatsAnalyticsEvent( 'stats_feedback_action_submit_form', {
feedback: content,
} );

const sourceUrl = `${ window.location.origin }${ window.location.pathname }`;
submitFeedback( {
source_url: sourceUrl,
product_name: 'Jetpack Stats',
feedback: content,
is_testing: false,
} );

trackStatsAnalyticsEvent( 'stats_feedback_action_submit_form', {
feedback: content,
} );
}, [ content, submitFeedback ] );

useEffect( () => {
Expand All @@ -94,7 +98,7 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
refetchNotices();
} );

handleClose( true );
handleClose();
}
}, [
dispatch,
Expand All @@ -110,14 +114,14 @@ const FeedbackModal: React.FC< ModalProps > = ( { siteId, onClose } ) => {
<Modal
className="stats-feedback-modal"
onRequestClose={ () => {
handleClose( false );
handleClose( true );
} }
__experimentalHideHeader
>
<Button
className="stats-feedback-modal__close-button"
onClick={ () => {
handleClose( false );
handleClose( true );
} }
icon={ close }
label={ translate( 'Close' ) }
Expand Down

0 comments on commit 56ca77d

Please sign in to comment.