Proxy setups
Proxy setup for Loogika on any server
Any reverse proxy can serve Loogika from your own domain. Forward one path, such as /stats/, to https://app.loogika.com/api/, pass on the browser's headers and send the visitor's IP address. This page lists the paths, the headers and the rules that apply to every server.
Last updated .
What do you need before you start?
You need three things. The proxy guide explains why a proxy on your own domain lets more visits through.
- A domain or subdomain that serves pages over HTTPS.
- A server or hosting platform that can forward requests to another host. That feature is called a reverse proxy.
- Your site ID. You find it in Site Settings in the Loogika dashboard, under the Tracking Script tab.
Some platforms have their own page with a finished configuration. See Nginx, Caddy, Cloudflare Workers, Vercel, Next.js, Astro, Express and Laravel.
Which paths does the proxy have to forward?
The Loogika script uses seven paths. The examples on this page place them under /stats/ on your domain, and each one maps to the same path under /api/ on app.loogika.com.
| Path on your domain | Method | Used for |
|---|---|---|
/stats/script.js | GET | The tracking script |
/stats/track | POST | Pageviews and events |
/stats/site/tracking-config/SITE_ID | GET | The tracking settings you chose for the site |
/stats/identify | POST | User IDs and traits from identify() and setTraits() |
/stats/replay.js | GET | The session replay recorder. The script loads it only when session replay is on |
/stats/session-replay/record/SITE_ID | POST | Session replay data |
/stats/site/SITE_ID/feature-flags/evaluate | POST | Feature flags. The script calls it only when the site uses them |
The shortest rule forwards everything under /stats/ to /api/ and keeps the rest of the path. Web Vitals need no path of their own, because the measuring code is part of script.js.
What happens if you forward only the script and the track path?
Pageviews still arrive, but the script cannot read your tracking settings. It then runs on its built-in defaults and ignores what you chose in Site Settings.
With the 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. Calls to identify() and setTraits() fail, so Loogika stores no traits.
Which rules must every proxy follow?
- Keep the file name
script.js. The script works out where its events go by cutting its own address at/script.js. A renamed file therefore sends them to the wrong place. - Keep the method and the body of each request. A POST must arrive at Loogika as a POST with the same content.
- Pass on every request header from the browser except
Host. SetHosttoapp.loogika.comor let your proxy fill it in. - Send the visitor's IP address in
X-Forwarded-For. - Allow request bodies of up to 10 MB on the session replay path. Recordings are larger than events.
- Use a rewrite or a proxy rule, not a redirect. A redirect sends the browser back to
app.loogika.com.
Which headers does Loogika need from the browser?
Loogika needs the headers that every real browser sends. Bot detection scores each request on them, and a request without them looks like it came from a script. A proxy that forwards only the user agent can therefore get real visits marked as bots. The bot detection page describes the signals.
Forwarding all headers is the safe choice. If your proxy needs an explicit list, include at least these:
| Header | Why Loogika needs it |
|---|---|
User-Agent | Browser and device detection, and bot detection |
X-Forwarded-For | The visitor's IP address |
Accept-Language | Bot detection |
Accept | Bot detection |
Accept-Encoding | Bot detection. The value must include gzip |
Sec-Fetch-Site and Sec-Fetch-Mode | Bot detection for Chrome and other Chromium browsers |
Content-Type | Reading the body of POST requests |
How do you pass on the visitor's IP address?
Set X-Forwarded-For to the visitor's address in the proxy, then turn on First-Party Proxy under Site Settings, General. With the switch on, Loogika reads X-Real-IP first and then the first address in X-Forwarded-For. Setting both headers to the same address does no harm.
Do not rely on X-Real-IP alone. Some platforms cannot send that header to another host, and Amazon CloudFront is one of them. On CloudFront, a CloudFront Function on the viewer request can set the header that works:
// CloudFront Function (viewer request)
function handler(event) {
event.request.headers["x-forwarded-for"] = { value: event.viewer.ip };
return event.request;
}
How do you change the script tag?
Replace app.loogika.com/api in the script tag with your own domain and path. The script then sends every request to the address it was loaded from.
<!-- Before -->
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
<!-- After -->
<script src="https://yourdomain.com/stats/script.js?siteId=YOUR_SITE_ID" defer></script>
Should you use a path or a subdomain?
Both work. A path such as yourdomain.com/stats/ needs no extra DNS record and no extra certificate. Check that the path does not clash with a route your site already uses.
A subdomain such as stats.yourdomain.com keeps the proxy apart from your site. You then forward the whole subdomain to /api/, and the script address becomes https://stats.yourdomain.com/script.js. The subdomain needs its own DNS record and HTTPS certificate.
Should the proxy cache anything?
Caching is optional. If you cache, limit it to the three GET paths and never cache a POST request, because each one carries a new event.
Cache-Control: public, max-age=3600 # script.js and replay.js
Cache-Control: public, max-age=300 # site/tracking-config
Cache-Control: no-store # track, identify and the other POST paths
Keep the tracking settings short-lived. A long cache time delays the changes you make in Site Settings.
How do you check that the proxy works?
Open your site with the browser's developer tools on the Network tab. The request for /stats/script.js and the POST requests to /stats/track should go to your own domain and return 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 header arrives correctly. If something is off, the proxy troubleshooting page lists the common causes.