Skip to content
Frameworks

Next.js analytics with revenue attribution

2 min read · Updated · By the Reveata team

Short answerAdd the Reveata script to your Next.js root layout with next/script, or use the typed Reveata component from @reveata/next. Client-side navigation is counted, and server helpers read the visitor id from Reveata's cookie so each checkout is credited to its visit.

Next.js apps usually sell something: a SaaS plan, a course, a product. Reveata fits the way Next.js is built, with a component for the browser and helpers for route handlers and server actions, so revenue attribution is a few lines rather than a project.

What you get

  • Every page view, App Router and Pages Router, client-side navigation included.
  • Goals, identify and payments from typed helpers: trackGoal, identify, trackPayment({ email }) for a thank-you page, resetVisitor() on log out and decorateUrl(url) for links you open from code.
  • Broken links (404) with the page that linked to them, from <ReveataNotFound /> in app/not-found.tsx.
  • Opt-in extras: file downloads, form submissions and web vitals.
  • Server-side ids for checkouts, through readTrackerIds from @reveata/next/server.

Two ways to install

The script tag, no package:

tsx
// app/layout.tsx
<Script src="https://reveata.com/js/script.js" data-website-id="ws_your_tracking_id" strategy="afterInteractive" />

The package: npm install @reveata/next, then render <Reveata /> once in the root layout (or pages/_app.tsx). Its options include cookieless, domains, excludePaths, hash, api, respectDnt and enabled, for example enabled={process.env.NODE_ENV === 'production'}. Next.js's own Script component is documented in the Next.js Script reference (opens in a new tab).

Linking payments to visits

In a route handler or server action that creates a checkout, read the Reveata cookies and pass the ids on:

ts
import { cookies } from 'next/headers';
import { readTrackerIds } from '@reveata/next/server';

const ids = readTrackerIds(await cookies());
// put ids.visitorId / ids.sessionId in the checkout metadata

For Stripe, that means metadata.reveata_visitor_id and metadata.reveata_session_id on the Checkout Session (Stripe Checkout attribution); clientReference(ids) gives the dt_… string for client_reference_id. Other payment providers take the same keys in their own custom data. If you bill yourself, ReveataApi from @reveata/next/server sends payments with a website key (Payments API).

Serving the script from your own domain

A Next.js app can proxy the script and events itself with rewrites and a proxy secret, so fewer visits are lost to ad blockers. See the Next.js section of Proxy through your own server, or use the managed proxy.

Frequently asked questions

Do I need the package?

No. The script tag counts every page view. The package adds typed helpers, the 404 component and server helpers for checkout ids.

Does it count visits on localhost?

No. The script ignores localhost by default, so development visits stay out. With the package, enabled can switch it off outside production too.

Is it different for apps generated with v0?

No. v0 produces Next.js apps, so the same setup applies. See v0 analytics for doing it from v0's chat.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
IntegrationStripe Checkout analytics and attributionAdd the Reveata visitor and session ids to the metadata of each Stripe Checkout Session your server creates. When Stripe reports the payment, Reveata reads the ids and credits the money to the exact visit that started the checkout.Integrationv0 app analytics with ReveataAsk v0 to add the Reveata Script component to app/layout.tsx, then publish. Client-side navigation is counted, and after you connect your payment provider, Reveata's prompt has v0 put the visitor id into the checkout metadata so each payment has a source.IntegrationAngular analytics with ReveataPaste the Reveata snippet before the closing head tag of src/index.html. ng build keeps it in the built page, server-side rendering included, and the Angular Router's History API navigation is counted automatically. HashLocationStrategy needs data-hash="true".IntegrationAstro analytics with revenue attributionPaste the Reveata snippet with is:inline into the Astro layout that renders the head of every page. Astro then leaves the tag as written, view transitions are tracked, and payment links or checkouts started from your pages are credited to the visit behind them.IntegrationDjango analytics with revenue attributionPaste the Reveata snippet before the closing head tag of the base template your Django templates extend. Every page is tracked, the Django admin is not, and two hidden form fields let your checkout view put the visitor id into the payment's metadata.IntegrationDocusaurus analytics for documentation sitesAdd the Reveata script to the scripts array in docusaurus.config.js, or build the entry with @reveata/next/snippet. Page changes inside the docs are tracked by the script, so every page a reader opens is counted.