Back to packages list

Vals using posthog-node

Description from the NPM package:
PostHog Node.js integration
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";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import process from "node:process";
export let posthogNode = (async () => {
const { PostHog } = await import("npm:posthog-node");
const client = new PostHog(process.env.posthog_debug_key, {
host: "https://app.posthog.com",
});
client.capture({
distinctId: "andre@val.town",
event: "user signed up",
});
client.on("error", (err) => {
console.log(err);
});
await client.shutdownAsync();
// flush events:
// https://posthog.com/docs/libraries/node#using-in-a-short-lived-process-like-aws-lambda
return "ran yes";
})();
1
Next