codeburn/app/renderer/lib/track.ts
iamtoruk 2b06a3a5e4 feat(app): send the CLI's telemetry snapshot and a few interaction events
The daily usage_snapshot event now carries the payload's
telemetrySnapshot verbatim, with the old renderer builder kept as the
fallback for an older CLI. Five name-only events join it: optimize_apply
with the fix kind, plan_set with the provider, export with the format,
compare_view with the two models, and settings_change with the setting
and its enum or boolean value.

The props sanitizer had allowed one level of arrays of flat objects and
would have stripped the snapshot's nested model and task rows; it walks
plain objects recursively now, five levels deep at most and a thousand
leaves per event, leaves still short strings, finite numbers and
booleans only. The README gains a Telemetry section listing every event
and field and how to turn it off.
2026-09-03 01:18:23 -07:00

13 lines
712 B
TypeScript

import { codeburn } from './ipc'
/** Fire-and-forget consent-gated telemetry. The main process decides whether
* anything is sent (see app/electron/telemetry.ts); the renderer only names the
* event. Nothing about it is load-bearing, so a preload that predates the
* bridge method, returns nothing, or throws must degrade to "no tracking"
* rather than take a click handler down with it. */
export function trackEvent(name: string, props?: Record<string, unknown>): void {
if (typeof codeburn.telemetryTrack !== 'function') return
try {
void Promise.resolve(codeburn.telemetryTrack(name, props)).catch(() => {})
} catch { /* a bridge that throws synchronously is still just no tracking */ }
}