2023-03-29 06:54:19 +00:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
|
|
|
|
// jitsu
|
|
|
|
import { createClient } from "@jitsu/nextjs";
|
|
|
|
import { convertCookieStringToObject } from "lib/cookie";
|
|
|
|
|
|
|
|
const jitsu = createClient({
|
2023-03-29 11:04:56 +00:00
|
|
|
key: process.env.TRACKER_ACCESS_KEY || "",
|
2023-03-29 06:54:19 +00:00
|
|
|
tracking_host: "https://t.jitsu.com",
|
|
|
|
});
|
|
|
|
|
|
|
|
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" });
|
|
|
|
|
|
|
|
// TODO: cache user info
|
|
|
|
|
|
|
|
jitsu
|
2023-04-03 11:07:19 +00:00
|
|
|
.id({
|
|
|
|
id: user.id,
|
|
|
|
email: user.email,
|
|
|
|
first_name: user.first_name,
|
|
|
|
last_name: user.last_name,
|
|
|
|
})
|
2023-03-29 06:54:19 +00:00
|
|
|
.then(() => {
|
|
|
|
jitsu.track(eventName, {
|
|
|
|
...extra,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json({ message: "success" });
|
|
|
|
}
|