Ver Fonte

feat(frontend): Move posthog key to config and upgrade posthog-js (#4940)

sp.wack há 1 ano atrás
pai
commit
b3fbbbaa9d

+ 4 - 4
frontend/package-lock.json

@@ -26,7 +26,7 @@
         "isbot": "^5.1.17",
         "jose": "^5.9.4",
         "monaco-editor": "^0.52.0",
-        "posthog-js": "^1.176.0",
+        "posthog-js": "^1.184.1",
         "react": "^18.3.1",
         "react-dom": "^18.3.1",
         "react-highlight": "^0.15.0",
@@ -19749,9 +19749,9 @@
       "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
     },
     "node_modules/posthog-js": {
-      "version": "1.176.0",
-      "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.176.0.tgz",
-      "integrity": "sha512-T5XKNtRzp7q6CGb7Vc7wAI76rWap9fiuDUPxPsyPBPDkreKya91x9RIsSapAVFafwD1AEin1QMczCmt9Le9BWw==",
+      "version": "1.184.1",
+      "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.184.1.tgz",
+      "integrity": "sha512-q/1Kdard5SZnL2smrzeKcD+RuUi2PnbidiN4D3ThK20bNrhy5Z2heIy9SnRMvEiARY5lcQ7zxmDCAKPBKGSOtQ==",
       "dependencies": {
         "core-js": "^3.38.1",
         "fflate": "^0.4.8",

+ 2 - 2
frontend/package.json

@@ -25,7 +25,7 @@
     "isbot": "^5.1.17",
     "jose": "^5.9.4",
     "monaco-editor": "^0.52.0",
-    "posthog-js": "^1.176.0",
+    "posthog-js": "^1.184.1",
     "react": "^18.3.1",
     "react-dom": "^18.3.1",
     "react-highlight": "^0.15.0",
@@ -120,4 +120,4 @@
       "public"
     ]
   }
-}
+}

+ 3 - 2
frontend/public/config.json

@@ -1,4 +1,5 @@
 {
   "APP_MODE": "oss",
-  "GITHUB_CLIENT_ID": ""
-}
+  "GITHUB_CLIENT_ID": "",
+  "POSTHOG_CLIENT_KEY": "phc_3ESMmY9SgqEAGBB6sMGK5ayYHkeUuknH2vP6FmWH9RA"
+}

+ 2 - 1
frontend/src/api/open-hands.types.ts

@@ -43,5 +43,6 @@ export interface Feedback {
 
 export interface GetConfigResponse {
   APP_MODE: "saas" | "oss";
-  GITHUB_CLIENT_ID: string | null;
+  GITHUB_CLIENT_ID: string;
+  POSTHOG_CLIENT_KEY: string;
 }

+ 14 - 3
frontend/src/entry.client.tsx

@@ -12,15 +12,26 @@ import { Provider } from "react-redux";
 import posthog from "posthog-js";
 import "./i18n";
 import store from "./store";
+import OpenHands from "./api/open-hands";
 
 function PosthogInit() {
+  const [key, setKey] = React.useState<string | null>(null);
+
   React.useEffect(() => {
-    posthog.init("phc_3ESMmY9SgqEAGBB6sMGK5ayYHkeUuknH2vP6FmWH9RA", {
-      api_host: "https://us.i.posthog.com",
-      person_profiles: "identified_only",
+    OpenHands.getConfig().then((config) => {
+      setKey(config.POSTHOG_CLIENT_KEY);
     });
   }, []);
 
+  React.useEffect(() => {
+    if (key) {
+      posthog.init(key, {
+        api_host: "https://us.i.posthog.com",
+        person_profiles: "identified_only",
+      });
+    }
+  }, [key]);
+
   return null;
 }