1 import { TelemetryInboxDestkopEvents, TelemetryMeasurementGroups } from '@proton/shared/lib/api/telemetry';
2 import { sendTelemetryReport } from '@proton/shared/lib/helpers/metrics';
3 import type { Api } from '@proton/shared/lib/interfaces';
5 import type { DailyStatsReport } from './DailyStats';
6 import type { DefaultProtocol } from './DefaultProtocol';
7 import { getInboxDesktopInfo, invokeInboxDesktopIPC } from './ipcHelpers';
9 type MailtoDimensions = {
10 isDefault: 'true' | 'false' | 'unknown';
11 changeSinceLast: 'yes_to_no' | 'no_to_yes' | 'no_change';
14 export const getDefaultMailto = () => getInboxDesktopInfo('defaultMailto');
15 export const checkDefaultMailto = () => invokeInboxDesktopIPC({ type: 'checkDefaultMailtoAndSignal' });
16 const defaultMailtoTelemetryReported = (timestamp: number) =>
17 invokeInboxDesktopIPC({ type: 'defaultMailtoTelemetryReported', payload: timestamp });
19 export const sendMailtoTelemetry = (api: Api, data: DefaultProtocol, timestamp: number) => {
20 const dimensions: MailtoDimensions = {
22 changeSinceLast: 'no_change',
25 if (data.wasChecked) {
26 dimensions.isDefault = data.isDefault ? 'true' : 'false';
28 if (data.lastReport.wasDefault && !data.isDefault) {
29 dimensions.changeSinceLast = 'yes_to_no';
31 if (!data.lastReport.wasDefault && data.isDefault) {
32 dimensions.changeSinceLast = 'no_to_yes';
36 void sendTelemetryReport({
38 measurementGroup: TelemetryMeasurementGroups.mailDesktopDefaultMailto,
39 event: TelemetryInboxDestkopEvents.mailto_heartbeat,
43 void defaultMailtoTelemetryReported(timestamp);
46 export const getDailyStats = () => getInboxDesktopInfo('dailyStats');
47 export const checkDailyStats = () => invokeInboxDesktopIPC({ type: 'checkDailyStatsAndSignal' });
48 const dailyStatsReported = (timestamp: number) =>
49 invokeInboxDesktopIPC({ type: 'dailyStatsReported', payload: timestamp });
51 export const sendDailyTelemetry = (api: Api, data: DailyStatsReport, timestamp: number) => {
52 void sendTelemetryReport({
54 measurementGroup: TelemetryMeasurementGroups.mailDesktopDailyStats,
55 event: TelemetryInboxDestkopEvents.daily_stats_heartbeat,
59 void dailyStatsReported(timestamp);