Add pageview tracking
Add your domain, then put the tracking script from your site settings in app/layout.tsx. Pageviews need no npm package.
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<script
async
src="https://clicktag.io/latest.js"
data-hostname="example.com"
data-verify="YOUR_SITE_VERIFY_TOKEN"
/>
</body>
</html>
);
}
The script hooks history.pushState and listens to popstate, so client-side navigation in the App Router records pageviews on its own. The first pageview verifies your site.
Track events
Call window.tt_event("signup") from a client component, or send events from a route handler or server action with POST /events. Events power goals and 2 to 6 step funnels with median and p90 time to convert. See custom events.
Monitor route handlers
Clicktag also tracks your Next.js route handlers. Install the package, then wrap each handler with withClicktag.
npm install clicktag
// app/users/[id]/route.ts
import { withClicktag } from "clicktag/next";
async function getUser(
request: Request,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
return Response.json({ id });
}
export const GET = withClicktag(getUser);
withClicktag works on Next.js 14.2 and newer, in the Node.js or edge runtime. Routes are rebuilt from params, so /users/42 shows up as /users/:id, with requests, status codes, p50, p95 and p99 latency, errors and callers. On Next.js 15.1 and newer, batches go out after the response with after(). Set CLICKTAG_API_KEY in your environment.
Clicktag vs Vercel Web Analytics
Clicktag is free for 50 websites on any host and includes UTM reports, which Vercel puts behind Web Analytics Plus at $10 a month or Enterprise.
| Clicktag | Vercel Web Analytics | |
|---|---|---|
| Free tier | Free, 50 websites | Hobby: 50,000 events a month, collection pauses after a 3-day grace period |
| Paid | None | Pro: $0.03 per 1,000 events on top of the Pro plan |
| UTM parameters | Included | Web Analytics Plus ($10 a month) or Enterprise |
| Hosting | Any host | Vercel deployments |
| Route handler metrics | Yes, with withClicktag |
Not part of Web Analytics |
| Cookies | None | None |
Vercel details checked on September 30, 2026 in Vercel's documentation.
Vercel Web Analytics is the simpler pick if you only deploy on Vercel and want your numbers inside the Vercel dashboard.
FAQ
Does withClicktag slow down responses?
No. It records metrics in memory and sends them in the background, and it never delays a response.
What does the middleware send?
The route template, method, status code, duration, user agent and an optional consumer id. It never sends request or response bodies, query strings, IP addresses or other headers.
Where is the data stored?
In Frankfurt, Germany, collected on Cloudflare's network.
Updated November 23, 2026