Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { useEffect } from "react";
|
||||
import { useLocation } from "react-router";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import CookieHelper from "~/utils/helpers/CookieHelper";
|
||||
import { CookieCategory } from "~/application/cookies/CookieCategory";
|
||||
import { isAppOrAdminSurface } from "~/utils/app/HostAwareSurface";
|
||||
|
||||
const FORCE_IN_ROUTES = ["/crisp"];
|
||||
|
||||
export default function ScriptCrisp() {
|
||||
const rootData = useRootData();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
const isAppOrAdminArea = isAppOrAdminSurface(rootData, location.pathname);
|
||||
let hasConsent = CookieHelper.hasConsent(rootData.userSession ?? null, CookieCategory.FUNCTIONAL) || isAppOrAdminArea || FORCE_IN_ROUTES.some((p) => location.pathname.startsWith(p));
|
||||
if (rootData.chatWebsiteId && hasConsent && !window.$crisp) {
|
||||
window.$crisp = [];
|
||||
window.CRISP_WEBSITE_ID = rootData.chatWebsiteId;
|
||||
const d = document;
|
||||
const s = d.createElement("script");
|
||||
s.src = "https://client.crisp.chat/l.js";
|
||||
s.async = true;
|
||||
d.getElementsByTagName("head")[0].appendChild(s);
|
||||
}
|
||||
if (window.$crisp && isAppOrAdminArea) {
|
||||
try {
|
||||
// @ts-ignore
|
||||
window.$crisp.push(["do", "chat:hide"]);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}, [rootData, rootData.userSession?.cookies, rootData.chatWebsiteId, location.pathname]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
$crisp: any;
|
||||
CRISP_WEBSITE_ID: string;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user