Proxy
Serve it through your own domain
Some ad blockers drop requests to analytics hosts, so a share of your visitors never shows up. You can serve the script and send its events through your own domain instead: everything under /va/ on your site forwards to Viakite, and the requests stay first-party.
The quickest way: open Analytics → Install in the dashboard and turn on Use a proxy under Serve from your domain. Pick your host, and the page gives you the config with your region's address filled in, and the snippet that loads from your domain.
How it works
Your region's API host answers the two proxy paths itself, so your proxy forwards them unchanged:
| Your path | Forwards to | What |
|---|---|---|
/va/a.js | https://us.api.vk.viabio.me/va/a.js | The script |
/va/e | https://us.api.vk.viabio.me/va/e | The events |
Use the address the Install page shows: it is your region's.
Then load the script from your domain and point data-api at the events path:
1<script defer src="/va/a.js" data-project="pk_live_us_…" data-api="/va/e"></script>
With the npm package or a framework component, pass the same address as api:
1<Analytics project="pk_live_us_…" api="/va/e" />
1import { init } from "@viakite/sdk";23init({ project: "pk_live_us_…", api: "/va/e" });
The package is bundled with your app, so with npm or a component only /va/e is used.
Pass the visitor on
Viakite counts visitors from a hash of their IP address and user agent (see Privacy). Through a proxy, the request comes from your proxy, so it must pass the visitor's IP address in the X-Forwarded-For header and keep their User-Agent. Viakite reads the first address in X-Forwarded-For. Without it, every visitor looks like your proxy and is counted as one.
Countries and cities come from the edge in front of Viakite, which through a proxy sees your proxy, not the visitor. A proxy that knows the visitor's location can send it, and Viakite uses it first:
| Header | Value |
|---|---|
X-Viakite-Country | Two-letter country code, IN |
X-Viakite-Region | Region name, URL-encoded |
X-Viakite-City | City name, URL-encoded |
The Cloudflare Worker below sends them. On the other hosts, locations are where your proxy's requests come from.
Next.js
Rewrites in next.config.ts forward both paths, on Vercel and with next start:
1import type { NextConfig } from "next";23const nextConfig: NextConfig = {4async rewrites() {5return [6{ source: "/va/a.js", destination: "https://us.api.vk.viabio.me/va/a.js" },7{ source: "/va/e", destination: "https://us.api.vk.viabio.me/va/e" },8];9},10};1112export default nextConfig;
Vercel
For any framework on Vercel, in vercel.json at the root of the project:
1{2"rewrites": [3{ "source": "/va/a.js", "destination": "https://us.api.vk.viabio.me/va/a.js" },4{ "source": "/va/e", "destination": "https://us.api.vk.viabio.me/va/e" }5]6}
Cloudflare Workers
Create a Worker (Workers & Pages → Create → Worker), replace its code with this and deploy it. Then add a route for your-site.com/va/* on your site's zone (Settings → Domains & Routes).
1const VIAKITE = "https://us.api.vk.viabio.me";23export default {4async fetch(request) {5const url = new URL(request.url);6if (url.pathname !== "/va/a.js" && url.pathname !== "/va/e") return fetch(request);7const headers = new Headers(request.headers);8headers.delete("cookie");9headers.set("X-Forwarded-For", request.headers.get("CF-Connecting-IP") || "");10const cf = request.cf || {};11if (cf.country) headers.set("X-Viakite-Country", cf.country);12if (cf.region) headers.set("X-Viakite-Region", encodeURIComponent(cf.region));13if (cf.city) headers.set("X-Viakite-City", encodeURIComponent(cf.city));14const init = { method: request.method, headers, body: request.body };15return fetch(VIAKITE + url.pathname, init);16},17};
Nginx
In your site's server block, then reload Nginx:
1location /va/ {2proxy_pass https://us.api.vk.viabio.me;3proxy_set_header Host us.api.vk.viabio.me;4proxy_ssl_server_name on;5proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;6proxy_set_header Cookie "";7}
Nginx passes the visitor's User-Agent on by default.
CloudFront
In your distribution:
- Origins → Create origin: origin domain
us.api.vk.viabio.me, protocol HTTPS only. - Behaviors → Create behavior: path pattern
/va/*, the Viakite origin, all HTTP methods allowed, cache policy CachingDisabled, origin request policy AllViewerExceptHostHeader.
CloudFront adds the visitor's address to X-Forwarded-For on its own.
Check it
See the requests
Open
/va/a.json your site: it shows the script. Then open a page with the browser's network panel: each event is aPOSTto/va/ethat answers202.See the events arrive
Open Analytics → Install in the dashboard. Last events shows your visit within a few seconds, with your browser. Visit from a second device: Realtime should show 2 visitors, not 1.