Add event tracking for MoreMenu, SaveAllButton, SendButton and TrashModal components
MAILPOET-6365
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
150403f158
commit
80d698c8c7
@@ -8,6 +8,7 @@ import { PreferenceToggleMenuItem } from '@wordpress/preferences';
|
|||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { storeName } from '../../store';
|
import { storeName } from '../../store';
|
||||||
import { TrashModal } from './trash-modal';
|
import { TrashModal } from './trash-modal';
|
||||||
|
import { recordEvent } from '../../events';
|
||||||
|
|
||||||
// See:
|
// See:
|
||||||
// https://github.com/WordPress/gutenberg/blob/9601a33e30ba41bac98579c8d822af63dd961488/packages/edit-post/src/components/header/more-menu/index.js
|
// https://github.com/WordPress/gutenberg/blob/9601a33e30ba41bac98579c8d822af63dd961488/packages/edit-post/src/components/header/more-menu/index.js
|
||||||
@@ -42,8 +43,13 @@ export function MoreMenu(): JSX.Element {
|
|||||||
} }
|
} }
|
||||||
icon={ moreVertical }
|
icon={ moreVertical }
|
||||||
label={ __( 'More', 'mailpoet' ) }
|
label={ __( 'More', 'mailpoet' ) }
|
||||||
|
onToggle={ ( isOpened ) =>
|
||||||
|
recordEvent( 'header_more_menu_dropdown_toggle', {
|
||||||
|
isOpened,
|
||||||
|
} )
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{ () => (
|
{ ( { onClose } ) => (
|
||||||
<>
|
<>
|
||||||
<MenuGroup label={ _x( 'View', 'noun', 'mailpoet' ) }>
|
<MenuGroup label={ _x( 'View', 'noun', 'mailpoet' ) }>
|
||||||
<PreferenceToggleMenuItem
|
<PreferenceToggleMenuItem
|
||||||
@@ -62,6 +68,11 @@ export function MoreMenu(): JSX.Element {
|
|||||||
'Top toolbar deactivated',
|
'Top toolbar deactivated',
|
||||||
'mailpoet'
|
'mailpoet'
|
||||||
) }
|
) }
|
||||||
|
onToggle={ () =>
|
||||||
|
recordEvent(
|
||||||
|
'header_more_menu_fixed_toolbar_toggle'
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<PreferenceToggleMenuItem
|
<PreferenceToggleMenuItem
|
||||||
scope="core"
|
scope="core"
|
||||||
@@ -79,6 +90,11 @@ export function MoreMenu(): JSX.Element {
|
|||||||
'Spotlight mode deactivated',
|
'Spotlight mode deactivated',
|
||||||
'mailpoet'
|
'mailpoet'
|
||||||
) }
|
) }
|
||||||
|
onToggle={ () =>
|
||||||
|
recordEvent(
|
||||||
|
'header_more_menu_focus_mode_toggle'
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<PreferenceToggleMenuItem
|
<PreferenceToggleMenuItem
|
||||||
scope={ storeName }
|
scope={ storeName }
|
||||||
@@ -97,6 +113,11 @@ export function MoreMenu(): JSX.Element {
|
|||||||
'mailpoet'
|
'mailpoet'
|
||||||
) }
|
) }
|
||||||
shortcut={ displayShortcut.secondary( 'f' ) }
|
shortcut={ displayShortcut.secondary( 'f' ) }
|
||||||
|
onToggle={ () =>
|
||||||
|
recordEvent(
|
||||||
|
'header_more_menu_fullscreen_mode_toggle'
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</MenuGroup>
|
</MenuGroup>
|
||||||
<MenuGroup>
|
<MenuGroup>
|
||||||
@@ -109,13 +130,22 @@ export function MoreMenu(): JSX.Element {
|
|||||||
''
|
''
|
||||||
);
|
);
|
||||||
await saveEditedEmail();
|
await saveEditedEmail();
|
||||||
|
recordEvent(
|
||||||
|
'header_more_menu_restore_from_trash_button_clicked'
|
||||||
|
);
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
{ __( 'Restore from trash', 'mailpoet' ) }
|
{ __( 'Restore from trash', 'mailpoet' ) }
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
) : (
|
) : (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={ () => setShowTrashModal( true ) }
|
onClick={ () => {
|
||||||
|
setShowTrashModal( true );
|
||||||
|
recordEvent(
|
||||||
|
'header_more_menu_move_to_trash_button_clicked'
|
||||||
|
);
|
||||||
|
onClose();
|
||||||
|
} }
|
||||||
isDestructive
|
isDestructive
|
||||||
>
|
>
|
||||||
{ __( 'Move to trash', 'mailpoet' ) }
|
{ __( 'Move to trash', 'mailpoet' ) }
|
||||||
|
@@ -7,6 +7,7 @@ import {
|
|||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
import { storeName } from '../../store';
|
import { storeName } from '../../store';
|
||||||
|
import { recordEvent } from '../../events';
|
||||||
|
|
||||||
const SaveAllContent = ( { onToggle } ) => {
|
const SaveAllContent = ( { onToggle } ) => {
|
||||||
// Hacky way to change the text in the templates row of the save dropdown
|
// Hacky way to change the text in the templates row of the save dropdown
|
||||||
@@ -60,7 +61,12 @@ export function SaveAllButton() {
|
|||||||
contentClassName="mailpoet-email-editor-save-button__dropdown"
|
contentClassName="mailpoet-email-editor-save-button__dropdown"
|
||||||
renderToggle={ ( { onToggle } ) => (
|
renderToggle={ ( { onToggle } ) => (
|
||||||
<Button
|
<Button
|
||||||
onClick={ onToggle }
|
onClick={ () => {
|
||||||
|
recordEvent(
|
||||||
|
'header_save_all_button_save_button_clicked'
|
||||||
|
);
|
||||||
|
onToggle();
|
||||||
|
} }
|
||||||
variant="primary"
|
variant="primary"
|
||||||
disabled={ isSaving }
|
disabled={ isSaving }
|
||||||
>
|
>
|
||||||
|
@@ -8,6 +8,7 @@ import { useEntityProp } from '@wordpress/core-data';
|
|||||||
import { MailPoetEmailData, storeName } from '../../store';
|
import { MailPoetEmailData, storeName } from '../../store';
|
||||||
import { useSelect } from '@wordpress/data';
|
import { useSelect } from '@wordpress/data';
|
||||||
import { useContentValidation, useEditorMode } from '../../hooks';
|
import { useContentValidation, useEditorMode } from '../../hooks';
|
||||||
|
import { recordEvent } from '../../events';
|
||||||
|
|
||||||
export function SendButton() {
|
export function SendButton() {
|
||||||
const [ mailpoetEmail ] = useEntityProp(
|
const [ mailpoetEmail ] = useEntityProp(
|
||||||
@@ -41,6 +42,7 @@ export function SendButton() {
|
|||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
onClick={ () => {
|
onClick={ () => {
|
||||||
|
recordEvent( 'header_send_button_clicked' );
|
||||||
if ( validateContent() ) {
|
if ( validateContent() ) {
|
||||||
window.location.href = `admin.php?page=mailpoet-newsletters#/send/${ mailpoetEmailData.id }`;
|
window.location.href = `admin.php?page=mailpoet-newsletters#/send/${ mailpoetEmailData.id }`;
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@ import { Button, Modal } from '@wordpress/components';
|
|||||||
import { useDispatch, useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { store as coreStore } from '@wordpress/core-data';
|
import { store as coreStore } from '@wordpress/core-data';
|
||||||
import { store as noticesStore } from '@wordpress/notices';
|
import { store as noticesStore } from '@wordpress/notices';
|
||||||
|
import { recordEvent } from '../../events';
|
||||||
|
|
||||||
export function TrashModal( {
|
export function TrashModal( {
|
||||||
onClose,
|
onClose,
|
||||||
@@ -20,6 +21,7 @@ export function TrashModal( {
|
|||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
const trashCallback = async () => {
|
const trashCallback = async () => {
|
||||||
|
recordEvent( 'trash_modal_move_to_trash_button_clicked' );
|
||||||
const success = await deleteEntityRecord(
|
const success = await deleteEntityRecord(
|
||||||
'postType',
|
'postType',
|
||||||
'mailpoet_email',
|
'mailpoet_email',
|
||||||
@@ -45,6 +47,9 @@ export function TrashModal( {
|
|||||||
'An error occurred while moving the email to the trash.',
|
'An error occurred while moving the email to the trash.',
|
||||||
'mailpoet'
|
'mailpoet'
|
||||||
);
|
);
|
||||||
|
recordEvent( 'trash_modal_move_to_trash_error', {
|
||||||
|
errorMessage,
|
||||||
|
} );
|
||||||
await createErrorNotice( errorMessage, {
|
await createErrorNotice( errorMessage, {
|
||||||
type: 'snackbar',
|
type: 'snackbar',
|
||||||
isDismissible: true,
|
isDismissible: true,
|
||||||
@@ -57,8 +62,11 @@ export function TrashModal( {
|
|||||||
<Modal
|
<Modal
|
||||||
className="mailpoet-move-to-trash-modal"
|
className="mailpoet-move-to-trash-modal"
|
||||||
title={ __( 'Move to trash', 'mailpoet' ) }
|
title={ __( 'Move to trash', 'mailpoet' ) }
|
||||||
onRequestClose={ closeCallback }
|
onRequestClose={ () => {
|
||||||
focusOnMount="firstContentElement"
|
closeCallback();
|
||||||
|
recordEvent( 'trash_modal_closed' );
|
||||||
|
} }
|
||||||
|
focusOnMount
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
{ __(
|
{ __(
|
||||||
@@ -67,7 +75,13 @@ export function TrashModal( {
|
|||||||
) }
|
) }
|
||||||
</p>
|
</p>
|
||||||
<div className="mailpoet-send-preview-modal-footer">
|
<div className="mailpoet-send-preview-modal-footer">
|
||||||
<Button variant="tertiary" onClick={ closeCallback }>
|
<Button
|
||||||
|
variant="tertiary"
|
||||||
|
onClick={ () => {
|
||||||
|
closeCallback();
|
||||||
|
recordEvent( 'trash_modal_cancel_button_clicked' );
|
||||||
|
} }
|
||||||
|
>
|
||||||
{ __( 'Cancel', 'mailpoet' ) }
|
{ __( 'Cancel', 'mailpoet' ) }
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="primary" onClick={ trashCallback }>
|
<Button variant="primary" onClick={ trashCallback }>
|
||||||
|
Reference in New Issue
Block a user