mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 21:02:45 -07:00
32 lines
900 B
TypeScript
32 lines
900 B
TypeScript
import type { JSX, ReactNode } from 'react'
|
|
import { useEffect } from 'react'
|
|
import { PostHogProvider as PostHogLibraryProvider } from 'posthog-js/react'
|
|
import posthogJs from 'posthog-js'
|
|
|
|
interface PostHogProviderProps {
|
|
children: ReactNode
|
|
}
|
|
|
|
export default function PostHogProvider({
|
|
children,
|
|
}: PostHogProviderProps): JSX.Element {
|
|
useEffect(() => {
|
|
if (import.meta.env.VITE_ENABLE_POSTHOG === 'true') {
|
|
posthogJs.init(import.meta.env.VITE_PUBLIC_POSTHOG_KEY, {
|
|
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
|
|
persistence: 'memory', // Cookieless tracking
|
|
disable_persistence: true, // Disable persistence
|
|
loaded: (ph) => {
|
|
if (import.meta.env.VITE_ENV === 'development') ph.debug()
|
|
},
|
|
})
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<PostHogLibraryProvider client={posthogJs}>
|
|
{children}
|
|
</PostHogLibraryProvider>
|
|
)
|
|
}
|