vercel / analytics

Privacy-friendly, real-time traffic insights
https://vercel.com/analytics
Mozilla Public License 2.0
416 stars 24 forks source link

script.js doesn't load with Next.js Dyamic Routes? [Error on build only] #144

Closed mitchuman closed 1 month ago

mitchuman commented 1 month ago

When using Next.js Dynamic Routes (setup found here and just below), /_vercel/insights/* does not seem to get included in the build, thus the analytics scripts aren't running.

Setup: /app/[slug]/page.tsx

Notice the usage of notFound() and generateStaticParams() that likely disable generated routes that aren't included in the fetched data, including /_vercel/*

export default async function Page({ params }: Props) {
    const page = await getPage(params)
    if (!page) notFound()
    return <>...</>
}

export async function generateMetadata({ params }: Props) {
    const page = await getPage(params)
    if (!page) notFound()
    return { ... }
}

export async function generateStaticParams() {
    const slugs = await fetchData(...)
    return slugs.map((slug) => ({ slug }))
}

Local dev (no issue):

Screenshot 2024-06-07 at 2 08 26 PM

after npm run build:

Screenshot 2024-06-07 at 2 04 15 PM
tobiaslins commented 1 month ago

Hey! Vercel Analytics only works when deployed on Vercel (or when running dev).

mitchuman commented 1 month ago

Ok I see it running now when I deploy on the live branch. TY