Hosting · 3 min setup
How to use VisitTrack analytics on Vercel
VERCEL_ENV is production, and save your production domain under VisitTrack's allowed hostnames so preview deployments never count.Updated
Vercel hosts whatever framework you deploy — Next.js, SvelteKit, Nuxt, Astro, Remix or a static site — so the install itself follows that framework's guide. What's Vercel-specific is environments: every pull request gets a preview deployment on its own *.vercel.app URL, and you don't want reviewers' clicks in your production numbers.
VisitTrack works the same on any host, which is the main difference from Vercel Web Analytics; for a detailed comparison see VisitTrack vs Vercel Analytics.
Vercel at a glance
- Where the tag goes
- Your framework's root layout (see its guide)
- Production only
- Render when
process.env.VERCEL_ENV === "production" - Preview URLs
- Dropped once you save Allowed hostnames
- CSP
headersinvercel.jsonor your framework config- AI crawlers
- Next.js
proxy.ts/ middleware → docs
How to install VisitTrack on Vercel
Step 2: Render it in production only
Vercel sets
VERCEL_ENVtoproduction,previewordevelopment. Server-rendered layouts can read it directly; this is the Next.js App Router version.app/layout.tsximport Script from "next/script"; const isProd = process.env.VERCEL_ENV === "production"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <body> {children} {isProd && <Script defer data-site="SITE_ID" src="https://visitrack.app/tracker.js" />} </body> </html> ); }Step 3: Save your allowed hostnames
In VisitTrack, open Settings → General → Allowed hostnames and save your production domain (and
*.yourdomain.comfor subdomains). Hits from any other host —*.vercel.apppreviews included — are dropped before they're stored. Blocked hosts are listed for 7 days with an Allow button, so nothing disappears silently.Step 4: Allow VisitTrack in your CSP headers
If you send a Content-Security-Policy from
vercel.json, add the origin toscript-srcandconnect-src. Merge it into your existing policy rather than replacing it.vercel.json{ "headers": [ { "source": "/(.*)", "headers": [ { "key": "Content-Security-Policy", "value": "default-src 'self'; script-src 'self' https://visitrack.app; connect-src 'self' https://visitrack.app;" } ] } ] }
How to check VisitTrack is working on Vercel
- Open a preview deployment — nothing should arrive (no tag, or the host is dropped).
- Open the production domain and browse two pages; VisitTrack's live view shows you within seconds.
- If a host was dropped by mistake, it appears under Blocked hostnames in Settings → General.
Does VisitTrack track Vercel page navigation?
Navigation tracking depends on your framework, not on Vercel: client-side routers (Next.js, SvelteKit, Nuxt, Remix) are followed through the History API, and static sites count one pageview per page load. Vercel's edge caching and ISR don't affect it — the script runs in the visitor's browser.
How to track custom events and goals in Vercel
Custom events are framework code: window.visitrack("signup") in the browser, or POST /api/track from a Vercel Function or server action with a secret API key stored in your Vercel project's environment variables (never with a NEXT_PUBLIC_ prefix).
// A Vercel Function / route handler
await fetch("https://visitrack.app/api/track", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.VISITRACK_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ type: "event", visitorId, name: "signup" }),
});See custom events and server-side events.
Track AI crawlers on Vercel
Crawlers like GPTBot and ClaudeBot never run JavaScript. On a Next.js app on Vercel, report them from middleware (proxy.ts on Next.js 16) — the AI crawler tracking docs include the snippet. Make sure your matcher doesn't skip robots.txt and sitemap.xml, which crawlers fetch first.
Script options you might need on Vercel
All optional — add them to the same tag. Full reference: script configuration.
| Attribute | What it does |
|---|---|
data-cookieless | Store nothing in the browser; the server derives a daily-rotating id. See cookieless mode. |
data-exclude="/app/*" | Never track these paths (comma-separated, * wildcard). Checked on every navigation. |
data-allow-local | Track on localhost and *.local — for testing an install only. |
data-debug | Log every event the script sends, and why it skipped one, to the console. |
data-auto="false" | Turn off automatic events (downloads, contact clicks, form submits, rage clicks, JS errors, 404s). |
Vercel troubleshooting
Preview deployments show up in your stats
Save Allowed hostnames, or render the tag only when VERCEL_ENV === "production".
Production custom domain is being blocked
It isn't in Allowed hostnames. Add it (or use *.yourdomain.com) — it's listed under Blocked hostnames with a one-click Allow.
CSP blocks the tracker after adding vercel.json headers
Both script-src and connect-src need https://visitrack.app. A framework-level CSP (Next.js headers or proxy.ts) can also override it — check the final response header in DevTools.
Server events fail with 401
The VISITRACK_API_KEY env var isn't set for the Production environment in Vercel, or the deployment predates it. Redeploy after adding it.
Vercel analytics FAQ
Can I add VisitTrack on Vercel without changing code?
No. Vercel doesn't inject scripts into your pages, so the tag goes into your framework's layout or index.html. It's a one-time, one-line change.
How do I stop Vercel preview deployments from being tracked?
Save your production domain under Settings → General → Allowed hostnames in VisitTrack, which drops hits from other hosts, or render the tag only when VERCEL_ENV is production.
Is VisitTrack an alternative to Vercel Web Analytics?
Yes. It isn't tied to Vercel hosting, and adds revenue attribution, funnels, journeys, session replays and an API. See VisitTrack vs Vercel Analytics for the trade-offs.
Does Vercel's caching affect VisitTrack?
No. The script runs in the visitor's browser and sends events to visitrack.app, so cached and ISR pages are counted like any other.
Where do I store the VisitTrack API key on Vercel?
In your project's Environment Variables, without a NEXT_PUBLIC_ prefix, so it's only available to server code.
Keep going
- Next.js analyticsAdd VisitTrack to a Next.js App Router or Pages Router app with next/script — client-side route changes are tracked automatically.
- Netlify analyticsAdd VisitTrack on Netlify with Snippet injection (no code) or in your framework, keep deploy previews out, and set CSP in _headers.
- Cloudflare Pages analyticsAdd VisitTrack on Cloudflare Pages in your HTML or with an HTMLRewriter middleware, exclude it from Rocket Loader, and track AI crawlers at the edge.
- SvelteKit analyticsAdd VisitTrack to SvelteKit by adding one tag to src/app.html — client-side navigations are tracked, and kit.csp gets two extra sources.
- Install the tracking scriptThe reference tag, CSP notes and how to check it's working.
- Custom events and signupsvisitrack(), data-vt-goal, scroll events and server-side signups.
- Use casesHow SaaS teams, indie hackers, stores and agencies use VisitTrack.
- VisitTrack vs Google AnalyticsCookie-free analytics with revenue attribution, compared honestly.
Add VisitTrack to your Vercel site
Cookie-free analytics with revenue attribution, live visitors, funnels and session replays. One script tag, every feature on every plan. 14 days free, no card required.
Not on Vercel? See all 29 integration guides.