2024-09-17 04:37:34 +00:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { CaptureOptions } from "posthog-js";
|
|
|
|
|
import posthog from "posthog-js";
|
|
|
|
|
import { PosthogEvent, PosthogEventMap } from "../lib/posthogEvents";
|
2024-10-17 18:50:07 +00:00
|
|
|
import { NEXT_PUBLIC_SOURCEBOT_VERSION } from "@/lib/environment.client";
|
2024-09-17 04:37:34 +00:00
|
|
|
|
|
|
|
|
export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E], options?: CaptureOptions) {
|
|
|
|
|
if(!options) {
|
|
|
|
|
options = {};
|
|
|
|
|
}
|
|
|
|
|
options.send_instantly = true;
|
2024-10-17 18:50:07 +00:00
|
|
|
posthog.capture(event, {
|
|
|
|
|
...properties,
|
|
|
|
|
sourcebot_version: NEXT_PUBLIC_SOURCEBOT_VERSION,
|
|
|
|
|
}, options);
|
2024-09-17 04:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Captures a distinct action as a event and forwards it to the event service
|
|
|
|
|
* (i.e., PostHog).
|
|
|
|
|
*
|
|
|
|
|
* @returns A callback for capturing events.
|
|
|
|
|
* @see: https://posthog.com/docs/libraries/js#capturing-events
|
|
|
|
|
*/
|
|
|
|
|
const useCaptureEvent = () => {
|
|
|
|
|
return captureEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default useCaptureEvent;
|