Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(analytics): posthog recorder script blocked, no session recordings sometimes (#5139)

dev-rbb75f305cbba8
diff --git a/apps/web/src/lib/analytics/analytics.ts b/apps/web/src/lib/analytics/analytics.ts
index 875bd90e52..5900575ec2 100644
--- a/apps/web/src/lib/analytics/analytics.ts
+++ b/apps/web/src/lib/analytics/analytics.ts
@@ -107,6 +107,10 @@ const IGNORABLE_ERRORS = [
'ResizeObserver loop completed with undelivered notifications',
];
+// Privacy filter lists block the upstream filename; the proxy maps this opaque alias back.
+const POSTHOG_RECORDER_SCRIPT_NAME = 'posthog-recorder.js';
+const POSTHOG_RECORDER_PROXY_SCRIPT_NAME = 'runtime.js';
+
const initializePosthog = (instance: PostHog) => {
const key = import.meta.env.VITE_POSTHOG_API_KEY;
if (!key) return;
@@ -115,6 +119,16 @@ const initializePosthog = (instance: PostHog) => {
api_host: 'https://macro-prox.macroverse.workers.dev/i/ph',
ui_host: 'https://us.posthog.com',
defaults: '2026-01-30',
+ prepare_external_dependency_script: (script) => {
+ const url = new URL(script.src);
+
+ if (url.pathname.endsWith(`/static/${POSTHOG_RECORDER_SCRIPT_NAME}`)) {
+ url.pathname = `/i/ph/static/${POSTHOG_RECORDER_PROXY_SCRIPT_NAME}`;
+ script.src = url.toString();
+ }
+
+ return script;
+ },
before_send: (cr) => {
if (cr) {
cr.properties.env = DEV_MODE_ENV
diff --git a/services/analytics-proxy/src/index.ts b/services/analytics-proxy/src/index.ts
index 6fbc5c09ec..94756f6230 100644
--- a/services/analytics-proxy/src/index.ts
+++ b/services/analytics-proxy/src/index.ts
@@ -1,11 +1,27 @@
+const POSTHOG_PROVIDER_PREFIX = '/i/ph';
+const POSTHOG_HOST = 'us.i.posthog.com';
+// Privacy filter lists block the upstream filename; keep the browser-facing alias opaque.
+const POSTHOG_RECORDER_SCRIPT_NAME = 'posthog-recorder.js';
+const POSTHOG_RECORDER_PROXY_SCRIPT_NAME = 'runtime.js';
+
const PROVIDERS: Record<string, string> = {
- '/i/ph': 'us.i.posthog.com',
+ [POSTHOG_PROVIDER_PREFIX]: POSTHOG_HOST,
// Datadog browser logs intake for the us5 site (site: us5.datadoghq.com).
// The observability SDK's `proxy` option targets the `/i/dd` prefix.
'/i/dd': 'browser-intake-us5-datadoghq.com',
};
function getProvider(pathname: string): { apiHost: string; path: string } | null {
+ if (
+ pathname ===
+ `${POSTHOG_PROVIDER_PREFIX}/static/${POSTHOG_RECORDER_PROXY_SCRIPT_NAME}`
+ ) {
+ return {
+ apiHost: POSTHOG_HOST,
+ path: `/static/${POSTHOG_RECORDER_SCRIPT_NAME}`,
+ };
+ }
+
for (const [prefix, apiHost] of Object.entries(PROVIDERS)) {
if (pathname.startsWith(prefix)) {
return { apiHost, path: pathname.slice(prefix.length) || '/' };