Public
Script
March 25, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export async function capturePostHogEvent(
key: string,
distinct_id: string,
event_name: string,
properties: object = {},
host: string = "https://app.posthog.com",
) {
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.shutdown();
return "Event captured";
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 25, 2024