Skip to content
Merged
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
30 changes: 27 additions & 3 deletions frontend/src/oso.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
/* Copyright 2024 Marimo. All rights reserved. */

import posthog from 'posthog-js'
import posthog from "posthog-js";
Comment thread
Jabolol marked this conversation as resolved.
import { mount } from "@/oso-mount";


declare global {
interface Window {
__MARIMO_MOUNT_CONFIG__: unknown;
}
}

if (import.meta.env.VITE_POSTHOG_PUBLIC_API_KEY) {
// Read identity passed from the parent page via URL fragment to stitch events
Comment thread
Jabolol marked this conversation as resolved.
// 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;

// Strip the identity params from the URL once consumed, so they don't linger
// in a shareable/openable link and stitch events under the wrong identity.
// Only the PostHog keys are removed; any other fragment state is preserved.
if (distinctID || sessionID) {
fragment.delete("posthogDistinctId");
fragment.delete("posthogSessionId");
const rest = fragment.toString();
history.replaceState(
null,
"",
window.location.pathname +
window.location.search +
(rest ? `#${rest}` : ""),
);
}

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");
Expand Down