Proxy setups
Vercel proxy for the Loogika script
On Vercel you proxy Loogika with rewrites in vercel.json. Seven rewrites send the paths under /stats/ to https://app.loogika.com/api/, and Vercel passes on the browser's headers and the visitor's IP address. This page is for static sites and other frameworks on Vercel.
Last updated .
Does the Vercel setup apply to Next.js?
No. A Next.js app on Vercel follows the Next.js proxy page instead, which is written for that framework. The proxy guide explains the idea behind both setups.
How do you add the rewrites to vercel.json?
Create vercel.json in the root of your project, or open the one you have, and add the rewrites below. Each rewrite maps one path the Loogika script uses.
{
"rewrites": [
{
"source": "/stats/script.js",
"destination": "https://app.loogika.com/api/script.js"
},
{
"source": "/stats/replay.js",
"destination": "https://app.loogika.com/api/replay.js"
},
{
"source": "/stats/track",
"destination": "https://app.loogika.com/api/track"
},
{
"source": "/stats/identify",
"destination": "https://app.loogika.com/api/identify"
},
{
"source": "/stats/session-replay/record/:siteId",
"destination": "https://app.loogika.com/api/session-replay/record/:siteId"
},
{
"source": "/stats/site/tracking-config/:siteId",
"destination": "https://app.loogika.com/api/site/tracking-config/:siteId"
},
{
"source": "/stats/site/:siteId/feature-flags/evaluate",
"destination": "https://app.loogika.com/api/site/:siteId/feature-flags/evaluate"
}
]
}
The list covers every path the script calls. The script loads replay.js only when session replay is on for the site. The generic setup page explains what each path does.
Use rewrites and not redirects. A redirect sends the browser on to app.loogika.com, so the request leaves your domain again. A rewrite fetches the answer on Vercel's side and returns it from your domain.
How do you change the script tag?
Load the script from /stats/script.js on your own domain. Keep the file name script.js, because the script uses it to find the address for its events.
<script src="https://yourdomain.com/stats/script.js?siteId=YOUR_SITE_ID" defer></script>
Replace YOUR_SITE_ID with the site ID from Site Settings in Loogika, under the Tracking Script tab.
Do you have to set the IP header on Vercel?
No. A Vercel rewrite forwards the browser's headers and sets X-Forwarded-For to the visitor's IP address by itself. You only tell Loogika to trust the header.
Open Site Settings in Loogika, go to General and turn on First-Party Proxy. With the switch off, Loogika may count your visitors under Vercel's addresses instead of their own.
How do you deploy the proxy?
Commit vercel.json and push. Vercel picks up the change and deploys the site with the new rewrites.
git add vercel.json
git commit -m "Add Loogika proxy rewrites"
git push
How do you check that the Vercel proxy works?
Open the deployed site with the browser's developer tools on the Network tab. The script should load from /stats/script.js, and the POST requests should go to /stats/track. Both should show your own domain and status 200.
Then open the realtime view in Loogika from two different networks, for example your office and your phone. Two visitors in two places mean the IP address arrives correctly.
Does Vercel cache the proxied script?
Vercel can cache a rewrite to another host when the answer carries a Cache-Control header. Loogika sends that header on script.js and replay.js. The POST requests are never cached.
Caching of external rewrites is the default for Vercel projects created on or after 6 April 2026. Older projects have to opt in. Vercel's documentation on rewrites describes how.
Do the rewrites count toward your Vercel bandwidth?
Yes. Every proxied request passes through Vercel, so it counts toward the bandwidth quota of your plan. Session replay sends far more data than pageviews and events, so check the limit of your plan before you turn it on.
Why does the Vercel proxy not work?
| Symptom | Cause and fix |
|---|---|
Requests still go to app.loogika.com | Check that vercel.json sits in the project root and that you deployed after adding it. Check that the script tag uses your own domain, then test in a private window |
The script loads, but /stats/track returns 404 | A rewrite is missing. Compare your file with the seven rewrites above |
| Session replay records nothing | Add the rewrites for /stats/replay.js and /stats/session-replay/record/:siteId |
| Every visitor has the same location | Switch on First-Party Proxy in Site Settings |
The proxy troubleshooting page covers problems that are not specific to Vercel.