import type { ExtendedWindow } from "~/types/window"; import { withErrorHandling } from "./sentry"; export function getSharingId(): string { if (typeof window === "undefined") { return ""; } const extendedWindow = window as ExtendedWindow; if (extendedWindow.chatbotData) { return extendedWindow.chatbotData.sharingID; } const wrappedFn = withErrorHandling("getSharingId", () => { const widgetScriptTag = document.querySelector( "script#mori-react-widget" ) as HTMLScriptElement | null; return widgetScriptTag?.getAttribute("data-sharing-id") || ""; }); return wrappedFn() || ""; }