'use client' import { usePathname } from 'next/navigation' import { useEffect, useRef } from 'react' import { IS_PREVIEW } from '@/lib/constants' import { sendFrontendMetric } from '@/lib/frontend-metrics' /** * Sends one pageview metric on hydration and on every pathname change. * Search-param and hash changes are not pageviews. */ export function usePageviewMetric() { const pathname = usePathname() const lastSentPathname = useRef(null) useEffect(() => { if (!IS_PREVIEW) return // Guards against the StrictMode effect double-invoke if (lastSentPathname.current === pathname) return lastSentPathname.current = pathname sendFrontendMetric('pageview') }, [pathname]) }