From ae7dffa211af209aea2ca13b37729e390047dd7c Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Tue, 29 Aug 2023 10:39:25 -0700
Subject: feat: :mute: complete removal of telemetry when
 allow_anonymous_telemetry false

---
 .../react-app/src/hooks/CustomPostHogProvider.tsx  | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 extension/react-app/src/hooks/CustomPostHogProvider.tsx

(limited to 'extension/react-app/src/hooks/CustomPostHogProvider.tsx')

diff --git a/extension/react-app/src/hooks/CustomPostHogProvider.tsx b/extension/react-app/src/hooks/CustomPostHogProvider.tsx
new file mode 100644
index 00000000..cc6de4a2
--- /dev/null
+++ b/extension/react-app/src/hooks/CustomPostHogProvider.tsx
@@ -0,0 +1,34 @@
+import posthog from "posthog-js";
+import { PostHogProvider } from "posthog-js/react";
+import { PropsWithChildren, useEffect } from "react";
+import { RootStore } from "../redux/store";
+import { useSelector } from "react-redux";
+import React from "react";
+
+const CustomPostHogProvider = ({ children }: PropsWithChildren) => {
+  const allowAnonymousTelemetry = useSelector(
+    (store: RootStore) => store?.serverState?.config?.allow_anonymous_telemetry
+  );
+
+  const [client, setClient] = React.useState<any>(undefined);
+
+  useEffect(() => {
+    if (allowAnonymousTelemetry) {
+      posthog.init("phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", {
+        api_host: "https://app.posthog.com",
+        disable_session_recording: true,
+      });
+      setClient(client);
+    } else {
+      setClient(undefined);
+    }
+  }, [allowAnonymousTelemetry]);
+
+  return allowAnonymousTelemetry ? (
+    <PostHogProvider client={client}>{children}</PostHogProvider>
+  ) : (
+    <>{children}</>
+  );
+};
+
+export default CustomPostHogProvider;
-- 
cgit v1.2.3-70-g09d2

