import posthog from "posthog-js"; import { PostHogProvider } from "posthog-js/react"; import React, { PropsWithChildren, useEffect } from "react"; import { useSelector } from "react-redux"; import { RootState } from "../redux/store"; const CustomPostHogProvider = ({ children }: PropsWithChildren) => { const allowAnonymousTelemetry = useSelector( (store: RootState) => store?.state?.config.allowAnonymousTelemetry ); const [client, setClient] = React.useState(undefined); useEffect(() => { if (allowAnonymousTelemetry === true) { posthog.init("phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", { api_host: "https://app.posthog.com", disable_session_recording: true, }); posthog.identify(window.vscMachineId); posthog.opt_in_capturing(); setClient(client); } else { setClient(undefined); } }, [allowAnonymousTelemetry]); return allowAnonymousTelemetry ? ( {children} ) : ( <>{children} ); }; export default CustomPostHogProvider;