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
19 changes: 14 additions & 5 deletions frontend/src/oso.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */

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

import { Logger } from "@/utils/Logger";

declare global {
interface Window {
Expand All @@ -11,14 +11,23 @@ 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 +37,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