| 1 | import posthog from "posthog-js"; |
| 2 | import { PostHogProvider } from "posthog-js/react"; |
| 3 | import { PropsWithChildren, useEffect } from "react"; |
| 4 | import { useAppSelector } from "../redux/hooks"; |
| 5 | |
| 6 | const CustomPostHogProvider = ({ children }: PropsWithChildren) => { |
| 7 | const allowAnonymousTelemetry = useAppSelector( |
| 8 | (store) => store?.config?.config?.allowAnonymousTelemetry, |
| 9 | ); |
| 10 | |
| 11 | useEffect(() => { |
| 12 | if (allowAnonymousTelemetry) { |
| 13 | posthog.init("phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", { |
| 14 | api_host: "https://app.posthog.com", |
| 15 | disable_session_recording: true, |
| 16 | autocapture: false, |
| 17 | // // We need to manually track pageviews since we're a SPA |
| 18 | capture_pageleave: false, |
| 19 | capture_pageview: false, |
| 20 | }); |
| 21 | posthog.identify(window.vscMachineId); |
| 22 | posthog.opt_in_capturing(); |
| 23 | } else { |
| 24 | posthog.opt_out_capturing(); |
| 25 | } |
| 26 | }, [allowAnonymousTelemetry]); |
| 27 | |
| 28 | return <PostHogProvider client={posthog}>{children}</PostHogProvider>; |
| 29 | }; |
| 30 | |
| 31 | export default CustomPostHogProvider; |