From 835b1e73a14df7d40d72034e80a5953232c27453 Mon Sep 17 00:00:00 2001 From: Joshua Flowers Date: Thu, 21 Apr 2022 12:01:56 -0700 Subject: [PATCH] Add tracks to task list reminder bar --- .../tasks/reminder-bar/reminder-bar.tsx | 57 ++++++++++++++----- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/plugins/woocommerce-admin/client/tasks/reminder-bar/reminder-bar.tsx b/plugins/woocommerce-admin/client/tasks/reminder-bar/reminder-bar.tsx index ea8ccd4c771..ba8932a46e9 100644 --- a/plugins/woocommerce-admin/client/tasks/reminder-bar/reminder-bar.tsx +++ b/plugins/woocommerce-admin/client/tasks/reminder-bar/reminder-bar.tsx @@ -15,6 +15,7 @@ import { close as closeIcon } from '@wordpress/icons'; import interpolateComponents from '@automattic/interpolate-components'; import { useEffect } from '@wordpress/element'; import { getQuery } from '@woocommerce/navigation'; +import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies @@ -29,11 +30,19 @@ type ReminderBarProps = { type ReminderTextProps = { remainingCount: number | null; + tracksProps: { + completed: number; + is_homescreen: boolean; + is_active_task_page: boolean; + }; }; const REMINDER_BAR_HIDDEN_OPTION = 'woocommerce_task_list_reminder_bar_hidden'; -const ReminderText: React.FC< ReminderTextProps > = ( { remainingCount } ) => { +const ReminderText: React.FC< ReminderTextProps > = ( { + remainingCount, + tracksProps, +} ) => { const translationText = remainingCount === 1 ? /* translators: 1: remaining tasks count */ @@ -56,6 +65,12 @@ const ReminderText: React.FC< ReminderTextProps > = ( { remainingCount } ) => { setupLink: ( + recordEvent( + 'tasklist_reminder_bar_continue', + tracksProps + ) + } type="wp-admin" /> ), @@ -123,7 +138,7 @@ export const TasksReminderBar: React.FC< ReminderBarProps > = ( { getQuery().page && getQuery().page === 'wc-admin' && ! getQuery().path; const isActiveTaskPage = Boolean( getQuery().wc_onboarding_active_task ); - const hideReminderBar = + const isHidden = loading || taskListHidden || taskListComplete || @@ -134,24 +149,40 @@ export const TasksReminderBar: React.FC< ReminderBarProps > = ( { useEffect( () => { updateBodyMargin(); - }, [ hideReminderBar, updateBodyMargin ] ); + }, [ isHidden, updateBodyMargin ] ); - if ( hideReminderBar ) { + const tracksProps = { + completed: completedTasksCount, + is_homescreen: isHomescreen, + is_active_task_page: isActiveTaskPage, + }; + + useEffect( () => { + if ( loading || isHidden ) { + return; + } + + recordEvent( 'tasklist_reminder_bar_view', tracksProps ); + }, [ isHidden, loading ] ); + + const onClose = () => { + updateOptions( { + [ REMINDER_BAR_HIDDEN_OPTION ]: 'yes', + } ); + recordEvent( 'tasklist_reminder_bar_close', tracksProps ); + }; + + if ( isHidden ) { return null; } return (
- -
); };