Developer guide: 3. Sending data (capture host)

The capture host: batch and capture wire format, responses, identity, reserved properties, flag exposure events, limits, consent and the browser script contract.

Embed
Preview of the card
<a href="https://lucidace.com/help/developer-guide-sending-data"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/2c734164-ecc1-43e4-9e97-ddc576aed580/social-card.svg?v=3e7ae33eec8b" alt="Developer guide: 3. Sending data (capture host)" width="600" height="315"></a>

3. Sending data (capture host)

All ingest routes live on the capture host ($LUCIDA_CAPTURE), not the API host (they are 404 there). The wire contract is also in the OpenAPI under the capture tag; the customer page is Send events over HTTP.

Route

Body

Key

Notes

POST /v1/batch

{api_key, batch:[event,...], sent_at?, historical_migration?, test?}

public or secret

up to 1000 events, 20 MB; valid events are stored, invalid ones listed in rejected. "test": true is a dry run: the key and every event are validated and answered the same way, nothing is stored ("stored": false)

POST /v1/capture

one event plus api_key

public or secret

1 MB; one bad event rejects the request (400). Answers {"status":1}

POST /v1/s2s/batch

as /v1/batch

secret only (401 secret api key required)

servers and imports; historical timestamps kept; drains behind live traffic

POST /v1/replay

{api_key, session_id, seq, events, window_id?} rrweb chunks

public or secret

10 MB per chunk; three body forms (section 13.1); seq is required (400 without), window_id is optional. Reading recordings is a later part

POST /v1/flags, /v1/flags/batch, GET /v1/config, GET /v1/flags/definitions

public / secret

flag evaluation; see the flags part

GET /v1/profiles/{distinct_id}, GET /v1/profiles/groups/{type_index}/{key}

key with profiles:read

served Profile API (Profile API)

GET /v1/p.gif, POST /v1/pixel/sign, POST /v1/hooks/{token}, POST /v1/logdrain/{source}

token / key

pixel, inbound webhooks and log drains

POST /e, /i/v0/e, /capture, /batch, /decide; /track, /engage, /import; /2/httpapi

PostHog, Mixpanel and Amplitude wire formats

project token

compatibility endpoints for migrations

Send the key as api_key in the body, as Authorization: Bearer <key>, as ?api_key=, or (PostHog style) as token. Bodies may be gzip (Content-Encoding: gzip or ?compression=gzip).

An event

curl -sS -X POST "$LUCIDA_CAPTURE/v1/s2s/batch" -H "Authorization: Bearer $SK" -H "Content-Type: application/json" -d '{
  "batch": [
    {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c21","event":"signed_up","distinct_id":"user_123",
     "timestamp":"2026-11-09T10:15:00Z","properties":{"plan":"pro","$geoip_disable":true}},
    {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c22","event":"purchase","distinct_id":"user_123",
     "properties":{"amount":49.5,"currency":"EUR","$groups":{"company":"acme"},"$geoip_disable":true}}
  ]
}'
# {"accepted":2,"rejected":[],"status":1}

Field

Rule

event

required, non-empty string. Names starting $ are Lucida's reserved events

distinct_id

required string (a number or boolean is converted to text; a blank or null id counts as missing). Over 200 bytes it is shortened with a distinct_id_too_long warning. Also read from properties.distinct_id

uuid

recommended. Must be a UUID. Dedupe key: a repeated uuid is dropped, so retry freely with the same one. It is deduped within the project, and in storage only together with the same event name, distinct_id and UTC day; see the capture wire format. A non-UUID discards that event and adds a warning invalid_uuid

timestamp

optional. RFC 3339 is best; the gateway also reads YYYY-MM-DD HH:MM:SS, a date, RFC 1123, and 10 or 13 digit epoch seconds or milliseconds. Unparseable: dropped with an invalid_timestamp warning, arrival time used. offset (ms before now, negative is ahead) beats timestamp

properties

JSON object; strings over 64 KiB are cut ($lc_truncated lists keys). An event over about 1 MiB is 413

$set, $set_once, $groups

objects, at top level or inside properties; a non-object is ignored with a warning. $unset is a list of names

sent_at (batch level)

client clock; event timestamps are shifted by now - sent_at unless the event sets $ignore_sent_at: true

Timestamp clamping: public key outside 30 days back to 1 hour ahead becomes arrival time (and $lc_clock_skew:true is set). Secret key / s2s: past values are kept; more than 23 hours ahead becomes arrival time with a future_timestamp warning. Verified: a 2020 timestamp with a public key was stored at arrival time.

Responses

Status

Meaning

200 {"status":1}

accepted. /v1/batch and /v1/s2s/batch add accepted (count) and rejected:[{index, reason}]; if events were discarded with a note they add warnings:[{index, kind, detail}]. accepted counts only events that were enqueued: rejected events and warned-and-discarded ones (a bad uuid) are not counted. Events that were kept after a fix-up (a bad or future timestamp replaced by arrival time, an over-long distinct_id shortened) are counted and listed in warnings too, so read both rejected and warnings. On /v1/s2s/batch an event older than the project's retention is not stored: it comes back as rejected:[{index, reason:"older_than_retention"}] and no event definition is created

400

malformed JSON, empty or non-array batch, or every event invalid (event 0: event requires \event` and `distinct_id``). Nothing was stored

401

missing key (missing api key), unknown, revoked or expired key (invalid api key), a public key on /v1/s2s/batch, or a personal (user-scoped, even read-only) key on any capture route, which is never accepted there. Authentication runs before body validation, so an empty batch with no key is 401, not 400

413

more than 1000 events (too many events in batch), body too large (request body exceeds size limit), or an event over the envelope limit. Split it

421

the project lives in another region; send to that region's capture host

429

rate limit or plan quota; wait Retry-After seconds. The response also carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset headers, as the API does

503

key lookup or the ingest queue is unavailable; retry

Every error is application/problem+json with type, title, status, detail, instance (the request path) and request_id (also sent as the X-Request-Id header). type is https://lucidace.com/help/problems#<slug>: validation (400 here on the capture host; the API answers a field-level failure with 422, see section 5), unauthenticated (401), payload-too-large (413). Quote request_id when you report a problem.

200 means accepted, not yet queryable: allow a few seconds. Delivery is at-least-once; the same uuid is stored once.

Identity, aliases, groups, person properties

Goal

Event

Link an anonymous id to your user id and set properties

$identify with distinct_id = your id, properties.$anon_distinct_id, optional $set, $set_once

Link a second id to a person

$create_alias with distinct_id and properties.alias

Join two already-identified persons (rare)

$merge_dangerously (alias form)

Set person properties on any event

$set, $set_once (first value wins), $unset

Attach an event to an account

$groups: {"<group_type>": "<group_key>"} (up to 5 group types per project; keys up to 400 chars). This also works on an event with $process_person_profile: false: the event keeps its group links and counts toward group math (unique_groups and friends) although no person is stored

Create or update a group's properties

$groupidentify with properties.$group_type, $group_key, $group_set, $group_set_once, $group_unset

curl -sS -X POST "$LUCIDA_CAPTURE/v1/s2s/batch" -H "Authorization: Bearer $SK" -H "Content-Type: application/json" -d '{
  "batch": [
    {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c31","event":"$identify","distinct_id":"user_123",
     "properties":{"$anon_distinct_id":"anon_77","$set":{"email":"ada@example.com","plan":"pro"},"$set_once":{"first_seen_via":"api"},"$geoip_disable":true}},
    {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c32","event":"$create_alias","distinct_id":"user_123",
     "properties":{"alias":"ada-legacy-id","$geoip_disable":true}},
    {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c33","event":"$groupidentify","distinct_id":"user_123",
     "properties":{"$group_type":"company","$group_key":"acme","$group_set":{"name":"Acme","tier":"gold"},"$geoip_disable":true}}
  ]}'

Verified live with the same three calls (a test run used ids anon_A1 and user_A1 in place of anon_77 and user_123): the person had distinct_ids [ada-legacy-id, anon_A1, user_A1], GET {p}/group_types returned company at index 0, and the group acme had the $group_set properties.

Identity rules that surprise people:

  • An identify never merges two persons that are both already identified (shared device). The merge is refused and the event carries $lc_merge_refused. Use $merge_dangerously to force it. Project identity rules (PUT {p}/identity/rules) can also keep profiles apart.

  • Placeholder ids are never linked: null, undefined, none, anonymous, guest, 0, -1, true, false, nan, unknown, user, id, email, distinct_id, [object object], and blank. The event is stored; the link is not made.

  • In a cookieless project, $create_alias is ignored (ids rotate daily).

  • Identity and person-property changes are processed by the worker, so they show up after a few seconds.

  • Check that the browser identify merge happened. GET {p}/persons/identity_gaps?days=30 lists persons that have server events but no browser events: the $identify that links the browser's anonymous id ($anon_distinct_id) to your user id never arrived, so their funnel steps split across two persons. Fix the sender (send the anonymous id with the server $identify), then re-check.

Reserved properties and server controls

Property

Effect

$lc_* (any name)

stripped at the gateway, top level and inside properties. Server-owned

$ip

dropped unless the project captures IPs (ip_capture)

$geoip_disable: true

turn off geo for the event: no country, region, city or lat/long. Set it on server events unless you send $client_ip; without it the lookup uses the request IP, which is your server's. The project setting geo_enabled:false turns geo off for every event

$process_person_profile: false

store the event without creating or updating a person; with no distinct_id the event's uuid is used. $groups on the event still link it to its groups. Such events count toward unique_groups, group-aggregated funnels and retention (aggregate_by: {groups: ...}) like any other event. They also count in unique users: each distinct_id is one stable person id (the existing person when the id is already linked), so a system actor sending them is one user

$client_ip

secret key / s2s only: the end user's address for geolocation (public keys cannot spoof it).

$lib, $lib_version

free text naming the sender; not validated

$session_id

links an event to a recording with the same session_id

$ignore_sent_at: true

do not shift this event's timestamp by client clock skew (historical data)

$current_url, $host, $pathname, $referrer, utm_*

read by web analytics; the browser SDK sets them

$user_agent / request User-Agent

on a browser UA, $browser, $os, $device_type and friends are derived and replace what you sent. Server UAs (node, python-requests, Go-http-client) or none derive nothing

Reserved event names (case-sensitive): $pageview, $pageleave, $screen, $autocapture, $identify, $create_alias, $merge_dangerously, $groupidentify, $feature_flag_called, $exposure, $survey_shown, $survey_sent, $survey_dismissed, $rageclick, $deadclick, $frustration, $form_start, $form_field_interact, $form_submit, $form_abandon, $opt_in, $opt_out, $web_vitals_ref, $revenue, $exception_seen, $web_vitals. Do not use $ names for your own events. A tracking plan never flags a reserved event as unplanned, and in enforce mode never drops one for being unplanned (its properties are still checked against any definition you wrote for it).

$exception_seen and $web_vitals

The Watchtower browser SDK (@watchtowerobservability/browser 0.5.0 or later) feeds these two events through the Lucida browser SDK. They are sent only after analytics consent is held, and only when Watchtower's client is present.

$exception_seen is one error seen on a page. Properties: wt_event_id, wt_trace_id (when the error has one), message (cut to 300 characters), handled (boolean) and wt_issue_id (only when Watchtower has grouped the error into an issue). Replays use wt_issue_id and wt_event_id to link to the Watchtower issue.

$web_vitals is one sample per page view. Properties: $current_url, lcp_ms, inp_ms, cls, fcp_ms, ttfb_ms (each present only when measured) and rating_worst (good, needs-improvement or poor, the worst of the measured vitals). Watchtower owns web-vitals monitoring; these events are only the link back into Lucida.

Requests whose User-Agent looks like a bot (including curl) get $lc_bot_hint and events from public keys are marked $lc_bot: true. For scripts and servers use a secret key (and /v1/s2s/batch) so events are not treated as crawler traffic.

Server-side flag exposure events

When your server decides a flag itself, report the exposure so experiments can count it. Send both events (either is enough for results; send both to match the SDKs), with the variant as a string:

curl -sS -X POST "$LUCIDA_CAPTURE/v1/s2s/batch" -H "Authorization: Bearer $SK" -H "Content-Type: application/json" -d '{
  "batch":[
   {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c41","event":"$feature_flag_called","distinct_id":"user_123",
    "properties":{"$feature_flag":"new-checkout","$feature_flag_response":"test","locally_evaluated":true,"$geoip_disable":true}},
   {"uuid":"0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c42","event":"$exposure","distinct_id":"user_123",
    "properties":{"$feature_flag":"new-checkout","$feature_flag_response":"test","locally_evaluated":true,"$geoip_disable":true}}]}'

POST /v1/flags on the capture host only decides by default; it records nothing. It writes the pair for each flag it decides (locally_evaluated:false) only when you send "send_exposure":true (section 10.6). Details: Evaluate flags over HTTP.

Geolocation

$country comes from a lookup of the client IP in the DB-IP City Lite database (CC BY 4.0, db-ip.com; refreshed on every deploy). If the IP is unknown, the CDN country header is the fallback. $region (the first-level subdivision's English name, for example Bavaria), $city, $latitude and $longitude come only from the IP lookup, so they are empty when it finds nothing. There is no $timezone: the database carries none. $geoip_disable: true on the event or the project geo switch (geo_enabled:false) turns off all of it, the header fallback included. The IP itself is not stored unless the project keeps IPs (ip_capture). For server events send the end user's address as $client_ip (secret key, /v1/s2s/batch) so the lookup does not use your server's.

Limits and protections

Limit

Value

events per /v1/batch or /v1/s2s/batch

1000 (413 above)

body size

20 MB batch, 1 MB single /v1/capture, 10 MB replay chunk

one event after envelope

about 1 MiB (413 event too large)

string property

64 KiB, longer is cut

distinct id

200 bytes, longer is cut

rate

1000 events/s per project (burst 2000; a batch costs one token per event) and, for public keys, 100 events/s per client IP; see Rate limits

one id flooding

an id above the hot threshold (hot_distinct_id_per_minute in {p}/settings/ingest, default 6000 per minute; all ingest settings) is moved to an overflow lane that skips person processing ($lc_overflow)

Events can also be dropped on purpose, and still answer 200: by an ingest event filter, a transformation drop_event, a traffic shield rule or a bot rule. Check GET {p}/ingestion/warnings (section 4) when counts differ from what you sent.

Limit public-key capture to your own origins

A public key is visible in page source, so anyone can copy it. Set capture_allowed_origins in the ingest settings to accept public-key events only from your sites:

lc -X PUT "$LUCIDA_API/v1/projects/$PROJECT_ID/settings/ingest" \
  -d '{"capture_allowed_origins": ["https://app.example.com", "*.example.com", "http://localhost:*"]}'
  • Entries are https://host (an exact origin, with :port if not the default), *.domain or https://*.domain (any subdomain, not the bare domain) and http://localhost:* (any port). Each starts with http://, https:// or *.. At most 100 entries of 200 characters. Matching ignores case.

  • An empty or unset list allows every origin (the default).

  • The check uses the request's Origin header, or the origin of Referer when there is no Origin. When the list is set, a public-key request with neither header, or from another origin, is dropped.

  • Secret keys are never filtered, so server events pass.

  • The drop still answers 200, because a retry from the same origin would change nothing. The body carries a warning, for example {"status":1,"warnings":[{"kind":"origin_not_allowed","detail":"request origin is not in capture_allowed_origins"}]} on /v1/capture. The drop is counted as origin_not_allowed.

  • This is not authentication: a script outside a browser can send any Origin. Use it to stop stray or copied pages, not an attacker.

  • Respect consent before sending anything about a visitor. The browser SDK's default consent mode is opt_out: a default client stores and sends before any consent. Where consent law applies, set consent:{mode:"opt_in"}; then nothing is written or sent until the visitor opts in. optIn() grants analytics and replay but not marketing; marketing needs optIn(["analytics","replay","marketing"]). Server senders own this decision.

  • Declines can be logged without identifying anyone: an id-less $consent_updated event keeps only categories, source, version, $lib. A first-visit decline with logBeacon is not tied to a person. A withdrawal after a grant is different: it sends $opt_out with the visitor's distinct_id and $session_id, and sets the person's $consent_analytics and $consent_replay to denied, so server events for them are dropped later when server_event_consent is drop_denied or require_granted (or the older drop_server_events_without_consent is on). Describe this in your privacy notice.

  • Replay inputs are masked by the SDK; a non-SDK replay sender must mask before sending (Replay privacy). Form analytics never collects field values.

  • Precedence (the browser SDK, resolveConsentDefault): a visitor's stored decision first; then the project's consent_mode and geo default from GET /v1/config (consent_mode, consent_geo_rules); then the page's consent.mode; then the SDK default opt_out. The project can only make consent stricter: a project opt_in beats any page mode, and a project opt_out never loosens a page opt_in. Until GET /v1/config answers, the SDK holds every storage write and every send (the config request itself carries only the public key); if it has not answered after 3 s, it fails closed to opt_in. A stored decision skips the wait. Conformance vectors: testdata/consent/precedence.json.

  • Clicks but not inputs: PUT {p}/settings/sdk {"autocapture_inputs":false} (default true; served in GET /v1/config) makes the browser SDK autocapture stop input, change and submit events and key counting, while clicks are still captured. It applies once the config has loaded (about the first request of the page). Replay input masking is separate (mask_all_inputs).

  • Global Privacy Control (browser 0.1.15): when the browser sends the GPC signal (navigator.globalPrivacyControl), consent starts denied instead of granted. The project setting respect_gpc in PUT {p}/settings/sdk turns this on for every visitor of the project. Unset, it is on when consent_mode is opt_in and off otherwise. A respectGpc option set in the page code always wins over the project setting, in either direction.

  • Per-region defaults come from consent_geo_rules in PUT {p}/settings/sdk (Consent by location).

  • $lc_ip is set on each event; the worker keeps it as $ip only when ip_capture is on, and ip_truncate shortens it.

The classic script (lucida.js)

For plain HTML, tag managers and site builders, one <script> loads the browser SDK without a bundler. Pin a version and check it with Subresource Integrity:

<script>
  window.lucidaQueue = window.lucidaQueue || [];
  lucidaQueue.push(["init", "lc_pk_...", { apiHost: "https://capture.lucidace.com", consent: { mode: "opt_in" }, modules: ["consent", "replay"] }]);
</script>
<script async src="https://lucidace.com/static/v0.1.18/lucida.js"
        integrity="sha384-PPVSd9WXHzh3I465pKZ3lJV8KG7PL9mRqizi1e0zeAjGosoBATQQfq8/UrrMLoNl" crossorigin="anonymous"></script>

lucida init --framework html [--key lc_pk_...] [--app-host URL] prints this snippet with the current version and its integrity hash filled in (CLI 0.1.6 or later; it writes no files; a missing key is minted when you are logged in, else the lc_pk_... placeholder stays).

  • window.lucidaQueue is a plain array you create before the script loads. The script drains it in order, then replaces push so later commands run at once. Commands: ["init", publicKey, config?] (once; later inits are ignored) and [method, ...args] for any client method (["capture","signed_up",{"plan":"pro"}], ["identify","u1"], ["optIn"]). Commands sent before init wait for it and for the modules it loads. window.lucida is the client once init ran. TypeScript users add /// <reference types="@lucida-analytics/browser/lucida-global" /> (lucida-global.d.ts).

With the npm package, init(key, { exposeGlobal: true }) (or "name") publishes the same client as globalThis.lucida and fires a lucida:ready event on window (browser 0.1.6; off by default, on in @lucida-analytics/next, and from 0.1.15 on by itself when a Watchtower browser SDK is on the page unless you pass exposeGlobal: false). On the server init() returns a no-op client of the same shape (every method does nothing, getSessionId() and getDistinctId() are undefined), so shared code can call it without a window guard.

Consent state: consentStatus() is "pending", "granted" or "denied"; hasOptedOut() is true only after an explicit decline (it is false while pending), hasOptedIn() only after a grant, and onConsent(cb) fires on every change. getDistinctId() returns the same value as the distinctId property. React has useSessionId(), useDistinctId() and useConsent(); Vue has the matching composables.

With a Watchtower browser client on the page (watchtower: { client } or globalThis.watchtower), the Lucida session id is stamped onto it as the lucida.session_id attribute once analytics consent is granted, and updated when the session rotates. Copying exceptions and web vitals into Lucida events needs subscription hooks that Watchtower's browser SDK does not expose yet.

  • modules (an init option, names only): replay, heatmaps, forms, toolbar, guides, inspector, experiments, early-access, consent. Each loads from <assetHost>/static/v<this script's version>/<name>.js before the client starts; one that fails to load is skipped. Modules are not loaded in extension mode.

  • assetHost and uiHost default to the origin the script was loaded from. Set assetHost only when the module files are hosted elsewhere, uiHost only when replay links should point elsewhere. apiHost is where events go (default https://capture.lucidace.com).

  • modules: ["consent"] adds client.consent.showBanner() and follows the Cookie Munch consent manager: once CookieMunch.hasResponse is true it maps its statistics choice to analytics plus replay and marketing to marketing, and it follows Cookie Munch's change events. Use it with consent: { mode: "opt_in" }. With the npm package, pass cookieMunchConsent from @lucida-analytics/browser/consent in the module list instead. The preset notes for Cookie Munch are in the repository at docs/integrations/cookiemunch-preset.md.

  • Subresource Integrity. Every release publishes /static/v<version>/manifest.json with {version, files: {"lucida.js": "sha384-...", "modules/<name>.js": "sha384-..."}}. Put the lucida.js hash in integrity and add crossorigin="anonymous" (the files are served with Access-Control-Allow-Origin: *). With a manifest.json next to the script, the loader also fetches each lazy module and checks it with WebCrypto (SHA-384) against the manifest before running it: a module that differs, one the manifest does not list, or a page without WebCrypto is refused with a console.warn and the client starts without it.

  • Caching. /static/v<x.y.z>/* never changes: Cache-Control: public, max-age=31536000, immutable (one year). The floating aliases /static/v<major>/* (for example /static/v0/) and /lucida.js are cached for 300 seconds. A 404 is always no-store, so a missing file never sticks. Pin the full version when you use SRI: the alias moves with each release, so its hash changes.

  • Storage manifest. Every cookie and storage key the SDK writes is listed in storage.json (shipped in the npm package, and published with each release at https://lucidace.com/static/v<version>/storage.json, no key needed; GET {p}/storage?format=cookiemunch gives the same list as a Cookie Munch preset): its store, whether its name carries the per-project suffix (_ plus the last 8 word characters of the public key), its consent category and why it exists. lc_consent (the visitor's remembered decision) stays after a decline; every other lc_* item is purged when analytics is declined. persistence: "memory" and "none" write nothing.

For the npm package, createClient from @lucida-analytics/browser/core is the small entry; see 15.6 SDKs.

Updated