From 4789ba3e8f5551ba87c74d49753c02158d16dbd0 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Mon, 21 Apr 2025 11:18:11 +0800 Subject: [PATCH] feat: add PostHogProvider for analytics integration - Introduced PostHogProvider to manage data collection based on user settings. - Wrapped the main application in PostHogProvider to enable analytics when data collection is allowed. --- src/renderer/src/App.tsx | 55 +++++++++++--------- src/renderer/src/context/PostHogProvider.tsx | 24 +++++++++ 2 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 src/renderer/src/context/PostHogProvider.tsx diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index c5e70a92..1727f5bb 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -8,6 +8,7 @@ import { PersistGate } from 'redux-persist/integration/react' import Sidebar from './components/app/Sidebar' import TopViewContainer from './components/TopView' import AntdProvider from './context/AntdProvider' +import PostHogProvider from './context/PostHogProvider' import StyleSheetManager from './context/StyleSheetManager' import { SyntaxHighlighterProvider } from './context/SyntaxHighlighterProvider' import { ThemeProvider } from './context/ThemeProvider' @@ -24,32 +25,34 @@ import TranslatePage from './pages/translate/TranslatePage' function App(): React.ReactElement { return ( - - - - - - - - - - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - - - - - + + + + + + + + + + + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + + + + + + + ) } diff --git a/src/renderer/src/context/PostHogProvider.tsx b/src/renderer/src/context/PostHogProvider.tsx new file mode 100644 index 00000000..edcfa385 --- /dev/null +++ b/src/renderer/src/context/PostHogProvider.tsx @@ -0,0 +1,24 @@ +import { useAppSelector } from '@renderer/store' +import { PostHogProvider as PostHogReactProvider } from 'posthog-js/react' +import { FC } from 'react' + +const POSTHOG_OPTIONS = { + api_key: 'phc_G0omsYajA6A9BY5c0rnU04ZaZck25xpR0DqKhwfF39n', + api_host: 'https://us.i.posthog.com' +} + +const PostHogProvider: FC<{ children: React.ReactNode }> = ({ children }) => { + const enableDataCollection = useAppSelector((state) => state.settings.enableDataCollection) + + if (enableDataCollection) { + return ( + + {children} + + ) + } + + return children +} + +export default PostHogProvider