MCPcopy Index your code
hub / github.com/21st-dev/1code / initAnalytics

Function initAnalytics

src/renderer/lib/analytics.ts:52–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50 * Initialize PostHog for renderer process
51 */
52export 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

Callers 1

AppFunction · 0.90

Calls 1

initMethod · 0.80

Tested by

no test coverage detected