Posthog integration
This commit is contained in:
23
pages/api/track.js
Normal file
23
pages/api/track.js
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user