add: lys hub tracks (#46462)
* add: lys hub tracks * moved tasks object up
This commit is contained in:
parent
5db25ea616
commit
2bd388057f
|
@ -93,6 +93,9 @@ export const Congrats = ( {
|
|||
</span>
|
||||
<Button
|
||||
onClick={ () => {
|
||||
recordEvent(
|
||||
'launch_your_store_congrats_back_to_home_click'
|
||||
);
|
||||
navigateTo( { url: '/' } );
|
||||
} }
|
||||
className="back-to-home-button"
|
||||
|
@ -125,7 +128,7 @@ export const Congrats = ( {
|
|||
ref={ copyClipboardRef }
|
||||
onClick={ () => {
|
||||
recordEvent(
|
||||
'launch_you_store_congrats_copy_store_link_click'
|
||||
'launch_your_store_congrats_copy_store_link_click'
|
||||
);
|
||||
} }
|
||||
>
|
||||
|
@ -136,7 +139,7 @@ export const Congrats = ( {
|
|||
variant="primary"
|
||||
onClick={ () => {
|
||||
recordEvent(
|
||||
'launch_you_store_congrats_preview_store_click'
|
||||
'launch_your_store_congrats_preview_store_click'
|
||||
);
|
||||
window.open( homeUrl, '_blank' );
|
||||
} }
|
||||
|
@ -256,8 +259,8 @@ export const Congrats = ( {
|
|||
onClick={ () => {
|
||||
recordEvent(
|
||||
isWooExpress
|
||||
? 'launch_you_store_congrats_survey_click'
|
||||
: 'launch_you_store_on_core_congrats_survey_click'
|
||||
? 'launch_your_store_congrats_survey_click'
|
||||
: 'launch_your_store_on_core_congrats_survey_click'
|
||||
);
|
||||
sendData();
|
||||
} }
|
||||
|
|
|
@ -16,6 +16,7 @@ import SidebarNavigationItem from '@wordpress/edit-site/build-module/components/
|
|||
*/
|
||||
import { createStorageUtils } from '~/utils/localStorage';
|
||||
import { taskCompleteIcon, taskIcons } from './components/icons';
|
||||
import { recordEvent } from '@woocommerce/tracks';
|
||||
|
||||
const SEVEN_DAYS_IN_SECONDS = 60 * 60 * 24 * 7;
|
||||
export const LYS_RECENTLY_ACTIONED_TASKS_KEY = 'lys_recently_actioned_tasks';
|
||||
|
@ -70,6 +71,10 @@ export const getLysTasklist = async () => {
|
|||
return {
|
||||
...tasklist[ 0 ],
|
||||
tasks: visibleTasks,
|
||||
recentlyActionedTasks,
|
||||
fullLysTaskList: tasklist[ 0 ].tasks.filter( ( task ) =>
|
||||
filteredTasks.includes( task.id )
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -79,6 +84,9 @@ export function taskClickedAction( event: {
|
|||
} ) {
|
||||
const recentlyActionedTasks = getRecentlyActionedTasks() ?? [];
|
||||
saveRecentlyActionedTask( [ ...recentlyActionedTasks, event.task.id ] );
|
||||
recordEvent( 'launch_your_store_hub_task_clicked', {
|
||||
task: event.task.id,
|
||||
} );
|
||||
if ( event.task.actionUrl ) {
|
||||
navigateTo( { url: event.task.actionUrl } );
|
||||
} else {
|
||||
|
|
|
@ -15,6 +15,7 @@ import classnames from 'classnames';
|
|||
import { getQuery, navigateTo } from '@woocommerce/navigation';
|
||||
import { OPTIONS_STORE_NAME, TaskListType, TaskType } from '@woocommerce/data';
|
||||
import { dispatch } from '@wordpress/data';
|
||||
import { recordEvent } from '@woocommerce/tracks';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -25,13 +26,20 @@ import type { mainContentMachine } from '../main-content/xstate';
|
|||
import { updateQueryParams, createQueryParamsListener } from '../common';
|
||||
import { taskClickedAction, getLysTasklist } from './tasklist';
|
||||
import { fetchCongratsData } from '../main-content/pages/launch-store-success/services';
|
||||
import { getTimeFrame } from '~/utils';
|
||||
|
||||
export type LYSAugmentedTaskListType = TaskListType & {
|
||||
recentlyActionedTasks: string[];
|
||||
fullLysTaskList: TaskType[];
|
||||
};
|
||||
|
||||
export type SidebarMachineContext = {
|
||||
externalUrl: string | null;
|
||||
mainContentMachineRef: ActorRefFrom< typeof mainContentMachine >;
|
||||
tasklist?: TaskListType;
|
||||
tasklist?: LYSAugmentedTaskListType;
|
||||
testOrderCount: number;
|
||||
removeTestOrders?: boolean;
|
||||
launchStoreAttemptTimestamp?: number;
|
||||
launchStoreError?: {
|
||||
message: string;
|
||||
};
|
||||
|
@ -63,6 +71,45 @@ const launchStoreAction = async () => {
|
|||
throw new Error( JSON.stringify( results ) );
|
||||
};
|
||||
|
||||
const recordStoreLaunchAttempt = ( {
|
||||
context,
|
||||
}: {
|
||||
context: SidebarMachineContext;
|
||||
} ) => {
|
||||
const total_count = context.tasklist?.fullLysTaskList.length || 0;
|
||||
const incomplete_tasks =
|
||||
context.tasklist?.tasks
|
||||
.filter( ( task ) => ! task.isComplete )
|
||||
.map( ( task ) => task.id ) || [];
|
||||
|
||||
const completed =
|
||||
context.tasklist?.fullLysTaskList
|
||||
.filter( ( task ) => task.isComplete )
|
||||
.map( ( task ) => task.id ) || [];
|
||||
|
||||
const tasks_completed_in_lys = completed.filter( ( task ) =>
|
||||
context.tasklist?.recentlyActionedTasks.includes( task )
|
||||
); // recently actioned tasks can include incomplete tasks
|
||||
|
||||
recordEvent( 'launch_your_store_hub_store_launch_attempted', {
|
||||
tasks_total_count: total_count, // all lys eligible tasks
|
||||
tasks_completed: completed, // all lys eligible tasks that are completed
|
||||
tasks_completed_count: completed.length,
|
||||
tasks_completed_in_lys,
|
||||
tasks_completed_in_lys_count: tasks_completed_in_lys.length,
|
||||
incomplete_tasks,
|
||||
incomplete_tasks_count: incomplete_tasks.length,
|
||||
delete_test_orders: context.removeTestOrders || false,
|
||||
} );
|
||||
return performance.now();
|
||||
};
|
||||
|
||||
const recordStoreLaunchResults = ( timestamp: number, success: boolean ) => {
|
||||
recordEvent( 'launch_your_store_hub_store_launch_results', {
|
||||
success,
|
||||
duration: getTimeFrame( performance.now() - timestamp ),
|
||||
} );
|
||||
};
|
||||
export const sidebarMachine = setup( {
|
||||
types: {} as {
|
||||
context: SidebarMachineContext;
|
||||
|
@ -104,6 +151,18 @@ export const sidebarMachine = setup( {
|
|||
windowHistoryBack: () => {
|
||||
window.history.back();
|
||||
},
|
||||
recordStoreLaunchAttempt: assign( {
|
||||
launchStoreAttemptTimestamp: recordStoreLaunchAttempt,
|
||||
} ),
|
||||
recordStoreLaunchResults: (
|
||||
{ context },
|
||||
{ success }: { success: boolean }
|
||||
) => {
|
||||
recordStoreLaunchResults(
|
||||
context.launchStoreAttemptTimestamp || 0,
|
||||
success
|
||||
);
|
||||
},
|
||||
},
|
||||
guards: {
|
||||
hasSidebarLocation: (
|
||||
|
@ -192,20 +251,39 @@ export const sidebarMachine = setup( {
|
|||
initial: 'launching',
|
||||
states: {
|
||||
launching: {
|
||||
entry: assign( { launchStoreError: undefined } ), // clear the errors if any from previously
|
||||
entry: [
|
||||
assign( { launchStoreError: undefined } ), // clear the errors if any from previously
|
||||
'recordStoreLaunchAttempt',
|
||||
],
|
||||
invoke: {
|
||||
src: 'updateLaunchStoreOptions',
|
||||
onDone: {
|
||||
target: '#storeLaunchSuccessful',
|
||||
actions: [
|
||||
{
|
||||
type: 'recordStoreLaunchResults',
|
||||
params: { success: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
onError: {
|
||||
actions: assign( {
|
||||
launchStoreError: ( { event } ) => {
|
||||
return {
|
||||
message: JSON.stringify( event.error ), // for some reason event.error is an empty object, worth investigating if we decide to use the error message somewhere
|
||||
};
|
||||
actions: [
|
||||
assign( {
|
||||
launchStoreError: ( { event } ) => {
|
||||
return {
|
||||
message: JSON.stringify(
|
||||
event.error
|
||||
), // for some reason event.error is an empty object, worth investigating if we decide to use the error message somewhere
|
||||
};
|
||||
},
|
||||
} ),
|
||||
{
|
||||
type: 'recordStoreLaunchResults',
|
||||
params: {
|
||||
success: false,
|
||||
},
|
||||
},
|
||||
} ),
|
||||
],
|
||||
target: '#launchYourStoreHub',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: add
|
||||
|
||||
Added tracks events for LYS hub
|
Loading…
Reference in New Issue