Add event tracking for template select modal
MAILPOET-6365
This commit is contained in:
committed by
Oluwaseun Olorunsola
parent
69aa7b906e
commit
34a8625318
@ -25,10 +25,10 @@ import { VisualEditor } from './visual-editor/visual-editor';
|
|||||||
|
|
||||||
import { TemplateSelection } from '../template-select';
|
import { TemplateSelection } from '../template-select';
|
||||||
|
|
||||||
import { recordEvent } from '../../events';
|
import { recordEventOnce } from '../../events';
|
||||||
|
|
||||||
export function Layout() {
|
export function Layout() {
|
||||||
recordEvent( 'editor-layout-loaded' );
|
recordEventOnce( 'editor_layout_loaded' );
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isFullscreenActive,
|
isFullscreenActive,
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
} from '../../store';
|
} from '../../store';
|
||||||
import { TemplateList } from './template-list';
|
import { TemplateList } from './template-list';
|
||||||
import { TemplateCategoriesListSidebar } from './template-categories-list-sidebar';
|
import { TemplateCategoriesListSidebar } from './template-categories-list-sidebar';
|
||||||
|
import { recordEvent, recordEventOnce } from '../../events';
|
||||||
|
|
||||||
const TemplateCategories: Array< { name: TemplateCategory; label: string } > = [
|
const TemplateCategories: Array< { name: TemplateCategory; label: string } > = [
|
||||||
{
|
{
|
||||||
@ -40,6 +41,11 @@ function SelectTemplateBody( {
|
|||||||
TemplateCategories[ 1 ].name // Show the “Basic” category by default
|
TemplateCategories[ 1 ].name // Show the “Basic” category by default
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleCategorySelection = ( category: TemplateCategory ) => {
|
||||||
|
recordEvent( 'template_select_modal_category_change', { category } );
|
||||||
|
setSelectedCategory( category );
|
||||||
|
};
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
if ( hasEmailPosts ) {
|
if ( hasEmailPosts ) {
|
||||||
@ -53,7 +59,7 @@ function SelectTemplateBody( {
|
|||||||
<TemplateCategoriesListSidebar
|
<TemplateCategoriesListSidebar
|
||||||
templateCategories={ TemplateCategories }
|
templateCategories={ TemplateCategories }
|
||||||
selectedCategory={ selectedCategory }
|
selectedCategory={ selectedCategory }
|
||||||
onClickCategory={ setSelectedCategory }
|
onClickCategory={ handleCategorySelection }
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TemplateList
|
<TemplateList
|
||||||
@ -72,6 +78,9 @@ export function SelectTemplateModal( {
|
|||||||
closeCallback = null,
|
closeCallback = null,
|
||||||
previewContent = '',
|
previewContent = '',
|
||||||
} ) {
|
} ) {
|
||||||
|
const templateSelectMode = previewContent ? 'swap' : 'new';
|
||||||
|
recordEventOnce( 'template_select_modal_opened', { templateSelectMode } );
|
||||||
|
|
||||||
const [ templates, emailPosts, hasEmailPosts ] =
|
const [ templates, emailPosts, hasEmailPosts ] =
|
||||||
usePreviewTemplates( previewContent );
|
usePreviewTemplates( previewContent );
|
||||||
|
|
||||||
@ -82,6 +91,12 @@ export function SelectTemplateModal( {
|
|||||||
|
|
||||||
const postContent = template.template as unknown as EmailEditorPostType;
|
const postContent = template.template as unknown as EmailEditorPostType;
|
||||||
|
|
||||||
|
recordEvent( 'template_select_modal_template_selected', {
|
||||||
|
template,
|
||||||
|
templateSelectMode,
|
||||||
|
templateIsPostContent,
|
||||||
|
} );
|
||||||
|
|
||||||
// When we provide previewContent, we don't want to reset the blocks
|
// When we provide previewContent, we don't want to reset the blocks
|
||||||
if ( ! previewContent ) {
|
if ( ! previewContent ) {
|
||||||
void dispatch( editorStore ).resetEditorBlocks(
|
void dispatch( editorStore ).resetEditorBlocks(
|
||||||
@ -100,15 +115,23 @@ export function SelectTemplateModal( {
|
|||||||
if ( ! template ) {
|
if ( ! template ) {
|
||||||
return;
|
return;
|
||||||
} // Prevent closing when templates are not loaded
|
} // Prevent closing when templates are not loaded
|
||||||
|
recordEvent(
|
||||||
|
'template_select_modal_handle_close_without_template_selected'
|
||||||
|
);
|
||||||
handleTemplateSelection( template );
|
handleTemplateSelection( template );
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={ __( 'Start with an email preset', 'mailpoet' ) }
|
title={ __( 'Start with an email preset', 'mailpoet' ) }
|
||||||
onRequestClose={ () =>
|
onRequestClose={ () => {
|
||||||
closeCallback ? closeCallback() : handleCloseWithoutSelection()
|
recordEvent( 'template_select_modal_closed', {
|
||||||
}
|
templateSelectMode,
|
||||||
|
} );
|
||||||
|
return closeCallback
|
||||||
|
? closeCallback()
|
||||||
|
: handleCloseWithoutSelection();
|
||||||
|
} }
|
||||||
isFullScreen
|
isFullScreen
|
||||||
>
|
>
|
||||||
<MemorizedSelectTemplateBody
|
<MemorizedSelectTemplateBody
|
||||||
@ -122,7 +145,12 @@ export function SelectTemplateModal( {
|
|||||||
<Button
|
<Button
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
className="email-editor-start_from_scratch_button"
|
className="email-editor-start_from_scratch_button"
|
||||||
onClick={ () => handleCloseWithoutSelection() }
|
onClick={ () => {
|
||||||
|
recordEvent(
|
||||||
|
'template_select_modal_start_from_scratch_clicked'
|
||||||
|
);
|
||||||
|
return handleCloseWithoutSelection();
|
||||||
|
} }
|
||||||
isBusy={ ! hasTemplates }
|
isBusy={ ! hasTemplates }
|
||||||
>
|
>
|
||||||
{ __( 'Start from scratch', 'mailpoet' ) }
|
{ __( 'Start from scratch', 'mailpoet' ) }
|
||||||
|
@ -15,4 +15,15 @@ const recordEvent = ( name: string, data = {} ) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { recordEvent, EMAIL_STRING, dispatcher };
|
const recordEventOnce = ( function () {
|
||||||
|
const cachedEventName = {};
|
||||||
|
return ( name: string, data = {} ) => {
|
||||||
|
if ( cachedEventName[ name ] ) {
|
||||||
|
return; // do not execute again
|
||||||
|
}
|
||||||
|
recordEvent( name, data );
|
||||||
|
cachedEventName[ name ] = true;
|
||||||
|
};
|
||||||
|
} )();
|
||||||
|
|
||||||
|
export { recordEvent, recordEventOnce, EMAIL_STRING, dispatcher };
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export { recordEvent } from './event-pipeline';
|
export { recordEvent, recordEventOnce } from './event-pipeline';
|
||||||
export * from './event-collector';
|
export * from './event-collector';
|
||||||
|
Reference in New Issue
Block a user