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

@@ -1,19 +0,0 @@
import { init, trackEvent } from "@aptabase/web";
export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig();
nuxtApp.hook("app:mounted", () => {
init(config.public.aptabaseAppKey, { isDebug: import.meta.dev });
});
nuxtApp.hook("page:finish", () => {
const route = useRoute();
trackEvent("page_view", {
path: route.path,
name: String(route.name),
redirectedFrom: String(route.redirectedFrom),
});
});
});

20
plugins/posthog.client.ts Normal file
View File

@@ -0,0 +1,20 @@
import posthog from "posthog-js";
export default defineNuxtPlugin(() => {
const runtimeConfig = useRuntimeConfig();
const posthogClient = posthog.init(runtimeConfig.public.posthogPublicKey, {
api_host: runtimeConfig.public.posthogHost,
//@ts-expect-error typing is more explicit than what it should
defaults: runtimeConfig.public.posthogDefaults,
loaded: (posthog) => {
if (import.meta.env.MODE === "development") posthog.debug();
},
});
return {
provide: {
posthog: () => posthogClient,
},
};
});