mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-09 18:58:46 -06:00
* make all env variables required at build time * update env files * add .env.docker file with basic docker configuration * update Readme with new instructions
28 lines
785 B
TypeScript
28 lines
785 B
TypeScript
import { hashString } from "./utils";
|
|
|
|
const enabled =
|
|
process.env.NODE_ENV === "production" && process.env.POSTHOG_API_HOST && process.env.POSTHOG_API_KEY;
|
|
|
|
export const capturePosthogEvent = async (userId, eventName, properties = {}) => {
|
|
if (!enabled) {
|
|
return;
|
|
}
|
|
try {
|
|
await fetch(`${process.env.POSTHOG_API_HOST}/capture/`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
api_key: process.env.POSTHOG_API_KEY,
|
|
event: eventName,
|
|
properties: {
|
|
distinct_id: hashString(userId.toString()),
|
|
...properties,
|
|
},
|
|
timestamp: new Date().toISOString(),
|
|
}),
|
|
});
|
|
} catch (error) {
|
|
console.error("error sending posthog event:", error);
|
|
}
|
|
};
|