| 50 | * Initialize PostHog for renderer process |
| 51 | */ |
| 52 | export async function initAnalytics() { |
| 53 | // Skip in development mode |
| 54 | if (isDev) return |
| 55 | |
| 56 | if (initialized) return |
| 57 | |
| 58 | // Skip if no PostHog key configured |
| 59 | if (!POSTHOG_DESKTOP_KEY) { |
| 60 | console.log("[Analytics] Skipping PostHog initialization (no key configured)") |
| 61 | return |
| 62 | } |
| 63 | |
| 64 | // Get app info from main process |
| 65 | try { |
| 66 | if (window.desktopApi?.getVersion) { |
| 67 | appVersion = await window.desktopApi.getVersion() |
| 68 | } |
| 69 | if (window.desktopApi?.platform) { |
| 70 | appPlatform = window.desktopApi.platform |
| 71 | } |
| 72 | if (window.desktopApi?.arch) { |
| 73 | appArch = window.desktopApi.arch |
| 74 | } |
| 75 | } catch (error) { |
| 76 | console.warn("[Analytics] Failed to get app info:", error) |
| 77 | } |
| 78 | |
| 79 | posthog.init(POSTHOG_DESKTOP_KEY, { |
| 80 | api_host: POSTHOG_HOST, |
| 81 | // Disable automatic tracking - we track manually |
| 82 | autocapture: false, |
| 83 | capture_pageview: false, |
| 84 | capture_pageleave: false, |
| 85 | disable_session_recording: true, |
| 86 | // Privacy settings |
| 87 | person_profiles: "identified_only", |
| 88 | persistence: "localStorage", |
| 89 | }) |
| 90 | |
| 91 | initialized = true |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Capture an analytics event |