()
| 67 | * Lazily generates a UUID on first call and persists it. |
| 68 | */ |
| 69 | export async function getOrCreateAnonymousId(): Promise<string> { |
| 70 | // Return cached value if available |
| 71 | if (anonymousId) { |
| 72 | return anonymousId; |
| 73 | } |
| 74 | |
| 75 | // Try to load from config |
| 76 | const config = await getTelemetryConfig(); |
| 77 | if (config.anonymousId) { |
| 78 | anonymousId = config.anonymousId; |
| 79 | return anonymousId; |
| 80 | } |
| 81 | |
| 82 | // Generate new UUID and persist |
| 83 | anonymousId = randomUUID(); |
| 84 | await updateTelemetryConfig({ anonymousId }); |
| 85 | return anonymousId; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get the PostHog client instance. |
no test coverage detected