add crisp
This commit is contained in:
parent
7d4d62aa41
commit
d56242af2c
@ -9,6 +9,7 @@ import AvatarDropdown from "./AvatarDropdown";
|
|||||||
import { UserResponse } from "./types";
|
import { UserResponse } from "./types";
|
||||||
import { POSTHOG_HOST, POSTHOG_KEY, SAAS_BACKEND_URL } from "../../config";
|
import { POSTHOG_HOST, POSTHOG_KEY, SAAS_BACKEND_URL } from "../../config";
|
||||||
import LandingPage from "./LandingPage";
|
import LandingPage from "./LandingPage";
|
||||||
|
import { loadCrispChat } from "../../lib/crisp";
|
||||||
|
|
||||||
function AppContainer() {
|
function AppContainer() {
|
||||||
const { isSignedIn, isLoaded } = useUser();
|
const { isSignedIn, isLoaded } = useUser();
|
||||||
@ -59,12 +60,9 @@ function AppContainer() {
|
|||||||
last_name: user.last_name,
|
last_name: user.last_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize Help Scout Beacon
|
// Initialize Crisp Chat
|
||||||
window.Beacon("init", "8bcd8d6f-f25d-4339-8f49-703b9f165cdc");
|
loadCrispChat();
|
||||||
window.Beacon("identify", {
|
window.$crisp.push(["set", "user:email", [user.email]]);
|
||||||
name: user.first_name + " " + user.last_name,
|
|
||||||
email: user.email,
|
|
||||||
});
|
|
||||||
|
|
||||||
setSubscriberTier(user.subscriber_tier);
|
setSubscriberTier(user.subscriber_tier);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,3 +28,6 @@ export const IS_FREE_TRIAL_ENABLED = false;
|
|||||||
// PostHog
|
// PostHog
|
||||||
export const POSTHOG_KEY = import.meta.env.VITE_POSTHOG_KEY || null;
|
export const POSTHOG_KEY = import.meta.env.VITE_POSTHOG_KEY || null;
|
||||||
export const POSTHOG_HOST = import.meta.env.VITE_POSTHOG_HOST || null;
|
export const POSTHOG_HOST = import.meta.env.VITE_POSTHOG_HOST || null;
|
||||||
|
|
||||||
|
// Crisp
|
||||||
|
export const CRISP_WEBSITE_ID = import.meta.env.VITE_CRISP_WEBSITE_ID || null;
|
||||||
|
|||||||
32
frontend/src/lib/crisp.ts
Normal file
32
frontend/src/lib/crisp.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { CRISP_WEBSITE_ID } from "../config";
|
||||||
|
|
||||||
|
export const loadCrispChat = (): (() => void) => {
|
||||||
|
if (document.getElementById("crisp-chat-script")) {
|
||||||
|
// The script element already exists, so don't add it again
|
||||||
|
return () => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.$crisp = [];
|
||||||
|
window.CRISP_WEBSITE_ID = CRISP_WEBSITE_ID;
|
||||||
|
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);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Cleanup function to remove the script when it's no longer needed
|
||||||
|
const scriptElement = document.getElementById("crisp-chat-script");
|
||||||
|
if (scriptElement && scriptElement.parentNode) {
|
||||||
|
scriptElement.parentNode.removeChild(scriptElement);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
// Crisp
|
||||||
|
$crisp: unknown[];
|
||||||
|
CRISP_WEBSITE_ID: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user