Make capturing according to serverless
This commit is contained in:
@@ -54,15 +54,7 @@ export default defineEventHandler(async (event) => {
|
||||
});
|
||||
});
|
||||
|
||||
posthog.identify({
|
||||
distinctId: String(user.id),
|
||||
properties: {
|
||||
name: user.name,
|
||||
country: user.country,
|
||||
},
|
||||
});
|
||||
|
||||
posthog.capture({
|
||||
posthog.captureImmediate({
|
||||
distinctId: String(user.id),
|
||||
event: "content generated",
|
||||
properties: {
|
||||
|
||||
@@ -20,7 +20,7 @@ export default defineEventHandler(async (event) => {
|
||||
},
|
||||
});
|
||||
|
||||
posthog.identify({
|
||||
posthog.identifyImmediate({
|
||||
distinctId: String(user!.id),
|
||||
properties: {
|
||||
name: user!.name,
|
||||
@@ -32,7 +32,7 @@ export default defineEventHandler(async (event) => {
|
||||
.delete(tables.users)
|
||||
.where(eq(tables.users.id, get(body, "object_id")));
|
||||
|
||||
posthog.capture({
|
||||
posthog.captureImmediate({
|
||||
distinctId: get(body, "object_id"),
|
||||
event: "user deleted",
|
||||
});
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
import { PostHog } from "posthog-node";
|
||||
|
||||
import { waitUntil } from "@vercel/functions";
|
||||
export default defineNitroPlugin((nitroApp) => {
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
|
||||
const posthog = new PostHog(runtimeConfig.public.posthogPublicKey, {
|
||||
host: runtimeConfig.public.posthogHost,
|
||||
defaults: runtimeConfig.public.posthogDefaults,
|
||||
flushAt: 1,
|
||||
flushInterval: 0,
|
||||
});
|
||||
|
||||
nitroApp.hooks.hook("request", (event) => {
|
||||
event.context.posthog = posthog;
|
||||
});
|
||||
|
||||
nitroApp.hooks.hook("beforeResponse", async () => {
|
||||
await posthog.shutdown();
|
||||
nitroApp.hooks.hook("beforeResponse", () => {
|
||||
waitUntil(posthog.shutdown());
|
||||
});
|
||||
|
||||
nitroApp.hooks.hook("close", async () => {
|
||||
await posthog.shutdown();
|
||||
nitroApp.hooks.hook("close", () => {
|
||||
waitUntil(posthog.shutdown());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export default defineOAuthStravaEventHandler({
|
||||
user: userPayload,
|
||||
});
|
||||
|
||||
posthog.identify({
|
||||
posthog.identifyImmediate({
|
||||
distinctId: String(user!.id),
|
||||
properties: {
|
||||
name: user!.name,
|
||||
@@ -90,7 +90,7 @@ export default defineOAuthStravaEventHandler({
|
||||
},
|
||||
});
|
||||
|
||||
posthog.capture({
|
||||
posthog.captureImmediate({
|
||||
distinctId: String(user!.id),
|
||||
event: "user logged in",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user