Proxy setups
Troubleshoot a Loogika proxy
Most proxy problems come from four causes: a path that is not forwarded, a request body that gets lost, missing browser headers or a missing visitor IP address. Start in the Network tab of your browser and find the first request under your proxy path that fails. The sections below are ordered by symptom.
Last updated .
Which paths must the proxy forward?
The proxy must forward seven paths to https://app.loogika.com/api/. The table uses /stats as the proxy path, as in the proxy guide.
| Path on your domain | Method | What fails without it |
|---|---|---|
/stats/script.js | GET | Nothing loads |
/stats/track | POST | No pageviews or events arrive |
/stats/site/tracking-config/:siteId | GET | The script ignores your tracking settings and runs on its defaults |
/stats/identify | POST | identify() and setTraits() fail, so no traits are stored |
/stats/site/:siteId/feature-flags/evaluate | POST | Feature flags cannot be evaluated |
/stats/replay.js | GET | Session replay cannot start |
/stats/session-replay/record/:siteId | POST | Recordings are not saved |
On its defaults the script tracks pageviews, route changes in single-page apps, query strings and outbound links. Session replay, error tracking and Web Vitals stay off, and so do button clicks, copy tracking and form tracking. Web Vitals are part of script.js, so they need no path of their own.
Why does script.js return 404?
A 404 means the proxy rule did not match or points at the wrong address. Check these points in order:
- The rule is active. Restart the Next.js server, reload nginx, validate the Caddyfile with
caddy validate, or check the route of your Cloudflare Worker. - The destination contains
/api. The path/stats/script.jsmust map to/api/script.js. - The source path in the rule is the same path as in your script tag.
- The file is still called
script.js. The script works out where its events go by cutting its own address at/script.js.
You can test Loogika directly with the command below. It should return status 200 and a JavaScript content type.
curl -I https://app.loogika.com/api/script.js
Why does script.js return HTML instead of JavaScript?
Your app answered the request before the proxy did. The response has status 200 and the content type text/html, and the console reports an unexpected < token.
Move the proxy in front of your app's own routing. In Express, register the proxy above any catch-all route. In Laravel, place the proxy routes at the top of routes/web.php. Next.js applies rewrites before it looks for a page, so the order needs no change there.
// Proxy first, catch-all route after
app.use('/stats', proxyMiddleware);
app.get('*', (req, res) => res.sendFile('index.html'));
Why does the script load while no events arrive?
The requests to /stats/track fail or arrive empty. Look at the status of those POST requests in the Network tab and compare it with the table.
| What you see | Cause | Fix |
|---|---|---|
404 on /stats/track | Only the script is proxied | Forward all seven paths |
400 on /stats/track in Express | A body parser read the body before the proxy | Register the proxy before express.json(), or use fixRequestBody from http-proxy-middleware |
| 419 in Laravel | CSRF protection blocks the POST request | Exclude the proxy paths from the CSRF check |
| The POST arrives as a GET, or without a JSON content type | The proxy changes the method or drops Content-Type | Forward the method, the body and the Content-Type header unchanged |
The Express page and the Laravel page show the code for the two framework fixes.
Do you need to add CORS headers in the proxy?
No. CORS only matters when the script loads from another origin than your pages, for example a subdomain. Loogika sets the CORS headers itself and returns the origin of your page in Access-Control-Allow-Origin.
Let those headers pass through untouched. A cors() middleware in front of an Express proxy replaces Loogika's headers with its own, so remove it from the proxy path.
Why do all visitors show the same location?
Loogika sees the IP address of your proxy and not the visitor's. All visits then share one location, and separate visitors can merge into one.
- Make the proxy send the visitor's IP address in
X-Forwarded-For. - Turn on First-Party Proxy under Site Settings, General, so Loogika trusts that header.
- If a CDN or load balancer sits in front of your proxy, configure the proxy to read the visitor's address from it. Otherwise you forward the address of the CDN.
When the visitor's address is missing, never put a fixed one such as 127.0.0.1 in its place. In an Express proxy, req.ip holds the visitor's address once you have configured trust proxy:
createProxyMiddleware({
target: 'https://app.loogika.com/api',
changeOrigin: true,
on: {
proxyReq: (proxyReq, req) => {
proxyReq.setHeader('X-Forwarded-For', req.ip);
},
},
});
Why does track return 200 while the dashboard stays empty?
Status 200 from /stats/track does not prove that Loogika stored the event. Loogika also answers 200 when it filters the event as bot traffic, when one of your exclusions matches, or when the site is over its monthly limit.
If tracking works without the proxy and fails with it, bot filtering is the likely cause. A proxy can trigger it in two ways, and many server-side proxies do both.
The proxy removes the browser's headers
Every real browser sends a set of headers, and the bot detection in Loogika checks them. The set includes Accept and Accept-Language, the Sec-Fetch headers from Chrome, and Accept-Encoding with gzip. A proxy that forwards only the user agent and the IP address looks like an automated client.
Forward all incoming request headers, apart from Host, Connection and Content-Length. Proxies written by hand in PHP often pick a few headers and drop the rest:
// Forward everything except Host and hop-by-hop headers
$headers = [];
foreach (getallheaders() as $name => $value) {
if (!in_array(strtolower($name), ['host', 'connection', 'content-length'])) {
$headers[] = "$name: $value";
}
}
$headers[] = 'X-Forwarded-For: ' . $_SERVER['REMOTE_ADDR'];
Loogika sees a data centre address
Proxies usually run in a data centre. When the visitor's IP address is missing, every visit carries a data centre address, and that counts toward the bot score. Set X-Forwarded-For and turn on First-Party Proxy, as described in the section about location.
The script troubleshooting page covers the causes that have nothing to do with the proxy.
Why does session replay not record through the proxy?
Session replay needs two paths of its own, /stats/replay.js and /stats/session-replay/record/:siteId. Pageviews work without them, so a missing replay path is not obvious at first.
Replay requests can also be large. Loogika accepts bodies of up to 10 MB, so your proxy must not cut them off earlier. In nginx you raise client_max_body_size to 10M for the record path. An Express proxy streams the body through, as long as no body parser runs first.
Why do changed settings or a new script version not show up?
Your proxy or CDN caches the response for too long. Cache script.js for one hour at most, and the tracking settings under /stats/site/tracking-config/ for five minutes at most.
Loogika already serves script.js with a cache lifetime of one hour, so a proxy that passes the header through needs no cache rules. If old content still appears, clear the cache of your proxy or CDN, or stop caching the settings path.
What should you check on your platform?
| Platform | Symptom | Fix |
|---|---|---|
| Next.js | Rewrites have no effect | Restart the development server and declare rewrites as an async function |
| nginx | 502 Bad Gateway | Add proxy_ssl_server_name on;. Add a resolver line if proxy_pass contains a variable |
| Vercel | 404 after deployment | Commit vercel.json and read the build log for errors |
Each platform has its own page with the full configuration: Next.js, nginx, Caddy, Vercel, Cloudflare Workers, Astro, Express and Laravel.
What if none of this helps?
Write to [email protected] and include the details that let us reproduce the problem. Name your framework or platform and paste the proxy configuration. Add a screenshot of the failing request in the Network tab and any error from your server log.