Docs
← Back to site

Websites your Next.js app serves

2 min readUpdated November 11, 2026

Visits go through your own app on each domain; nothing in the page points to an outside address. They are signed, so the stats count the real visitor and place, not your server.

Add the proxy route#

app/nq/[file]/route.ts
import { createProxy } from 'nahnu-analytics-sdk/next/server';
export const { GET, POST } = createProxy();

The folder name is yours; pass <Analytics base="/…"> if it isn’t /nq.

Add the component#

app/layout.tsx
import { Analytics } from 'nahnu-analytics-sdk/next';

export default async function Layout({ children }) {
  const tenant = await tenantForHost(); // your lookup by host name
  return (
    <html>
      <body>
        {children}
        {tenant && <Analytics siteKey={tenant.siteKey} />}
      </body>
    </html>
  );
}
app/layout.tsx
import { Analytics } from 'nahnu-analytics-sdk/next';

export default async function Layout({ children }) {
  const tenant = await tenantForHost(); // your lookup by host name
  return (
    <html>
      <body>
        {children}
        {tenant && <Analytics siteKey={tenant.siteKey} />}
      </body>
    </html>
  );
}

Page changes in the app are counted by themselves.

<Analytics> optionWhat it does
exclude={['/admin*']}Pages not to count
props={{ plan: 'pro' }}Added to every page view
manualOnly views you send with view() count
hash#/routes count as pages
localhostVisits on localhost count too
nonceFor a Content Security Policy

The visitor’s address#

A visitor can send any header, so the proxy believes only the one your host sets. It detects Vercel (x-real-ip and its location headers), Netlify and Fly; anywhere else it takes the last address in X-Forwarded-For, added by your load balancer.

  • Set trust: 'cloudflare' when the app is only reachable through Cloudflare.
  • On a server with nothing in front, pass ip: (req) => ….

Signing secrets#

The proxy asks the platform API for every site’s secret in one call and keeps them for an hour. A site key it doesn’t know (a new site) triggers one more call, at most once a minute; made-up keys are dropped without costing you requests.

To skip the call, keep site.install.proxy_secret in your database and pass secret: (siteKey) => ….

Was this helpful?