Implement posthog
This commit is contained in:
@@ -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
20
plugins/posthog.client.ts
Normal 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,
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user