diff --git a/agenta-web/src/lib/helpers/analytics/AgPosthogProvider.tsx b/agenta-web/src/lib/helpers/analytics/AgPosthogProvider.tsx index f7b1011560..2f6849c1fc 100644 --- a/agenta-web/src/lib/helpers/analytics/AgPosthogProvider.tsx +++ b/agenta-web/src/lib/helpers/analytics/AgPosthogProvider.tsx @@ -1,9 +1,10 @@ import {useCallback, useEffect, useRef} from "react" import {useRouter} from "next/router" import {useAtom} from "jotai" -import {posthogAtom} from "./store/atoms" +import {posthogAtom, type PostHogConfig} from "./store/atoms" +import {CustomPosthogProviderType} from "./types" -const CustomPosthogProvider = ({children}: {children: React.ReactNode}) => { +const CustomPosthogProvider: CustomPosthogProviderType = ({children, config}) => { const router = useRouter() const loadingPosthog = useRef(false) const [posthogClient, setPosthogClient] = useAtom(posthogAtom) @@ -24,9 +25,9 @@ const CustomPosthogProvider = ({children}: {children: React.ReactNode}) => { if (process.env.NODE_ENV === "development") posthog.debug() }, capture_pageview: false, - persistence: "localStorage+cookie", + ...config, }) - }, [posthogClient, setPosthogClient]) + }, [config, posthogClient, setPosthogClient]) useEffect(() => { initPosthog() diff --git a/agenta-web/src/lib/helpers/analytics/store/atoms.ts b/agenta-web/src/lib/helpers/analytics/store/atoms.ts index 5907eb709b..55acac9d8c 100644 --- a/agenta-web/src/lib/helpers/analytics/store/atoms.ts +++ b/agenta-web/src/lib/helpers/analytics/store/atoms.ts @@ -1,4 +1,5 @@ import {atom} from "jotai" -import {type PostHog} from "posthog-js" +import {type PostHog, type PostHogConfig} from "posthog-js" +export type {PostHogConfig} export const posthogAtom = atom(null) diff --git a/agenta-web/src/lib/helpers/analytics/types.d.ts b/agenta-web/src/lib/helpers/analytics/types.d.ts new file mode 100644 index 0000000000..d55cc0d99c --- /dev/null +++ b/agenta-web/src/lib/helpers/analytics/types.d.ts @@ -0,0 +1,7 @@ +import {type PostHogConfig} from "./store/atoms" + +export interface CustomPosthogProviderType + extends React.FC<{ + children: React.ReactNode + config: Partial + }> {} diff --git a/agenta-web/src/pages/_app.tsx b/agenta-web/src/pages/_app.tsx index ca98a01c65..8866c081f8 100644 --- a/agenta-web/src/pages/_app.tsx +++ b/agenta-web/src/pages/_app.tsx @@ -29,7 +29,11 @@ export default function App({Component, pageProps}: AppProps) {
- +