* Initialize the PostHog client. * Should be called once on app startup.
()
| 196 | * Should be called once on app startup. |
| 197 | */ |
| 198 | async initialize(): Promise<void> { |
| 199 | if (this.client) { |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | const env = process.env; |
| 204 | |
| 205 | // Fast path: avoid Electron imports when telemetry is obviously disabled. |
| 206 | if (isTelemetryDisabledByEnv(env)) { |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | const isElectron = typeof process.versions.electron === "string"; |
| 211 | const isPackaged = await getElectronIsPackaged(isElectron); |
| 212 | |
| 213 | if (!shouldEnableTelemetry({ env, isElectron, isPackaged })) { |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | // Load or generate distinct ID |
| 218 | this.distinctId = await this.loadOrCreateDistinctId(); |
| 219 | |
| 220 | this.client = new PostHog(DEFAULT_POSTHOG_KEY, { |
| 221 | host: DEFAULT_POSTHOG_HOST, |
| 222 | // Avoid geo-IP enrichment (we don't need coarse location for mux telemetry) |
| 223 | disableGeoip: true, |
| 224 | }); |
| 225 | |
| 226 | console.debug("[TelemetryService] Initialized", { host: DEFAULT_POSTHOG_HOST }); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Load existing distinct ID or create a new one. |
nothing calls this directly
no test coverage detected