Posthog integration
This commit is contained in:
24
instrumentation-client.js
Normal file
24
instrumentation-client.js
Normal 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;
|
||||
Reference in New Issue
Block a user