fancytextstuff/pages/api/track.js

24 lines
632 B
JavaScript

// 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 });
}
}