Posthog integration

This commit is contained in:
2025-08-11 08:54:45 +02:00
parent 878dbc63f7
commit 1179b406b8
7 changed files with 322 additions and 76 deletions

24
instrumentation-client.js Normal file
View File

@@ -0,0 +1,24 @@
// instrumentation-client.js
import posthog from "posthog-js";
// envs lesen
const key = process.env.NEXT_PUBLIC_POSTHOG_KEY;
const host = process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://us.i.posthog.com";
// nur im Browser initialisieren + Doppel-Init verhindern
if (typeof window !== "undefined" && !window.__posthogInitialized) {
if (key) {
posthog.init(key, {
api_host: host,
capture_pageview: false, // Pageviews trackst du selbst
loaded: () => {
if (process.env.NODE_ENV === "development") posthog.debug();
},
});
window.__posthogInitialized = true;
} else {
console.warn("NEXT_PUBLIC_POSTHOG_KEY ist nicht gesetzt");
}
}
export default posthog;