Developer guide: 4. Events, persons, groups and data management
Events, persons, groups, definitions and the data catalogue, privacy and deletion.
4. Events, persons, groups and data management
Reads need insight:read (events), person:read (persons, groups) or settings:read (rules); writes need the matching :write. Use *:read for a read-only key. Results lag ingestion by seconds; retry for up to ~30 s after a send.
Events
Method and path | Scope | Purpose |
|---|---|---|
|
| newest first. Query: |
|
| server-sent events: polls and pushes new rows; keep the connection open and read the stream ( |
|
| CSV |
|
|
|
|
| who is on the site now |
lc "$LUCIDA_API/v1/projects/$PROJECT_ID/events?event=purchase&prop_key=currency&prop_value=EUR&limit=5" \
| jq '.data[] | {event, distinct_id, timestamp, amount: .properties.amount}'A row is {uuid, event, distinct_id, person_id, timestamp, properties}; the page also has next_cursor, newer_cursor, older_cursor. The endpoint never returns an error for a huge limit; it just caps it (the house convention for lists: a value above the route's maximum is clamped, 0 is 400). A malformed limit or cursor is 400.
Persons
A person is one human with one or more distinct_ids and merged properties.
GET {p}/persons and the routes below are management routes for tools, exports and admin screens, not something to call on every request. To read one person from your server per request (personalization, agents), use the gateway's Profile API: edge-cached, one key with the profiles:read scope.
Method and path | Scope | Purpose |
|---|---|---|
|
| search. Query: |
|
| one person with properties (masked unless |
|
|
|
|
| their events ( |
|
| their session recordings (reading replays is a later part) |
|
| memberships, evaluated flags, groups, property history; all cursor-paginated |
|
|
|
|
|
|
|
| CSV export |
|
| start a DSAR export (async; see Privacy) |
|
| erasure request (async |
PID=$(lc "$LUCIDA_API/v1/projects/$PROJECT_ID/persons?distinct_id=user_123" | jq -r '.data[0].id')
lc -X PATCH "$LUCIDA_API/v1/projects/$PROJECT_ID/persons/$PID/properties" \
-d '{"set":{"company_size":"50"},"unset":["first_seen_via"]}'GET {p}/profiles/{distinct_id} and GET {p}/profiles/groups/{type_index}/{key} (profiles:read or person:read, ?events=N) return the same served profile the gateway edge returns.
Groups and group types
Method and path | Scope | Purpose |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
| properties, |
|
|
|
|
| events of the group |
|
| owner links |
|
| account tasks |
|
| CSV |
A group type by name. Wherever a query takes a group type index you may send the type's name (group_type from GET {p}/group_types) instead: in math ({"unique_groups":"workspace"}, weekly_active_groups, monthly_active_groups), aggregate_by ({"groups":"workspace"}), the group_index of a filter or a breakdown, and in saved insights and dashboard tiles (a saved query keeps the name you sent, so it survives an index being reassigned). Name resolution is per project. A name the project has no type for, or an index with no type defined, is 400 naming it and listing what is defined (group type "workspace" is not defined in this project (defined: company=0)). The profile routes take it in the path as well: GET {p}/profiles/groups/{type}/{key} and GET /v1/profiles/groups/{type}/{key} on the capture host ({type} is a name or an index 0 to 4). The other /groups/{type_index}/... management routes still take the numeric index.
Identity
GET/PUT {p}/identity/rules (settings:read / admin): {types:[{name, priority, limit, source:"distinct_id"|"property", pattern, property}]}, up to 20 types; a merge that would leave a profile with more values of a type than limit (0 is unlimited) is refused. POST {p}/identity/rules/test {a, b, types} dry-runs a merge. The worker picks changes up within 60 s.
Definitions and the data catalogue
Event and property definitions are created automatically from traffic. Edit them to document, verify, hide or deprecate.
Method and path | Scope | Purpose |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
| hard delete of the definition and its property definitions ( |
|
|
|
| read / write | preview-type overrides |
|
|
|
|
| one change for up to 500: |
|
| round-trips through import |
|
| body is CSV ( |
|
| newly seen event names to triage |
|
| suggested events; hidden properties and warehouse objects |
lc -X PATCH "$LUCIDA_API/v1/projects/$PROJECT_ID/event-definitions/signed_up" \
-d '{"description":"User finished sign-up","verified":true,"tags":["growth"]}' | jq '{name, verified, tags}'
curl -sS -X POST -H "Authorization: Bearer $LUCIDA_ACCOUNT_KEY" -H 'Content-Type: text/csv' \
--data-binary $'name,description,tags,verified\nupgraded,Upgrade to paid,growth;billing,true\n' \
"$LUCIDA_API/v1/projects/$PROJECT_ID/taxonomy/events/import" # {"updated":1}Tracking plans
A plan is the schema the worker validates events against (mode off, warn or enforce) and that lucida codegen reads. Planned events appear as verified definitions before they are first seen.
Method and path | Scope | Purpose |
|---|---|---|
|
|
|
|
| compile patterns without saving: |
| read / |
|
|
| draft copies with four-eyes review; merge conflicts answer |
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/tracking-plans" -d '{
"name":"core","mode":"warn",
"schema":{"events":[{"name":"purchase","description":"A paid order","props":[
{"name":"amount","type":"number","required":true},
{"name":"currency","type":"string","enum":["EUR","USD"]}]}],
"global_props":[{"name":"ssn","flag":"forbidden"}]}}' | jq '{id, mode, version}'Schema vocabulary: events[] {name, description?, props[], groups[]}, global_props[], property_groups[] {name, props[]}. A prop is {name, type?, required?, enum?, pattern?, flag?} with type string|number|bool|datetime|array|object and flag pii|sensitive|forbidden. forbidden props are dropped at ingest. The schema must be a JSON object under 1 MiB; a bad regex is 400.
Ingest-time rules (pick the right tool)
Tool | What it does | Scope |
|---|---|---|
Event filter | one condition tree that drops matching events before anything else |
|
Transformations | ordered rules: drop, rename, hash, set, sample, code |
|
JS rules |
|
|
Bot rules | label user agents and IPs as bots by category |
|
Traffic exclusions | hide matching traffic from reports at query time, retroactive and reversible |
|
Internal traffic | flag matching events as internal at ingest |
|
Tracking plan | validate and optionally drop forbidden props |
|
Event filter. PUT {p}/event-filter {mode*, root*, tests?}: mode is off, dry_run (counts what would drop) or live; root is a tree of {"type":"and"|"or","children":[...]}, {"type":"not","child":{}} and leaves {"type":"condition","field":"event"|"distinct_id","op":"equals"|"contains"|"starts_with"|"ends_with"|"regex","value":"..."} (max 20 conditions, depth 5); tests are saved cases {event, distinct_id?, expect_drop} (max 50) that must pass before live. GET returns 404 no event filter until one is set.
lc -X PUT "$LUCIDA_API/v1/projects/$PROJECT_ID/event-filter" -d '{"mode":"dry_run",
"root":{"type":"condition","field":"event","op":"starts_with","value":"test_"},
"tests":[{"event":"test_ping","expect_drop":true},{"event":"signed_up","expect_drop":false}]}' | jq '{mode, failing_tests, counts}'
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/event-filter/test" -d '{"events":[{"event":"test_x","distinct_id":"a"}]}' # {"drops":[true],...}Transformations. POST {p}/transformations {name*, rule*, events?, conditions?, filter?, enabled?, position?}. rule.kind is one of drop_event (optional per_event:[{event, conditions}]), drop_property {property}, rename_property {from, to}, hash_property {property}, set_property {property, value}, sample {percent 0..100, mode: "random"|"distinct_id"}, code {source, inputs?, secrets?} (a small statement language, not JavaScript). Scope: events (OR) and conditions [{property, op, value}] with op eq, neq, contains, not_contains, gt, gte, lt, lte, regex, is_set, is_not_set (AND). Property names may not start with $lc_. Rules run in position order. Other routes: GET, PATCH/DELETE {p}/transformations/{id} (clear_quarantine), GET {p}/transformations/metrics?hours=, POST {p}/transformations/test {event, rules[]} dry-run (no save), and reusable code libraries {p}/transformation-libraries (GET, POST {name*, source*, description}, GET/PATCH/DELETE .../{id}, GET .../{id}/versions). A rule that keeps failing is quarantined (quarantined_until, quarantine_reason).
# Dry-run first (nothing is saved), then create
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/transformations/test" -d '{
"event":{"event":"signup","distinct_id":"u1","properties":{"email":"a@b.co","plan":"pro"}},
"rules":[{"name":"hash email","rule":{"kind":"hash_property","property":"email"}},
{"name":"rename","rule":{"kind":"rename_property","from":"plan","to":"tier"}}]}' | jq '{properties, dropped, steps}'
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/transformations" -d '{
"name":"hash email","events":["signed_up"],"rule":{"kind":"hash_property","property":"email"},"enabled":true}' | jq '{id, position, scope}'An unknown rule.kind is 400 invalid rule: unknown variant ... listing the valid kinds. Changes apply to events ingested after the change; they do not rewrite stored events.
JS rules. POST {p}/js_rules {name*, source*, enabled?, position?}; PATCH/DELETE .../{id}; POST {p}/js_rules/test {event*, source?}; GET {p}/js_rules/metrics?hours=; the per-project key-value store: GET {p}/js_rules/kv?prefix=, GET .../kv/usage, PUT .../kv/quota {max_keys*, max_bytes*} (admin), DELETE .../kv?key=|prefix= (admin; no parameter deletes all). See Key-value store for ingest JS rules.
Bot rules. POST {p}/bot-rules {name*, category*, conditions*, combiner?, note?}: category is ai_crawler, ai_search, ai_assistant, search_crawler, seo_crawler, social_crawler, monitoring, http_client, headless_browser, no_user_agent, referrer_spam, other_bot; combiner and or or (default or); 1 to 10 conditions {property, op, value} with op contains, equals, regex, cidr and property one of user_agent, ip, lib, host, pathname, url, browser, os, language, screen_width, screen_height, country, referrer, referring_domain. Also GET {p}/bot-rules, PUT .../{id}, DELETE .../{id}, PUT .../order {ids*} (every id), POST .../reclassify {days} (apply to past events), and GET {p}/bot-traffic (report).
Traffic exclusions and internal traffic.
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/traffic-exclusions" -d '{"kind":"hostname","value":"staging.example.com","note":"staging"}' | jq '{id, kind, enabled}'
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/traffic-exclusions/preview" -d '{"days":7,"rules":[{"kind":"hostname","value":"staging.example.com"}]}' # {events, sessions, persons, days}
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/internal-traffic/rules" -d '{"kind":"ip_cidr","value":"203.0.113.0/24","note":"office"}'Exclusion kind: ip_cidr, hostname, path, distinct_id, event_property, person_property (key is required for the two property kinds). GET ?trash=true lists deleted rules; PATCH .../{id} {enabled}; DELETE moves to the trash; POST .../{id}/restore. At most 100 live rules. Internal-traffic kind: ip_cidr, email_domain, person_property; POST {p}/internal-traffic/cohort builds a cohort of internal users. Details: Traffic exclusions.
Path cleaning. PUT {p}/path-cleaning-rules {rules*:[{kind:"regex"|"wildcard", pattern, replacement}], apply_to_filters?} (up to 50): regex replaces every match (\1 is group 1), wildcard matches the whole path (* one segment, ** anything). POST .../ops {ops*, dry_run?} previews bulk edits. GET returns {max_rules, rules, apply_to_filters}.
Lookup tables. POST {p}/lookup_tables {name*, join_property*, csv*, key_column?}; queries read lookup:<name>.<column>. Name [a-z][a-z0-9_]{0,62}; CSV with a header row, at most 50 000 rows, 20 columns, 1.5 MB; the key column must be unique. PUT .../{id} replaces the CSV; DELETE .../{id}; GET lists {id, name, key_column, join_property, columns, row_count}.
Calculated properties. POST {p}/calculated_properties {name*, expr*, description?}; use as calc:<name> in filters and breakdowns. expr is a tree {"op": "prop"|"lit"|"concat"|"regex_extract"|"coalesce"|"arith"|"case"|"borrow", ...}, for example {"op":"concat","args":[{"op":"prop","key":"a"},{"op":"lit","value":"-"}]} (depth 8, 64 nodes). PATCH/DELETE .../{id}.
Materialized properties. POST {p}/materialized-properties {key*} promotes a hot event property to a column for fast filters (status goes backfilling, then ready); DELETE .../{id}; GET .../candidates; GET/PUT .../settings {auto_enabled*, max_columns*, threshold*}. See Materialized properties.
Sensitive keys (client-side encrypted properties). GET {p}/sensitive-keys (settings:read), POST {p}/sensitive-keys (admin, makes a new key pair the active one), DELETE .../{kid} destroys a private key: crypto-shredding, irreversible.
Snapshot properties. GET/POST {p}/snapshot-properties (action:read / action:write) {name*, selector*, source*, events*, attribute?, scope?, url?} capture a page value onto events; DELETE .../{name}.
Custom fields. Org-defined fields on flags, experiments and dashboards: GET {p}/custom-fields, GET {p}/custom-fields/{object_type} (?field=&value= to filter), GET/PUT {p}/custom-fields/{object_type}/{object_id} (the PUT body is a {field: value} object; the scope is the object type's own :write).
Data quality
GET {p}/data-quality?from=&to= is the overview (volume with anomaly baseline, late events, null rates, naming and dynamic-name findings); GET .../data-quality/pii-scan (admin) scans a sample for emails, card and phone numbers. Checks are scheduled assertions over any table or SQL view:
Method and path | Scope | Purpose |
|---|---|---|
|
|
|
|
|
|
|
| run now: |
|
| history, a SQL query for the failing rows, |
kind: not_null, unique, accepted_values (config.values, 1 to 200), relationship (config.to_table, to_column), row_count (config.min and/or max), freshness (column_name and config.max_age_hours), custom_sql (config.sql, a SELECT whose rows are the failures). severity: error or warning. schedule: manual, after_refresh, after_sync, 1h, 6h, 12h, daily, weekly (default daily). Tags: up to 20.
CHK=$(lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/data-quality/checks" -d '{
"name":"events have distinct_id","kind":"not_null","target_table":"events","column_name":"distinct_id",
"severity":"error","schedule":"daily"}' | jq -r .id)
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/data-quality/checks/$CHK/run" # {"status":"pass","observed":0.0,...}Ingestion health
GET {p}/ingestion/warnings (settings:read; filters kind, outcome, event, from, to, plus /summary) lists what the gateway and worker dropped or repaired (invalid_uuid, invalid_timestamp, future_timestamp, distinct_id_too_long, invalid_person_ops, ...). GET {p}/ingestion/dlq (source, include_dismissed) lists events that failed processing; POST .../dlq/replay and .../dlq/dismiss take {ids*} (settings:write).
Origin-drop alert. A public-key request from an origin outside capture_allowed_origins is acknowledged with 200 and dropped, so a moved site looks like a flat graph. The gateway writes one origin_not_allowed ingestion warning per project per minute, its detail starting with the number of events dropped since the last one. When a project drops 50 or more events in 10 minutes, a critical health issue origin_not_allowed opens within about a minute (Data > Project health, GET {p}/health-issues) and $lc_health_issue_firing is emitted with kind: origin_not_allowed, so an alert rule, workflow or project webhook on that event notifies you. It resolves by itself when the drops fall under the threshold ($lc_health_issue_resolved). Fix it with lucida origin move <old> <new>. Self-hosted: LC_ORIGIN_DROP_ALERT_MIN on lc-jobs changes the 50. Drops of the last minute before traffic stops are counted when the next drop arrives, not before.
Privacy and deletion
Method and path | Scope | Purpose |
|---|---|---|
|
| erasure request; |
|
|
|
|
| requests, |
|
| cancel while |
|
| per-destination status of deletes forwarded to connected tools; retry a failed one ( |
|
| DSAR export job; poll |
|
| your exports, oldest first, |
|
| delete the export row and its stored bundle; |
|
|
|
|
| find personal data in event properties |
|
| replay privacy scan; owned by the replay part |
| platform signature | cross-product privacy requests from the Lucida privacy platform; not for general agents |
# Erase one person and their events and recordings; do not forward to destinations
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/persons/bulk_delete" \
-d '{"ids":["'"$PID"'"],"events":true,"recordings":true,"forward":false}' | jq '{queued, batch_id}'
lc "$LUCIDA_API/v1/projects/$PROJECT_ID/deletion-requests?limit=5" | jq '.data[] | {id, status, options}'A batch where no distinct id is known (no person and no events), for example {"distinct_ids":["never-seen"]}, still answers 202. Nothing is queued:
{
"queued": 0,
"batch_id": "0192f4c4-7f0e-7c3a-9d21-5b1f0e8a4c11",
"requests": [],
"errors": [{"subject": "never-seen", "detail": "not found"}]
}batch_id is still a new id, but there are no requests to list under it. A repeated subject in one call is handled once. To confirm an erasure finished, call GET {p}/deletion-requests?batch_id=<batch_id> (or ?person_id=) with the same privacy:execute (or admin) key and wait until every request has status done; completed_at is set when every store was verified erased. The statuses are pending, running, done, failed and cancelled.
Erasure (DELETE {p}/persons/{id}, persons/bulk_delete) needs admin or privacy:execute, on a project secret key or on an account key. A server that only forwards deletions should hold a project secret key with ["capture","privacy:execute"] (it can then send events and erase, and read nothing), not admin (section 1). Erasure is irreversible once running. Dry-run it by reading GET {p}/persons/{id} and events first; cancel with DELETE .../deletion-requests/{id} while pending. keep_person:true keeps the record and its distinct ids and implies forward:false.