📈(frontend) track page view events in SPA
Implement page view tracking in the SPA following PostHog’s guidelines. Manually capture page's location when it changes.
This commit is contained in:
committed by
aleb_the_flash
parent
0ad9b7e233
commit
0c64580abf
@@ -1,11 +1,11 @@
|
|||||||
import '@livekit/components-styles'
|
import '@livekit/components-styles'
|
||||||
import '@/styles/index.css'
|
import '@/styles/index.css'
|
||||||
import { Suspense } from 'react'
|
import { Suspense, useEffect } from 'react'
|
||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
|
||||||
import { QueryClientProvider } from '@tanstack/react-query'
|
import { QueryClientProvider } from '@tanstack/react-query'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useLang } from 'hoofd'
|
import { useLang } from 'hoofd'
|
||||||
import { Switch, Route } from 'wouter'
|
import { Switch, Route, useLocation } from 'wouter'
|
||||||
import { I18nProvider } from 'react-aria-components'
|
import { I18nProvider } from 'react-aria-components'
|
||||||
import { Layout } from './layout/Layout'
|
import { Layout } from './layout/Layout'
|
||||||
import { NotFoundScreen } from './components/NotFoundScreen'
|
import { NotFoundScreen } from './components/NotFoundScreen'
|
||||||
@@ -17,6 +17,7 @@ import posthog from 'posthog-js'
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { i18n } = useTranslation()
|
const { i18n } = useTranslation()
|
||||||
|
const [location] = useLocation()
|
||||||
useLang(i18n.language)
|
useLang(i18n.language)
|
||||||
|
|
||||||
const isProduction = import.meta.env.PROD
|
const isProduction = import.meta.env.PROD
|
||||||
@@ -31,6 +32,10 @@ function App() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
posthog.capture('$pageview')
|
||||||
|
}, [location])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<Suspense fallback={null}>
|
<Suspense fallback={null}>
|
||||||
|
|||||||
Reference in New Issue
Block a user