analytics fixs

This commit is contained in:
nmemmert
2026-06-03 11:35:45 -04:00
parent b7aa32e4b7
commit e561bfa000
5 changed files with 339 additions and 53 deletions
+15
View File
@@ -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')