( distinctId: string, event: E, properties: PostHogEventMap[E], options?: CaptureOptions )
| 62 | * @param options - Optional groups, $set, and $set_once person properties. |
| 63 | */ |
| 64 | export function captureServerEvent<E extends PostHogEventName>( |
| 65 | distinctId: string, |
| 66 | event: E, |
| 67 | properties: PostHogEventMap[E], |
| 68 | options?: CaptureOptions |
| 69 | ): void { |
| 70 | try { |
| 71 | const client = getClient() |
| 72 | if (!client) return |
| 73 | |
| 74 | const contextRequestId = getRequestContext()?.requestId |
| 75 | const props = properties as Record<string, unknown> |
| 76 | client.capture({ |
| 77 | distinctId, |
| 78 | event, |
| 79 | properties: { |
| 80 | ...properties, |
| 81 | ...(contextRequestId && !('request_id' in props) ? { request_id: contextRequestId } : {}), |
| 82 | ...(options?.groups ? { $groups: options.groups } : {}), |
| 83 | ...(options?.set ? { $set: options.set } : {}), |
| 84 | ...(options?.setOnce ? { $set_once: options.setOnce } : {}), |
| 85 | }, |
| 86 | }) |
| 87 | } catch (error) { |
| 88 | logger.warn('Failed to capture PostHog server event', { event, error }) |
| 89 | } |
| 90 | } |
no test coverage detected