Comparison · Website builders

Best Analytics for Next.js Apps

Vercel Analytics, GA4, Plausible, PostHog and DataFair for Next.js compared, with how to install each in the App Router and how to get revenue by source.

· 3 min read

A dashboard frame with a rising line and the DataFair mark

Next.js makes adding analytics easy, and the choice depends on what you want to learn: page performance, traffic, product usage or revenue. Here are the main options and how each installs in the App Router.

Vercel Analytics

Built into Vercel: install the @vercel/analytics package and add its component to your root layout. Visitors, pages and referrers in your Vercel dashboard, plus Speed Insights for performance.

Good for: apps hosted on Vercel that want zero setup. Limits: tied to Vercel hosting, and pricing depends on your Vercel plan and event volume. Check Vercel's pricing page.

Google Analytics 4

Next.js's official @next/third-parties package includes a GoogleAnalytics component for the root layout.

Good for: teams using Google Ads. Limits: consent banners in many countries, and complex reports. Why GA4 misses Stripe revenue.

Plausible, Fathom, Umami

Privacy-first tools that install with a script tag through next/script, or community packages. Clean dashboards, cookieless counting.

Good for: marketing sites and blogs.

PostHog

Product analytics with session replay, feature flags and experiments, with a Next.js SDK.

Good for: understanding what users do inside your app.

DataFair

Revenue analytics: visitors, sources and pages, with revenue from your payment provider credited to each source. Install with next/script in the root layout:

import Script from 'next/script';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script defer data-website-id="YOUR_WEBSITE_ID" src="https://datafair.dev/js/script.js" strategy="afterInteractive" />
      </body>
    </html>
  );
}

Client-side navigation between pages is tracked automatically as pageviews.

For Stripe Checkout Sessions created in a route handler or server action, pass the visitor id from the browser into the session's metadata. The guide has the code.

Bonus for Next.js: most AI crawlers never run JavaScript. Report them from middleware.ts with one fetch to DataFair's crawler endpoint, and see which pages ChatGPT, Claude and Perplexity read. The AI crawler list explains each bot.

Comparison

Vercel AnalyticsGA4Plausible / Fathom / UmamiPostHogDataFair
InstallPackage + component@next/third-partiesScriptSDKScript
Revenue by sourceNoWith purchase eventsFrom values you sendFrom events you sendFrom provider webhooks
Product analyticsNoSomeNoYesGoals and funnels
AI crawler trackingNoNoNoNoYes, via middleware
The AI crawler panel in DataFair
AI crawler activity in the DataFair demo (sample data).

Related guide: Revenue analytics: measure what pays, not just what visits.

Questions

What is the best analytics for Next.js?
It depends on the question: Vercel Analytics for zero-setup traffic on Vercel, PostHog for product usage, GA4 for Google Ads, and a revenue analytics tool for which channels bring paying customers.
Does DataFair track client-side navigation in Next.js?
Yes. Single page app navigations are counted as pageviews.
Do I need a package to add DataFair to Next.js?
No. Use next/script with the DataFair script tag in your root layout.

Related