- Browser proxy — the Worker serves the Dáva snippet and forwards browser events through your own subdomain (e.g.
collect.yourdomain.com), so no third-party CDN URLs appear in your page source. - Server relay — a dedicated route on the same Worker that your backend calls explicitly to forward server-side events to Dáva. The Worker adds your API key and forwards the payload; your backend supplies the event.
This is your own Worker deployed in your own Cloudflare account. Dáva does not operate this Worker — you are responsible for deploying it, maintaining it, and paying for Cloudflare Workers capacity.
Quickstart
The steps below are the fast path through the browser proxy setup. Each step links to the full detail further down this page and in Install the tracking snippet.1
Dashboard — get your Worker endpoint
Log in to your Dáva workspace → Settings → Workspace → Settings & Integrations. Copy the Worker endpoint URL shown there — this is the value you’ll paste into
DAVA_WORKER_URL below.2
Terminal — check the Wrangler CLI
wrangler is installed and lets you browse all available commands. If it’s missing, install it first: npm install -g wrangler or pnpm add -g wrangler.3
Log in to Cloudflare
login opens a browser to authorize the CLI against your Cloudflare account; whoami confirms which account/email you’re now authenticated as — check this matches the account you’ll deploy the Worker into.4
Terminal — scaffold the Worker
wrangler.jsonc and src/index.ts — you’ll replace both in the next step.5
Paste the template
- In
wrangler.jsonc: setDAVA_WORKER_URLto the value from step 1, keepDAVA_SNIPPET_URLas-is. - In
src/index.ts: setALLOWED_ORIGINSto your real domains (bare domain +www). - Don’t keep both
wrangler.tomlandwrangler.jsoncin the project — Wrangler silently prefers one over the other.
6
Deploy
7
Bind a Custom Domain (Cloudflare dashboard)
Workers & Pages → dava-proxy → Settings → Domains & Routes → Add Custom Domain. Enter your dedicated subdomain, e.g.
collect.yourdomain.com — Cloudflare creates the DNS record and SSL certificate automatically.You do not need to add a Workers Route on your main domain — Custom Domain replaces it and avoids the silent breakage Routes have on sites fronted by another CDN in front of Cloudflare.8
Update the script tag on your site
data-endpoint, or using the wrong path (/_dava/t/event instead of /_dava/events).9
Verify
Quick command-line check before opening the browser — replace
collect.yourdomain.com with your dedicated subdomain:listen.jsshould return200withcontent-type: application/javascript. A TLS error here (unrecognized name/ handshake failure) means the Custom Domain isn’t bound yet or DNS hasn’t propagated — recheck step 6.OPTIONSshould return204withaccess-control-allow-originechoing yourOrigin. If it’s missing, checkALLOWED_ORIGINSinsrc/index.ts.
OPTIONS request should return 204, and POST /_dava/events should return 200. Finally, check your Dáva workspace — new events/sessions should appear in near real time.Browser proxy
Follow the Install method 2 steps in Install the tracking snippet. That guide covers:- Scaffolding a Worker project with
wrangler init - The full
wrangler.jsoncandsrc/index.tstemplate (with CORS,User-AgentandCF-Connecting-IPheader forwarding, and the dedicated-subdomain approach) - Binding a Cloudflare Custom Domain to the Worker
- Updating your script tag to load the snippet through the proxy
Server relay
The server relay is an explicit, named route you add to your Worker. Your backend calls this route when it has a server-confirmed event to record — for example, after a payment gateway confirms a purchase. The Worker receives the payload, adds your Dáva API key, and forwards the request toPOST https://api-v2.davazmysel.com/v1/events.
The relay is not automatic. The Worker does not intercept or auto-detect backend traffic on your subdomain. Your own backend code must call the relay route with the event payload at the appropriate time.
Add the relay route to your Worker
Extendsrc/index.ts from the Install method 2 template with a dedicated relay route. The additions below fit inside your existing fetch handler — add RELAY_PATH to the path constants at the top, add DAVA_API_KEY to the Env interface, add the route check inside fetch, and add the relayServerEvent function at the bottom.
Path constant (add alongside LISTEN_PATH and EVENTS_PATH):
Env interface (add DAVA_API_KEY):
fetch handler, before the pass-through fallback):
src/index.ts):
vars):
Call the relay from your backend
Your backend POSTs the event payload to your relay route. The Worker adds the API key and forwards it to Dáva. Example:At least one of
anonymous_id, contact_id, or hashed_email is required in the payload — the request is rejected with 400 if all three are absent. See Identity for details.subdomain is required because the relay calls api-v2.davazmysel.com directly. Dáva cannot infer the domain from the relay request’s Host header (which is api-v2.davazmysel.com, not your customer domain). See Sending a single event for details.event_id and transaction_id are dedup keys — see Deduplication for the full priority chain. Use properties for any additional domain-specific facts (e.g. properties.sku, properties.plan).
The relay route does not add authentication of its own — it is a backend-to-Worker call that stays server-side and never touches a browser. If you want to restrict which callers can use the relay, add a shared-secret header check inside relayServerEvent before forwarding.
For the full payload field table, deduplication chain, and error codes, see Server-Side Events.
Hybrid setup (recommended)
To link the server event to the browser journey, includedava_session_id in every server event payload.
The flow:
- The browser snippet loads on your page and creates a session.
- Your frontend JavaScript reads the session ID:
window.dava.sessionId - The frontend passes that value to your backend — via a hidden form field, a cookie, or a request body.
- Your backend includes it as
dava_session_idin the payload it sends to the relay route.
dava_session_id threads the server event onto the existing browser session.
Next steps
- Install the tracking snippet — Install method 2 → — browser proxy setup: full Worker template, Custom Domain binding, CORS, and header forwarding
- Server-Side Events reference → — full field table, dedup chain, batch endpoint, and error codes