2023-03-29 06:54:19 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
// jitsu
|
|
|
|
import { createClient } from "@jitsu/nextjs";
|
|
|
|
|
2023-09-14 10:35:31 +00:00
|
|
|
const jitsuClient = createClient({
|
|
|
|
key: process.env.JITSU_TRACKER_ACCESS_KEY || "",
|
|
|
|
tracking_host: process.env.JITSU_TRACKER_HOST || "",
|
2023-03-29 06:54:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
2023-06-06 16:06:00 +00:00
|
|
|
const { eventName, user, extra } = req.body;
|
2023-03-29 06:54:19 +00:00
|
|
|
|
|
|
|
if (!eventName) {
|
|
|
|
return res.status(400).json({ message: "Bad request" });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!user) return res.status(401).json({ message: "Unauthorized" });
|
|
|
|
|
2023-09-14 10:35:31 +00:00
|
|
|
jitsuClient
|
2023-04-03 11:07:19 +00:00
|
|
|
.id({
|
2023-09-14 10:35:31 +00:00
|
|
|
id: user?.id,
|
|
|
|
email: user?.email,
|
|
|
|
first_name: user?.first_name,
|
|
|
|
last_name: user?.last_name,
|
2023-08-08 07:31:43 +00:00
|
|
|
display_name: user?.display_name,
|
2023-04-03 11:07:19 +00:00
|
|
|
})
|
2023-03-29 06:54:19 +00:00
|
|
|
.then(() => {
|
2023-09-14 10:35:31 +00:00
|
|
|
jitsuClient.track(eventName, {
|
2023-03-29 06:54:19 +00:00
|
|
|
...extra,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json({ message: "success" });
|
|
|
|
}
|