From 55578ccf4b20fe6f13d0dacc8a599636c9accd2b Mon Sep 17 00:00:00 2001 From: Rishabh Gupta <38923768+imrishabh18@users.noreply.github.com> Date: Sun, 28 Jun 2026 18:25:39 +0530 Subject: [PATCH] Add Crisp chat script --- src/theme/Root.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/theme/Root.tsx b/src/theme/Root.tsx index 7e1d9b23..fdd2f955 100644 --- a/src/theme/Root.tsx +++ b/src/theme/Root.tsx @@ -6,6 +6,15 @@ const LEVEL_3_LINK_SELECTOR = ".theme-doc-sidebar-item-link-level-3 > .menu__link" const LEVEL_3_PADDING_CLASS = "menu__link--level-3" const SIDEBAR_MENU_SELECTOR = ".theme-doc-sidebar-menu" +const CRISP_WEBSITE_ID = "24b58135-86c7-4e4b-bf6e-cca862bc4b26" +const CRISP_SCRIPT_SRC = "https://client.crisp.chat/l.js" + +declare global { + interface Window { + $crisp?: unknown[] + CRISP_WEBSITE_ID?: string + } +} function applyLevel3PaddingClass() { if (typeof document === "undefined") { @@ -23,6 +32,24 @@ function applyLevel3PaddingClass() { export default function Root({ children }: Props): ReactElement { const location = useLocation() + useEffect(() => { + if (typeof document === "undefined") { + return + } + + window.$crisp = window.$crisp ?? [] + window.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID + + if (document.querySelector(`script[src="${CRISP_SCRIPT_SRC}"]`)) { + return + } + + const script = document.createElement("script") + script.src = CRISP_SCRIPT_SRC + script.async = true + document.head.appendChild(script) + }, []) + useEffect(() => { if (typeof document === "undefined") { return undefined