1 import { useRef } from 'react';
3 import metrics from '@proton/metrics';
4 import useFlag from '@proton/unleash/useFlag';
6 import type { CalendarViewEventTemporaryEvent } from '../containers/calendar/interface';
7 import { getNESTData } from './calendarMetricsHelper';
10 startTime: DOMHighResTimeStamp;
13 hasConferenceData: boolean;
16 export const useCalendarNESTMetric = () => {
17 const metricRef = useRef<NESTMetric | undefined>(undefined);
18 const calendarMetricsEnabled = useFlag('CalendarMetrics');
20 const startNESTMetric = (event: CalendarViewEventTemporaryEvent, isCreatingEvent: boolean) => {
21 if (!calendarMetricsEnabled || !isCreatingEvent) {
25 const startTime = performance.now();
29 ...getNESTData(event),
33 const stopNESTMetric = (isCreatingEvent: boolean) => {
34 if (!calendarMetricsEnabled || !isCreatingEvent || !metricRef.current) {
38 const endTime = performance.now();
39 const duration = (endTime - metricRef.current.startTime) / 1000;
41 void metrics.calendar_new_event_setup_time_histogram.observe({
44 recurring: metricRef.current.isRecurring ? 'true' : 'false',
45 has_conference_data: metricRef.current.hasConferenceData ? 'true' : 'false',
46 has_invitees: metricRef.current.hasInvitees ? 'true' : 'false',
50 metricRef.current = undefined;