How to install Clerion on Next.js and Vercel
Add the Clerion script with next/script in app/layout (or pages/_document on the Pages Router), push so Vercel builds a new production deployment, then open the live site once. Client-side route changes count as pageviews, and data-disabled keeps preview deployments out of your numbers.

To install Clerion on a Next.js site hosted on Vercel, add the Clerion script with next/script in your root layout, app/layout, then push so Vercel builds a new deployment. Open the live site once and the first visit shows up on the install screen, with AI-assistant referrals counted from that point on.
14-day trial, no card to sign up.
What do I need before I start?
Three things: a Clerion account, your site added in Clerion, and access to the repo Vercel deploys from. When you add your site, Clerion reads the page, recognises Next.js, and shows the steps for it next to your snippet, according to the Clerion quickstart.
Copy the snippet from that screen. It carries your real tracking key (starting cle_) and site id (starting site_). The examples below use placeholders, so do not paste them as they are.
Where does the script go in the App Router?
In the root layout, so it loads on every route. The Clerion script tag reference gives this version for Next.js:
// app/layout.tsx
import Script from "next/script";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://api.getclerion.com/sdk/clerion-analytics.js"
data-api-key="YOUR_API_KEY"
data-website-id="YOUR_WEBSITE_ID"
strategy="afterInteractive"
/>
</body>
</html>
);
}
afterInteractive is the default strategy of the Next.js Script component. The Next.js Script docs describe it as loading early, after some of the page has hydrated, which suits analytics: it does not hold up the first render.
If you would rather not use next/script, the Clerion install docs also allow pasting the plain <script> tag inside <head> in app/layout. Pick one, not both.
What about the Pages Router?
On the Pages Router, the install docs point to pages/_document. That file renders the <html>, <head> and <body> for every page, and the Next.js custom document docs note it is only rendered on the server. Put the tag inside <Head> there:
// pages/_document.tsx
import { Html, Head, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en">
<Head>
<script
src="https://api.getclerion.com/sdk/clerion-analytics.js"
data-api-key="YOUR_API_KEY"
data-website-id="YOUR_WEBSITE_ID"
></script>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
Are client-side route changes counted?
Yes. The install docs say client-side route changes are counted as pageviews, so moving between pages with next/link shows up like any other visit. You do not need a router listener.
How do I keep Vercel preview deployments out of my numbers?
Every pull request on Vercel gets a preview deployment, and you and your team will click around in them. Clerion has a data-disabled="true" attribute that turns tracking off entirely, meant for a staging site that shares the template.
Vercel sets a system environment variable, VERCEL_ENV, to production, preview or development, as the Vercel system environment variables docs describe. The root layout is a Server Component by default, so it can read that value:
<Script
src="https://api.getclerion.com/sdk/clerion-analytics.js"
data-api-key="YOUR_API_KEY"
data-website-id="YOUR_WEBSITE_ID"
data-disabled={process.env.VERCEL_ENV === "production" ? undefined : "true"}
strategy="afterInteractive"
/>
If the variable is not set, open your project's Environment Variables settings on Vercel and turn on access to System Environment Variables. To leave your own browser out of production numbers too, run localStorage.setItem("clerion_ignore", "true") once in the console on your live site.
Should the key go in an environment variable?
It can, but it does not have to. The tracking key sits in a public script tag, so anyone who views your page source can see it either way. If you keep it in NEXT_PUBLIC_CLERION_KEY for tidiness, know two things from the docs:
| Rule | Source |
|---|---|
NEXT_PUBLIC_ values are inlined into the browser bundle at build time, so changing one needs a new build |
Next.js environment variables |
| A changed Vercel environment variable only applies to new deployments, not previous ones | Vercel environment variables |
So after you add or change the value on Vercel, redeploy.
How do I check it worked?
Push, wait for the production deployment, then open the live URL in another tab. The check your installation page says the install screen updates on its own, Clerion emails you when the first visit lands, and the live pulse on the Overview updates every 30 seconds.
If nothing arrives, the install screen has a "Pasted it? Check my site" button that fetches your live page and says whether the snippet is there, missing, or carrying an old key. The usual causes on Next.js:
- The code is on a branch that only built a preview. Merge to the production branch, or check the production URL rather than the preview one.
- Your strict Content Security Policy blocks it. If you set CSP headers in
next.configor middleware, allow the Clerion script source and its collection endpoint inscript-srcandconnect-src. The exact hosts are shown with your snippet in the dashboard. - The tag is there twice. A Script in the layout and a tag in a page count every visit twice. Keep one.
- Your browser sends Global Privacy Control or Do Not Track. Clerion does not count those visits, so test from a normal browser.
- It was loaded through Google Tag Manager. Ad blockers block tag managers, so the tag never runs. Load it directly as above.
To watch events as they go out, add data-debug="true" and open the browser console. Remove it afterwards.
What does Clerion count once it is live?
Pageviews, sources and campaigns, referrals from ChatGPT, Perplexity, Claude, Gemini and Copilot as their own channel, clicks and scroll depth, Core Web Vitals and JavaScript errors, all without configuration. Bots are detected and left out. Signups and purchases need one call each with the custom events API, which is what lets you see revenue by source, as in how to track revenue from ChatGPT traffic.
For other platforms, the general guide is paste this one line. For what to watch once data arrives, see analytics for an AI startup and is ChatGPT sending me traffic.
What is Clerion?
Clerion is website intelligence for AI founders. You add it with one script tag. It sets no cookies, needs no consent banner, keeps data in the EU, and never sells it. It counts AI-assistant visits as their own channel, shows revenue by source, and each morning says the one thing worth doing, with your own numbers as the evidence. The model only sees aggregates.
What is the next step?
Add your site, copy the snippet, put it in app/layout, and push. Clerion gets sharper once it has about a week of data, so the sooner the deploy goes out, the sooner the first useful briefing arrives.
Add Clerion to your Next.js site
14-day trial, no card to sign up. A card is only asked if you start a paid plan trial from the upgrade modal.
Frequently asked questions
What do I need before I start?
A Clerion account, your site added in Clerion, and access to the repo Vercel deploys from. When you add your site, Clerion recognises Next.js and shows the steps for it next to your snippet. Copy that snippet; it carries your real tracking key and site id.
Where does the Clerion script go in the Next.js App Router?
In the root layout, app/layout, so it loads on every route. Render it with next/script and the afterInteractive strategy, or paste the plain script tag inside head in that file. Pick one, not both.
Where does the script go on the Pages Router?
In pages/_document, inside Head. That file renders the html, head and body for every page and is only rendered on the server.
Are client-side route changes counted as pageviews?
Yes. Client-side route changes are counted as pageviews, so moving between pages with next/link shows up like any other visit. You do not need a router listener.
How do I keep Vercel preview deployments out of my numbers?
Set data-disabled to true when VERCEL_ENV is not production. Clerion's data-disabled attribute turns tracking off entirely, which is meant for a staging site that shares the template. Every pull request on Vercel gets a preview deployment, so this keeps those visits out.
How do I check that Clerion is installed on Vercel?
Push, wait for the production deployment, then open the live URL in another tab. The install screen updates on its own, Clerion emails you when the first visit lands, and the live pulse on the Overview updates every 30 seconds. If nothing arrives, use the Pasted it? Check my site button.
Sources
- Quickstart (Clerion docs)
- Install on your platform (Clerion docs)
- Script tag (Clerion docs)
- Check your installation (Clerion docs)
- Custom events (Clerion docs)
- Script Component (Next.js docs)
- Custom Document (Next.js docs)
- System environment variables (Vercel docs)
- Environment Variables (Next.js docs)
- Environment Variables (Vercel docs)