Posthog integration

This commit is contained in:
2025-08-11 08:54:45 +02:00
parent 878dbc63f7
commit 1179b406b8
7 changed files with 322 additions and 76 deletions

23
pages/api/track.js Normal file
View File

@@ -0,0 +1,23 @@
// pages/api/track.js
import { PostHogClient } from "@/lib/posthog";
export default async function handler(req, res) {
const posthog = PostHogClient();
try {
const { event, properties, distinctId } = req.body;
await posthog.capture({
distinctId: distinctId || "server_event",
event: event || "default_event",
properties: properties || {},
});
await posthog.shutdown();
return res.status(200).json({ success: true });
} catch (error) {
console.error("PostHog error:", error);
return res.status(500).json({ success: false, error: error.message });
}
}