fix: guard PostHog init behind production check
Build and Push Image / docker (push) Failing after 17s
Build and Push Image / docker (push) Failing after 17s
Only initialize PostHog in production to avoid noise and unnecessary tracking during development.
This commit is contained in:
+23
-22
@@ -1,27 +1,28 @@
|
||||
import posthog from "posthog-js";
|
||||
|
||||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN!, {
|
||||
api_host: "/i",
|
||||
ui_host: "https://us.posthog.com",
|
||||
defaults: "2026-01-30",
|
||||
capture_exceptions: true,
|
||||
debug: process.env.ENVIRONMENT === "development",
|
||||
if (process.env.NODE_ENV === "production")
|
||||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN!, {
|
||||
api_host: "/i",
|
||||
ui_host: "https://us.posthog.com",
|
||||
defaults: "2026-01-30",
|
||||
capture_exceptions: true,
|
||||
debug: process.env.ENVIRONMENT === "development",
|
||||
|
||||
before_send: (event) => {
|
||||
if (event?.event === "$exception") {
|
||||
const exceptionList = event.properties.$exception_list || [];
|
||||
const exception = exceptionList[0];
|
||||
if (exception) {
|
||||
if (
|
||||
exception.$exception_source?.includes("posthog") ||
|
||||
exception.value?.includes("posthog") ||
|
||||
exception.value?.includes("__ph_opt_in_out") ||
|
||||
exception.value === "NEXT_REDIRECT"
|
||||
) {
|
||||
return null;
|
||||
before_send: (event) => {
|
||||
if (event?.event === "$exception") {
|
||||
const exceptionList = event.properties.$exception_list || [];
|
||||
const exception = exceptionList[0];
|
||||
if (exception) {
|
||||
if (
|
||||
exception.$exception_source?.includes("posthog") ||
|
||||
exception.value?.includes("posthog") ||
|
||||
exception.value?.includes("__ph_opt_in_out") ||
|
||||
exception.value === "NEXT_REDIRECT"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return event;
|
||||
},
|
||||
});
|
||||
return event;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user