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.
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 |
|---|---|---|---|
|
| public or secret | up to 1000 events, 20 MB; valid events are stored, invalid ones listed in |
| one event plus | public or secret | 1 MB; one bad event rejects the request ( |
| as | secret only ( | servers and imports; historical timestamps kept; drains behind live traffic |
|
| public or secret | 10 MB per chunk; three body forms (section 13.1); |
| public / secret | flag evaluation; see the flags part | |
| key with | served Profile API (Profile API) | |
| token / key | pixel, inbound webhooks and log drains | |
| 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 |
|---|---|
| required, non-empty string. Names starting |
| 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 |
| recommended. Must be a UUID. Dedupe key: a repeated |
| optional. RFC 3339 is best; the gateway also reads |
| JSON object; strings over 64 KiB are cut ( |
| objects, at top level or inside |
| client clock; event timestamps are shifted by |
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 |
|---|---|
| accepted. |
| malformed JSON, empty or non-array |
| missing key ( |
| more than 1000 events ( |
| the project lives in another region; send to that region's capture host |
| rate limit or plan quota; wait |
| 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 |
|
Link a second id to a person |
|
Join two already-identified persons (rare) |
|
Set person properties on any event |
|
Attach an event to an account |
|
Create or update a group's properties |
|
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_dangerouslyto 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_aliasis 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=30lists persons that have server events but no browser events: the$identifythat 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 |
|---|---|
| stripped at the gateway, top level and inside |
| dropped unless the project captures IPs ( |
| turn off geo for the event: no country, region, city or lat/long. Set it on server events unless you send |
| store the event without creating or updating a person; with no |
| secret key / s2s only: the end user's address for geolocation (public keys cannot spoof it). |
| free text naming the sender; not validated |
| links an event to a recording with the same |
| do not shift this event's timestamp by client clock skew (historical data) |
| read by web analytics; the browser SDK sets them |
| on a browser UA, |
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 | 1000 ( |
body size | 20 MB batch, 1 MB single |
one event after envelope | about 1 MiB ( |
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 ( |
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:portif not the default),*.domainorhttps://*.domain(any subdomain, not the bare domain) andhttp://localhost:*(any port). Each starts withhttp://,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
Originheader, or the origin ofRefererwhen there is noOrigin. 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 asorigin_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.
Consent and privacy defaults
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, setconsent:{mode:"opt_in"}; then nothing is written or sent until the visitor opts in.optIn()grants analytics and replay but not marketing; marketing needsoptIn(["analytics","replay","marketing"]). Server senders own this decision.Declines can be logged without identifying anyone: an id-less
$consent_updatedevent keeps onlycategories, source, version, $lib. A first-visit decline withlogBeaconis not tied to a person. A withdrawal after a grant is different: it sends$opt_outwith the visitor'sdistinct_idand$session_id, and sets the person's$consent_analyticsand$consent_replaytodenied, so server events for them are dropped later whenserver_event_consentisdrop_deniedorrequire_granted(or the olderdrop_server_events_without_consentis 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'sconsent_modeand geo default fromGET /v1/config(consent_mode,consent_geo_rules); then the page'sconsent.mode; then the SDK defaultopt_out. The project can only make consent stricter: a projectopt_inbeats any page mode, and a projectopt_outnever loosens a pageopt_in. UntilGET /v1/configanswers, 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 toopt_in. A stored decision skips the wait. Conformance vectors:testdata/consent/precedence.json.Clicks but not inputs:
PUT {p}/settings/sdk {"autocapture_inputs":false}(defaulttrue; served inGET /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 settingrespect_gpcinPUT {p}/settings/sdkturns this on for every visitor of the project. Unset, it is on whenconsent_modeisopt_inand off otherwise. ArespectGpcoption set in the page code always wins over the project setting, in either direction.Per-region defaults come from
consent_geo_rulesinPUT {p}/settings/sdk(Consent by location).$lc_ipis set on each event; the worker keeps it as$iponly whenip_captureis on, andip_truncateshortens 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.lucidaQueueis a plain array you create before the script loads. The script drains it in order, then replacespushso later commands run at once. Commands:["init", publicKey, config?](once; laterinits are ignored) and[method, ...args]for any client method (["capture","signed_up",{"plan":"pro"}],["identify","u1"],["optIn"]). Commands sent beforeinitwait for it and for themodulesit loads.window.lucidais the client onceinitran. 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>.jsbefore the client starts; one that fails to load is skipped. Modules are not loaded in extension mode.assetHostanduiHostdefault to the origin the script was loaded from. SetassetHostonly when the module files are hosted elsewhere,uiHostonly when replay links should point elsewhere.apiHostis where events go (defaulthttps://capture.lucidace.com).modules: ["consent"]addsclient.consent.showBanner()and follows the Cookie Munch consent manager: onceCookieMunch.hasResponseis true it maps itsstatisticschoice to analytics plus replay andmarketingto marketing, and it follows Cookie Munch's change events. Use it withconsent: { mode: "opt_in" }. With the npm package, passcookieMunchConsentfrom@lucida-analytics/browser/consentin the module list instead. The preset notes for Cookie Munch are in the repository atdocs/integrations/cookiemunch-preset.md.Subresource Integrity. Every release publishes
/static/v<version>/manifest.jsonwith{version, files: {"lucida.js": "sha384-...", "modules/<name>.js": "sha384-..."}}. Put thelucida.jshash inintegrityand addcrossorigin="anonymous"(the files are served withAccess-Control-Allow-Origin: *). With amanifest.jsonnext 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 aconsole.warnand 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.jsare cached for 300 seconds. A404is alwaysno-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 athttps://lucidace.com/static/v<version>/storage.json, no key needed;GET {p}/storage?format=cookiemunchgives 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 otherlc_*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.