Skip to main content
The browser sends hits through your relay. Your project key stays on the server. See how web analytics counts, privacy, relay recipes and why a report has no numbers.

Before you start

  1. Add a site in the dashboard, give it its allowed origins and copy its id.
  2. Check that page_view is in the site’s tracking plan. A site without it counts nothing, and the script goes quiet for the page, so custom events are lost too.
  3. Keep a project key in your server’s environment. It never goes into the page.
Install the package:

Add the relay

@getlurk/web provides Next.js, Express and Cloudflare Workers helpers. Name the address header your trusted host overwrites; there is no default or fallback. Never trust a header a visitor controls.
  • With x-forwarded-for, forwardedHops is how many proxies you run. The relay counts that many entries from the right.
  • Behind Cloudflare, use cf-connecting-ip.
  • On Vercel as the first hop, use x-real-ip and x-vercel-ip-country for countryHeader. With a proxy in front, use your outermost trusted proxy’s header.
  • The relay serves the script itself at /api/lurk/script.js, the same version as the relay. It handles any path ending in /script.js, /auto.js or /collect, so mount it only under your own endpoint.
  • It never logs, sends no CORS header, and never passes the key or Lurk’s error text on.

Hosted collection

Hosted collection is coming soon and is not available yet. The relay instructions describe how to prepare your integration.

Add the script

Page views are sent on load and path changes. Send your own events with lurk.track("signup_started", { plan: "pro" }). Both automatic events are off until you set data-outbound-links="true" or data-file-downloads="true". With a bundler, import { lurk } from "@getlurk/web" and call lurk.init({ site: "SITE_ID" }).

Your own copy of the files

Copy both lurk.js and auto.js when you serve the script yourself, into the same folder. The tag adds auto.js next to itself when an automatic event is on.
  • A tag’s integrity attribute does not cover auto.js.
  • A policy that allows scripts by nonce alone, without 'strict-dynamic', blocks auto.js. Allow your own origin, or add 'strict-dynamic'.

Content security policy

With the script and the relay on your own domain:
Inline initialization needs your nonce or hash. The script adds no style, image or frame. For require-trusted-types-for 'script', allow trusted-types lurk-web. It accepts only the sibling auto.js URL; no default policy is needed. With a nonce and 'strict-dynamic', the browser ignores 'self' in script-src. Put your nonce on the script tag: auto.js, which the script adds, is then trusted too. A tag without the nonce does not load.

The default tracking plan

A site stores only declared hits and properties. New sites start with this plan:
  • The three properties are text, and are declared only when they fit within the project’s properties per site.
  • A site made before the plan, or one whose plan you edited, may lack them: check before you switch an event on.
  • A hit with a property the site did not declare is rejected whole. A hit name it did not declare is counted as unknown and nothing is stored.

Limits

A batch above your project’s batch size is deferred whole. Nothing is stored and no number in the dashboard shows it, so enable debug first. Counts are a lower bound. When a page closes, hits go out as a beacon whose answer cannot be read, and the browser holds only 64 KiB of them. Hits held back by that are lost. Each project has a monthly limit of accepted hits, counted per UTC month. At the limit Lurk accepts no new hits and the Web tab says “This month’s limit is reached.”; the count starts again on the 1st at 00:00 UTC. Lurk can pause collection for a project. The Web tab says “Lurk paused collection for this project.” Hits sent during a pause are not kept and not collected later.

Privacy

  • The script sends nothing for a browser that sends Global Privacy Control or Do Not Track, and the relay checks those headers again and sends nothing. Nothing about that visitor reaches Lurk.
  • lurk.optout() stops counting a visitor on this and later page loads.
  • Without consent, one thing is stored on the device: the visitor’s opt-out, in localStorage under the key lurk_optout. Name that key in your privacy notice, apart from analytics storage.
  • After lurk.consent(true), with identified analytics on and the relay in mode full, your relay sets one cookie, lurk_vid, that holds a random visitor id for at most 13 months. lurk.consent(false) removes it.

What the browser gets back

The relay itself answers 403 for a missing or foreign Origin, 413 over its size limit, 405 for the wrong method (HEAD included) and 204 for a visitor who sent GPC or DNT. A site that is off, or a bot, is answered 200 without a ready visit.