plane/web/lib/wrappers/crisp-wrapper.tsx
sriram veeraghanta 6595a387d0
feat: event tracking using posthog and created application provider to render multiple wrappers (#2757)
* fix: event tracker changes

* fix: App provider implementation using wrappers

* fix: updating packages

* fix: handling warning

* fix: wrapper fixes and minor optimization changes

* fix: chore app-provider clearnup

* fix: cleanup

* fix: removing jitsu tracking

* fix: minor updates

* fix: adding event to posthog event tracker (#2802)

* dev: posthog event tracker update intitiate

* fix: adding events for posthog integration

* fix: event payload

---------

Co-authored-by: Ramesh Kumar Chandra <31303617+rameshkumarchandra@users.noreply.github.com>
2023-11-20 13:29:54 +05:30

41 lines
988 B
TypeScript

import { useEffect, ReactNode, FC } from "react";
// hooks
import { IUser } from "types";
declare global {
interface Window {
$crisp: any;
CRISP_WEBSITE_ID: any;
}
}
export interface ICrispWrapper {
children: ReactNode;
user: IUser | null;
}
const CrispWrapper: FC<ICrispWrapper> = (props) => {
const { children, user } = props;
useEffect(() => {
if (typeof window && user?.email) {
window.$crisp = [];
window.CRISP_WEBSITE_ID = process.env.NEXT_PUBLIC_CRISP_ID;
(function () {
var d = document;
var s = d.createElement("script");
s.src = "https://client.crisp.chat/l.js";
s.async = true;
d.getElementsByTagName("head")[0].appendChild(s);
window.$crisp.push(["set", "user:email", [user.email]]);
window.$crisp.push(["do", "chat:hide"]);
window.$crisp.push(["do", "chat:close"]);
})();
}
}, [user?.email]);
return <>{children}</>;
};
export default CrispWrapper;