Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat(analytics): re-enable PostHog in ERP and MES

Raulc3b339154c68
diff --git a/apps/erp/app/entry.client.tsx b/apps/erp/app/entry.client.tsx
index 14da84d881..23fa2b4cbb 100644
--- a/apps/erp/app/entry.client.tsx
+++ b/apps/erp/app/entry.client.tsx
@@ -1,32 +1,37 @@
import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url";
-import { Fragment, startTransition } from "react";
+import { Fragment, startTransition, useEffect } from "react";
import { pdfjs } from "react-pdf";
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
+import { POSTHOG_API_HOST, POSTHOG_PROJECT_PUBLIC_KEY } from "@carbon/auth";
import { ensureLoggingConfigured } from "@carbon/logger/config.client";
+import posthog from "posthog-js";
import { hydrateRoot } from "react-dom/client";
import { HydratedRouter } from "react-router/dom";
ensureLoggingConfigured();
-// function PosthogInit() {
-// useEffect(() => {
-// if (!window?.location.href.includes("localhost")) {
-// posthog.init(POSTHOG_PROJECT_PUBLIC_KEY, {
-// api_host: POSTHOG_API_HOST
-// });
-// }
-// }, []);
-// return null;
-// }
+// The project key is what enables analytics: it is unset in local development
+// and set by the deployment. A hostname check can't stand in for that, since
+// `crbn up` serves the app from *.dev rather than localhost.
+function PosthogInit() {
+ useEffect(() => {
+ if (!POSTHOG_PROJECT_PUBLIC_KEY) return;
+
+ posthog.init(POSTHOG_PROJECT_PUBLIC_KEY, {
+ api_host: POSTHOG_API_HOST
+ });
+ }, []);
+ return null;
+}
startTransition(() => {
hydrateRoot(
document,
<Fragment>
<HydratedRouter />
- {/* <PosthogInit /> */}
+ <PosthogInit />
</Fragment>
);
});
diff --git a/apps/mes/app/entry.client.tsx b/apps/mes/app/entry.client.tsx
index bae67cb270..2dba05cf69 100644
--- a/apps/mes/app/entry.client.tsx
+++ b/apps/mes/app/entry.client.tsx
@@ -3,30 +3,35 @@ import { pdfjs } from "react-pdf";
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
+import { POSTHOG_API_HOST, POSTHOG_PROJECT_PUBLIC_KEY } from "@carbon/auth";
import { ensureLoggingConfigured } from "@carbon/logger/config.client";
-import { Fragment, startTransition } from "react";
+import posthog from "posthog-js";
+import { Fragment, startTransition, useEffect } from "react";
import { hydrateRoot } from "react-dom/client";
import { HydratedRouter } from "react-router/dom";
ensureLoggingConfigured();
-// function PosthogInit() {
-// useEffect(() => {
-// if (!window?.location.href.includes("localhost")) {
-// posthog.init(POSTHOG_PROJECT_PUBLIC_KEY, {
-// api_host: POSTHOG_API_HOST
-// });
-// }
-// }, []);
-// return null;
-// }
+// The project key is what enables analytics: it is unset in local development
+// and set by the deployment. A hostname check can't stand in for that, since
+// `crbn up` serves the app from *.dev rather than localhost.
+function PosthogInit() {
+ useEffect(() => {
+ if (!POSTHOG_PROJECT_PUBLIC_KEY) return;
+
+ posthog.init(POSTHOG_PROJECT_PUBLIC_KEY, {
+ api_host: POSTHOG_API_HOST
+ });
+ }, []);
+ return null;
+}
startTransition(() => {
hydrateRoot(
document,
<Fragment>
<HydratedRouter />
- {/* <PosthogInit /> */}
+ <PosthogInit />
</Fragment>
);
});