Back

Version 0

9/21/2023
async function capturePostHogEvent(
key: string,
host: string = "https://app.posthog.com",
distinct_id: string,
event_name: string,
properties: object = {},
) {
const { PostHog } = await import("npm:posthog-node");
const client = new PostHog(key, {
host: host,
});
client.capture({
distinctId: distinct_id,
event: event_name,
properties: properties,
});
client.on("error", (err) => {
console.log(err);
});
// flush events because this is short-lived process
await client.shutdownAsync();
return "Event captured";
}
Updated: September 18, 2024