Implement posthog

This commit is contained in:
2025-07-06 14:02:22 +03:00
parent f7d994d02e
commit 1e099d88ae
13 changed files with 209 additions and 41 deletions

View File

@@ -4,6 +4,8 @@ import { eq } from "drizzle-orm";
export default defineEventHandler(async (event) => {
await validateHookdeck(event);
const posthog = event.context.posthog;
const body = await readBody(event);
const db = useDrizzle();
@@ -11,9 +13,29 @@ export default defineEventHandler(async (event) => {
return;
}
const user = await db.query.users.findFirst({
where: (f, o) => o.eq(f.id, get(body, "object_id")),
with: {
preferences: true,
},
});
posthog.identify({
distinctId: String(user!.id),
properties: {
name: user!.name,
country: user!.country,
},
});
await db
.delete(tables.users)
.where(eq(tables.users.id, get(body, "object_id")));
posthog.capture({
distinctId: get(body, "object_id"),
event: "user deleted",
});
sendNoContent(event);
});