feat: implement analytics tracking for desktop app events

- Added event tracking for desktop app activation and quitting.
- Introduced analytics bridge in preload script to handle user identification and event capturing.
- Updated IPC channels to support analytics-related actions.
- Enhanced analytics functionality in the main process to track user interactions and application updates.
- Integrated analytics tracking for folder watching and deep link handling.
- Improved connector setup tracking in the web application.

This commit enhances the overall analytics capabilities of the application, ensuring better user behavior insights and event tracking across both desktop and web environments.
This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-04-18 14:35:14 -07:00
parent b38a297349
commit b440610e04
18 changed files with 673 additions and 80 deletions

View file

@ -2,6 +2,7 @@ import { app, globalShortcut, Menu, nativeImage, Tray } from 'electron';
import path from 'path';
import { getMainWindow, createMainWindow } from './window';
import { getShortcuts } from './shortcuts';
import { trackEvent } from './analytics';
let tray: Tray | null = null;
let currentShortcut: string | null = null;
@ -15,14 +16,16 @@ function getTrayIcon(): nativeImage {
return img.resize({ width: 16, height: 16 });
}
function showMainWindow(): void {
let win = getMainWindow();
if (!win || win.isDestroyed()) {
win = createMainWindow('/dashboard');
function showMainWindow(source: 'tray_click' | 'tray_menu' | 'shortcut' = 'tray_click'): void {
const existing = getMainWindow();
const reopened = !existing || existing.isDestroyed();
if (reopened) {
createMainWindow('/dashboard');
} else {
win.show();
win.focus();
existing.show();
existing.focus();
}
trackEvent('desktop_main_window_shown', { source, reopened });
}
function registerShortcut(accelerator: string): void {
@ -32,7 +35,7 @@ function registerShortcut(accelerator: string): void {
}
if (!accelerator) return;
try {
const ok = globalShortcut.register(accelerator, showMainWindow);
const ok = globalShortcut.register(accelerator, () => showMainWindow('shortcut'));
if (ok) {
currentShortcut = accelerator;
} else {
@ -50,13 +53,19 @@ export async function createTray(): Promise<void> {
tray.setToolTip('SurfSense');
const contextMenu = Menu.buildFromTemplate([
{ label: 'Open SurfSense', click: showMainWindow },
{ label: 'Open SurfSense', click: () => showMainWindow('tray_menu') },
{ type: 'separator' },
{ label: 'Quit', click: () => { app.exit(0); } },
{
label: 'Quit',
click: () => {
trackEvent('desktop_tray_quit_clicked');
app.exit(0);
},
},
]);
tray.setContextMenu(contextMenu);
tray.on('double-click', showMainWindow);
tray.on('double-click', () => showMainWindow('tray_click'));
const shortcuts = await getShortcuts();
registerShortcut(shortcuts.generalAssist);