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.
This commit is contained in:
parent
cc18f0f0c3
commit
4789ba3e8f
@ -8,6 +8,7 @@ import { PersistGate } from 'redux-persist/integration/react'
|
|||||||
import Sidebar from './components/app/Sidebar'
|
import Sidebar from './components/app/Sidebar'
|
||||||
import TopViewContainer from './components/TopView'
|
import TopViewContainer from './components/TopView'
|
||||||
import AntdProvider from './context/AntdProvider'
|
import AntdProvider from './context/AntdProvider'
|
||||||
|
import PostHogProvider from './context/PostHogProvider'
|
||||||
import StyleSheetManager from './context/StyleSheetManager'
|
import StyleSheetManager from './context/StyleSheetManager'
|
||||||
import { SyntaxHighlighterProvider } from './context/SyntaxHighlighterProvider'
|
import { SyntaxHighlighterProvider } from './context/SyntaxHighlighterProvider'
|
||||||
import { ThemeProvider } from './context/ThemeProvider'
|
import { ThemeProvider } from './context/ThemeProvider'
|
||||||
@ -24,6 +25,7 @@ import TranslatePage from './pages/translate/TranslatePage'
|
|||||||
function App(): React.ReactElement {
|
function App(): React.ReactElement {
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
|
<PostHogProvider>
|
||||||
<StyleSheetManager>
|
<StyleSheetManager>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<AntdProvider>
|
<AntdProvider>
|
||||||
@ -50,6 +52,7 @@ function App(): React.ReactElement {
|
|||||||
</AntdProvider>
|
</AntdProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</StyleSheetManager>
|
</StyleSheetManager>
|
||||||
|
</PostHogProvider>
|
||||||
</Provider>
|
</Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/renderer/src/context/PostHogProvider.tsx
Normal file
24
src/renderer/src/context/PostHogProvider.tsx
Normal file
@ -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 (
|
||||||
|
<PostHogReactProvider apiKey={POSTHOG_OPTIONS.api_key} options={POSTHOG_OPTIONS}>
|
||||||
|
{children}
|
||||||
|
</PostHogReactProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return children
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PostHogProvider
|
||||||
Loading…
x
Reference in New Issue
Block a user