1 import { useEffect } from 'react';
3 import { usePassCore } from '@proton/pass/components/Core/PassCoreProvider';
4 import type { TelemetryEvent, TelemetryEventName, TelemetryPlatform } from '@proton/pass/types/data/telemetry';
5 import isTruthy from '@proton/utils/isTruthy';
7 /** Pushes the specified telemetry event when the provided
8 * dependency array is truthy. Passing an empty dependency
9 * array will push the event when the component mounts */
10 export const useTelemetryEvent = <T extends TelemetryEventName>(
12 Values: TelemetryEvent<T>['Values'],
13 Dimensions: TelemetryEvent<T>['Dimensions'],
14 platform?: TelemetryPlatform
16 function useTelemetryEventEffect(deps: boolean[]) {
17 const { onTelemetry } = usePassCore();
20 if (deps.every(isTruthy)) onTelemetry(Event, Values, Dimensions, platform);