Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions frontend/src/oso.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import posthog from 'posthog-js'
import { mount } from "@/oso-mount";
import { Logger } from "@/utils/Logger";


declare global {
Expand All @@ -11,14 +12,21 @@ declare global {
}

if (import.meta.env.VITE_POSTHOG_PUBLIC_API_KEY) {
// Read identity passed from the parent page via URL fragment to stitch events
// under the same distinct_id without emitting a spurious $identify event.
const fragment = new URLSearchParams(window.location.hash.slice(1));
const distinctID = fragment.get("posthogDistinctId") ?? undefined;
const sessionID = fragment.get("posthogSessionId") ?? undefined;

posthog.init(import.meta.env.VITE_POSTHOG_PUBLIC_API_KEY, {
bootstrap: distinctID ? { distinctID, sessionID, isIdentifiedID: true } : undefined,
session_recording: {
// WARNING: Only enable this if you understand the security implications
recordCrossOriginIframes: true,
}
},
});
} else {
console.warn("POSTHOG_PUBLIC_API_KEY not set, skipping posthog init");
Logger.warn("POSTHOG_PUBLIC_API_KEY not set, skipping posthog init");
}

// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
Expand All @@ -28,7 +36,7 @@ if (el) {
throw new Error("[marimo] mount config not found");
}
mount(window.__MARIMO_MOUNT_CONFIG__, el).catch((e) => {
console.error("Failed to mount marimo app", e);
Logger.error("Failed to mount marimo app", e);
});
} else {
throw new Error("[marimo] root element not found");
Expand Down
Loading