11"use client" ;
22
33import { usePathname , useSearchParams } from "next/navigation" ;
4+ import { usePostHog } from "posthog-js/react" ;
45import { Suspense , useEffect } from "react" ;
56
67import posthog from "posthog-js" ;
78import { PostHogProvider as PHProvider } from "posthog-js/react" ;
8- import { useTrackAnalytics } from "." ;
99import { isProd } from "./utils" ;
1010
1111export function PostHogProvider ( { children } : { children : React . ReactNode } ) {
1212 useEffect ( ( ) => {
1313 if ( ! isProd ) {
14- console . log ( "Mock analytics init " ) ;
14+ console . log ( "Analytics disabled in non-production environment " ) ;
1515 return ;
1616 }
1717
@@ -34,19 +34,18 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
3434function PostHogPageView ( ) {
3535 const pathname = usePathname ( ) ;
3636 const searchParams = useSearchParams ( ) ;
37- const { track } = useTrackAnalytics ( ) ;
37+ const posthog = usePostHog ( ) ;
3838
39- // Track pageviews
4039 useEffect ( ( ) => {
41- if ( pathname ) {
40+ if ( pathname && posthog ) {
4241 let url = window . origin + pathname ;
4342 if ( searchParams . toString ( ) ) {
4443 url = url + "?" + searchParams . toString ( ) ;
4544 }
4645
47- track ( { event : "$pageview" , $current_url : url } ) ;
46+ posthog . capture ( "$pageview" , { $current_url : url } ) ;
4847 }
49- } , [ pathname , searchParams , track ] ) ;
48+ } , [ pathname , searchParams , posthog ] ) ;
5049
5150 return null ;
5251}
0 commit comments