A Next.js app needs the snippet once, in the layout every route shares. Client-side navigation is counted on its own, so you don't need a route-change listener.
1. Copy your snippet
Open your site in trackr.link and copy its snippet. It looks like this, with your own site id:
<script defer data-site="YOUR_SITE_ID" src="https://pulse.trackr.link/t.js"></script>
2. Add it to the root layout
With the App Router, render it with next/script in app/layout.tsx:
import Script from 'next/script';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
<Script
src="https://pulse.trackr.link/t.js"
data-site="YOUR_SITE_ID"
strategy="afterInteractive"
/>
</body>
</html>
);
}
With the Pages Router, render the same <Script> in pages/_app.tsx, next to <Component {...pageProps} />.
Keep it to one layout. A second copy in a nested layout counts every pageview twice.
3. Navigation between pages
<Link> and router.push() change the URL with history.pushState, and the tracker records each of those as a pageview, as it does the back and forward buttons. router.replace() swaps the URL without a new history entry, so it isn't counted.
The tracker records the path only. /pricing?plan=pro and /pricing#faq count as /pricing, and UTM tags in the query are kept as campaign data.
4. Send custom events from client components
Call the global trackr function after an action succeeds, from a client component:
'use client';
export function SignupForm() {
async function onSubmit(formData: FormData) {
const response = await fetch('/api/signup', {
method: 'POST',
body: formData,
});
if (response.ok) {
window.trackr?.('event', 'signup', { plan: 'free' });
}
}
return <form action={onSubmit}>{/* ... */}</form>;
}
Server components and route handlers run on the server, where there is no window, so send events from the browser only. With TypeScript, declare the function once:
declare global {
interface Window {
trackr?: (
command: 'event',
name: string,
props?: Record<string, string | number | boolean>,
) => void;
}
}
export {};
For a button or link, you can skip the code and add data-trackr-event="cta_click", plus props such as data-trackr-prop-location="hero". The tracker sends the event on click.
5. Development and preview deployments
trackr.link records hits from your site's domain, its subdomains and localhost. Visits to next dev on localhost are counted, while a preview URL such as my-app-git-feature.vercel.app is not, because it isn't on your domain. To keep development out of your numbers, render the <Script> only in production:
<body>
{children}
{process.env.NODE_ENV === 'production' && (
<Script src="https://pulse.trackr.link/t.js" data-site="YOUR_SITE_ID" strategy="afterInteractive" />
)}
</body>
Or keep it everywhere and run localStorage.setItem('trackr_ignore', '1') in the browser console of every browser you develop in. That browser then sends nothing.
6. Content Security Policy
If your app sends a Content-Security-Policy header, from next.config.js or from middleware, allow the tracker's origin in both script-src and connect-src. The script loads from it and sends its hits back to it. With a nonce-based policy, pass the nonce to <Script nonce={nonce}>.
7. Check that it works
Deploy, then open your site in an ordinary browser window and click through a few pages. Your dashboard opens when the first pageview arrives. Hits from automated browsers, such as Playwright or Puppeteer, are dropped as bots, so test by hand.
If you use Claude Code or Codex, copy the setup prompt from your site's page in trackr.link instead. The agent adds the snippet and your events, and saves your goals and funnels.
8. Read your first visits
Every visit counts in a channel, such as Organic Search, Email or AI. Channels and UTM parameters lists the rules that decide which one, and AI traffic shows how visits from ChatGPT, Claude, Perplexity and other assistants are recognized. To tag the links you share in campaigns, use the UTM builder.