analytics fixs
This commit is contained in:
+15
@@ -15,6 +15,20 @@ const SPOTIFY_EMBED_URL =
|
||||
const CONSENT_KEY = 'vbn_analytics_consent_choice'
|
||||
const HEADLINER_WIDGET_ID = 'WI_cmou3b4q7000701p0o9qmmcfj'
|
||||
|
||||
function usePageTracking() {
|
||||
const location = useLocation()
|
||||
useEffect(() => {
|
||||
if (localStorage.getItem(CONSENT_KEY) !== 'accepted') return
|
||||
const referrer = document.referrer || ''
|
||||
fetch('/api/analytics/pageview', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ path: location.pathname, referrer }),
|
||||
keepalive: true,
|
||||
}).catch(() => {})
|
||||
}, [location.pathname])
|
||||
}
|
||||
|
||||
function toSpotifyEpisodeEmbedUrl(url: string | undefined): string {
|
||||
if (!url) return ''
|
||||
|
||||
@@ -2120,6 +2134,7 @@ export default function App() {
|
||||
const [content, setContent] = useState<SiteContent>(DEFAULTS)
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
usePageTracking()
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/admin-content')
|
||||
|
||||
Reference in New Issue
Block a user