1212// be production, indexable builds too, so the gates above alone would let their
1313// traffic reach the real PostHog project. Analytics initializes ONLY on the real
1414// site (agenta.ai / www.agenta.ai); every *.workers.dev preview host is skipped.
15- const posthogKey = import .meta .env .PUBLIC_POSTHOG_KEY ;
16- const noindex = import .meta .env .PUBLIC_NOINDEX === " true" ;
15+ //
16+ // This script must stay BUNDLED (no define:vars / is:inline): an inline script's
17+ // import("posthog-js") is a bare specifier the browser cannot resolve, so
18+ // analytics silently never loads. Vite statically replaces the PUBLIC_* env
19+ // reads in bundled client code, which is why no value handoff is needed.
1720---
1821
19- <script define:vars ={ { posthogKey , noindex }} >
22+ <script >
23+ import posthog from "posthog-js";
24+
25+ const posthogKey = import.meta.env.PUBLIC_POSTHOG_KEY;
26+ const noindex = import.meta.env.PUBLIC_NOINDEX === "true";
27+
2028 const dnt =
2129 navigator.doNotTrack === "1" ||
2230 // @ts-expect-error legacy vendor-prefixed flags
@@ -31,16 +39,14 @@ const noindex = import.meta.env.PUBLIC_NOINDEX === "true";
3139 if (posthogKey && !noindex && isRealSite && !dnt && !window.__agPosthogInit) {
3240 // @ts-expect-error one-time guard on window
3341 window.__agPosthogInit = true;
34- import("posthog-js").then(({ default: posthog }) => {
35- posthog.init(posthogKey, {
36- api_host: "https://alef.agenta.ai",
37- ui_host: "https://us.posthog.com",
38- person_profiles: "identified_only",
39- capture_pageview: true,
40- capture_pageleave: true,
41- autocapture: true,
42- respect_dnt: true,
43- });
42+ posthog.init(posthogKey, {
43+ api_host: "https://alef.agenta.ai",
44+ ui_host: "https://us.posthog.com",
45+ person_profiles: "identified_only",
46+ capture_pageview: true,
47+ capture_pageleave: true,
48+ autocapture: true,
49+ respect_dnt: true,
4450 });
4551 }
4652</script >
0 commit comments