2022-05-09 04:40:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useRef } from '@wordpress/element';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
2022-05-10 00:58:23 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getTimeFrame } from '~/utils';
|
|
|
|
|
2022-05-09 04:40:55 +00:00
|
|
|
const useRecordCompletionTime = ( taskName: string, startTime?: number ) => {
|
|
|
|
const _startTime = useRef( startTime || window.performance.now() );
|
|
|
|
|
|
|
|
const recordCompletionTime = () => {
|
|
|
|
recordEvent( 'task_completion_time', {
|
|
|
|
task_name: taskName,
|
2022-05-10 00:58:23 +00:00
|
|
|
time: getTimeFrame( window.performance.now() - _startTime.current ),
|
2022-05-09 04:40:55 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
recordCompletionTime,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useRecordCompletionTime;
|