/** * Mixpanel events for the MCP & AI page (mcp-ai-spec §6.3). * * Telemetry opt-in (B2-1) is respected automatically: the shared client in * src/lib/mixpanel.ts is only ever initialized when the site owner consented * (`analyticsData.telemetryOptIn`), and a runtime opt-out flips the library's * own opt_out flag. Calling `track` on the uninitialized client throws, which * `safeTrack` swallows — so without consent every event below is a no-op and * nothing is sent. */ import { mixpanel } from '../../lib/mixpanel'; function safeTrack(event: string, props?: Record): void { try { mixpanel.track(event, props); } catch { // Client not initialized — no telemetry consent. Intentionally silent. } } export function trackMcpServerToggled(enabled: boolean): void { safeTrack('MCP - Server Toggled', { enabled }); } export function trackMcpAccessModeChanged(mode: string): void { safeTrack('MCP - Access Mode Changed', { mode }); } export function trackMcpTokenCreated(scope: 'read' | 'write'): void { safeTrack('MCP - Token Created', { scope }); } export function trackMcpTokenRevoked(legacy: boolean): void { safeTrack('MCP - Token Revoked', { legacy }); } export function trackMcpClientTabSelected(client: string): void { safeTrack('MCP - Client Tab Selected', { client }); } export function trackMcpSnippetCopied(client: string, withToken: boolean): void { safeTrack('MCP - Snippet Copied', { client, with_token: withToken }); } export function trackMcpPromptCopied(client: string, withToken: boolean): void { safeTrack('MCP - Setup Prompt Copied', { client, with_token: withToken }); } export function trackMcpTestConnection(result: 'pass' | 'fail' | 'error'): void { safeTrack('MCP - Test Connection', { result }); } export function trackMcpEndpointCopied(): void { safeTrack('MCP - Endpoint Copied', {}); }