1 import useApi from '@proton/components/hooks/useApi';
2 import { TelemetryMailComposerAssistantEvents, TelemetryMeasurementGroups } from '@proton/shared/lib/api/telemetry';
6 GENERATION_SELECTION_TYPE,
9 } from '@proton/shared/lib/assistant';
10 import { sendTelemetryReport } from '@proton/shared/lib/helpers/metrics';
12 import type { ASSISTANT_INSERT_TYPE } from 'proton-mail/hooks/assistant/useComposerAssistantGenerate';
14 const useAssistantTelemetry = () => {
17 const sendShowAssistantReport = () => {
18 void sendTelemetryReport({
20 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
21 event: TelemetryMailComposerAssistantEvents.show_assistant,
25 const sendFreeTrialStart = () => {
26 void sendTelemetryReport({
28 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
29 event: TelemetryMailComposerAssistantEvents.free_trial_start,
33 const sendDownloadAssistantReport = (downloadTime: number) => {
34 void sendTelemetryReport({
36 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
37 event: TelemetryMailComposerAssistantEvents.download_model,
39 download_time: downloadTime,
44 const sendUseAnswerAssistantReport = (insertionType: ASSISTANT_INSERT_TYPE) => {
45 void sendTelemetryReport({
47 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
48 event: TelemetryMailComposerAssistantEvents.use_answer,
50 insertion_type: insertionType,
55 const sendNotUseAnswerAssistantReport = () => {
56 void sendTelemetryReport({
58 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
59 event: TelemetryMailComposerAssistantEvents.not_use_answer,
63 const sendRequestAssistantReport = ({
71 assistantType: ASSISTANT_TYPE;
72 generationType: GENERATION_TYPE;
73 selectionType: GENERATION_SELECTION_TYPE;
74 ingestionTime: number;
75 generationTime: number;
76 tokensGenerated: number;
78 void sendTelemetryReport({
80 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
81 event: TelemetryMailComposerAssistantEvents.request_assistant,
83 ingestion_time: ingestionTime,
84 generation_time: generationTime,
85 tokens_generated: tokensGenerated,
88 assistant_type: assistantType,
89 generation_type: generationType,
90 selection_type: selectionType,
95 const sendAssistantErrorReport = ({
99 assistantType: ASSISTANT_TYPE;
100 errorType: ERROR_TYPE;
102 void sendTelemetryReport({
104 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
105 event: TelemetryMailComposerAssistantEvents.assistant_error,
107 assistant_type: assistantType,
108 error_type: errorType,
113 const sendSendMessageAssistantReport = () => {
114 void sendTelemetryReport({
116 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
117 event: TelemetryMailComposerAssistantEvents.send_message,
121 const sendPauseDownloadAssistantReport = () => {
122 void sendTelemetryReport({
124 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
125 event: TelemetryMailComposerAssistantEvents.pause_download,
129 const sendLoadModelAssistantReport = (loadTime: number) => {
130 void sendTelemetryReport({
132 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
133 event: TelemetryMailComposerAssistantEvents.load_model,
140 const sendUnloadModelAssistantReport = () => {
141 void sendTelemetryReport({
143 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
144 event: TelemetryMailComposerAssistantEvents.unload_model,
148 const sendIncompatibleAssistantReport = ({
151 incompatibilityType: INCOMPATIBILITY_TYPE;
153 void sendTelemetryReport({
155 measurementGroup: TelemetryMeasurementGroups.mailComposerAssistant,
156 event: TelemetryMailComposerAssistantEvents.incompatible_assistant,
158 incompatibility_type: incompatibilityType,
164 sendShowAssistantReport,
166 sendDownloadAssistantReport,
167 sendUseAnswerAssistantReport,
168 sendNotUseAnswerAssistantReport,
169 sendRequestAssistantReport,
170 sendAssistantErrorReport,
171 sendSendMessageAssistantReport,
172 sendPauseDownloadAssistantReport,
173 sendLoadModelAssistantReport,
174 sendUnloadModelAssistantReport,
175 sendIncompatibleAssistantReport,
179 export default useAssistantTelemetry;