(event: E, properties: PosthogEventMap[E])
| 80 | } |
| 81 | |
| 82 | export async function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) { |
| 83 | try { |
| 84 | if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | const distinctId = await tryGetPostHogDistinctId(); |
| 89 | const posthog = await createPostHogClient(); |
| 90 | |
| 91 | const headersList = await headers(); |
| 92 | const host = headersList.get("host") ?? undefined; |
| 93 | |
| 94 | posthog.capture({ |
| 95 | event, |
| 96 | properties: { |
| 97 | ...properties, |
| 98 | sourcebot_version: SOURCEBOT_VERSION, |
| 99 | install_id: env.SOURCEBOT_INSTALL_ID, |
| 100 | $host: host, |
| 101 | }, |
| 102 | distinctId, |
| 103 | groups: { company: env.SOURCEBOT_INSTALL_ID }, |
| 104 | }); |
| 105 | } catch (error) { |
| 106 | logger.error('Failed to capture PostHog event:', error); |
| 107 | } |
| 108 | } |
no test coverage detected