# SQL tables

> Every table and column you can read with SQL, and how to count from each one


These are the tables and columns you can read with [SQL](/docs/api/sql), whether you query from the API or the MCP server. Each query sees only the websites you choose.

Read a table's notes before you count from it. They say which rows are page views, which column dates a row, how to count visitors, and when a row can be counted twice. To get this list from code, call `GET https://api.databuddy.cc/sql/schema`.

## analytics.ai_traffic_spans

One row per request from an AI crawler or agent (GPTBot, ClaudeBot, ChatGPT-User, Claude Code...), recorded server-side by @databuddy/sdk/agents (source = 'middleware') or a Vercel log drain (source = 'vercel'), or by the browser tracker (source = 'tracker'). These are bot reads, never visitors or pageviews. Prefer get_data ai_\* builders (ai_crawlers, ai_agent_pages, ai_content_formats, ai_products): they name agents and products and skip duplicate rows.

Count AI requests with agent_id != ''; '' marks forwarded hits from bots that are not AI agents (search, SEO, monitoring). Server-side sources repeat requests the tracker also saw: when a site has both middleware and vercel rows, the source whose first row is newer counts from then on and the other only before it, and tracker rows count only before the first middleware or vercel row. Name agents by agent_id, not bot_name.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` |  |
| `timestamp` | `DateTime64(3, 'UTC')` |  |
| `bot_type` | `LowCardinality(String)` | ai_crawler \| ai_assistant, or the detector category for other bots |
| `bot_name` | `String` | Detector bot name; rows written before the October 2026 detector fix can hold browser engines such as 'WebKit', so use agent_id instead |
| `path` | `String` | Requested path, or full URL on tracker rows |
| `referrer` | `Nullable(String)` | Referrer sent with the request; tracker rows written before the October 2026 tracker fix can hold the page's own URL |
| `agent_id` | `LowCardinality(String)` | Registry id such as 'openai-crawler' (GPTBot), 'anthropic-crawler' (ClaudeBot) or 'claude-code'; 'unidentified:\<token\>' for unknown clients that asked for markdown first; '' when no AI agent was identified |
| `agent_purpose` | `LowCardinality(String)` | training \| search_index \| user_fetch (fetched live to answer a user) \| agent (acting for a user) |
| `verification` | `LowCardinality(String)` | 'host_unchecked' when stored during a website lookup outage, otherwise '' |
| `source` | `LowCardinality(String)` | middleware \| vercel \| tracker; tracker rows written before the October 2026 tracker fix also include rows from beacons and non-page-view events, not only page views |
| `format` | `LowCardinality(String)` | markdown \| llms (llms.txt, llms-full.txt) \| html, as the agent asked for it; '' on tracker rows before 2026-09-27, which are html |
| `host` | `LowCardinality(String)` | Host the request was made to; '' on tracker rows |
| `accept` | `String` | Request Accept header; '' when absent, on tracker rows and on vercel rows |
| `status_code` | `UInt16` | HTTP status returned to the agent (vercel rows only); 0 when unknown |

## analytics.blocked_traffic

Requests rejected by the ingestion edge (bots, abuse, rate-limit). Useful for sizing junk traffic; never count as real visitors. AI crawlers and agents are not here; they are in analytics.ai_traffic_spans.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` |  |
| `timestamp` | `DateTime64(3, 'UTC')` |  |
| `path` | `Nullable(String)` |  |
| `block_reason` | `LowCardinality(String)` | Why the request was rejected |
| `bot_name` | `Nullable(String)` | Detected bot, if any |
| `request_path` | `LowCardinality(String)` | Ingestion endpoint the request was sent to |
| `issue` | `String` | First failing field and its problem, for invalid_schema |

## analytics.custom_events

Custom events from SDK track() and the /track API.

Feature flag exposures have event_name = '$flag_evaluated'. Partitioned by month, ordered by (owner_id, event_name, timestamp). Count people with uniq(coalesce(nullIf(profile_id, ''), nullIf(anonymous_id, ''))): profile_id is '' when anonymous, so a bare coalesce collapses anonymous rows.

| Column | Type | Notes |
| --- | --- | --- |
| `owner_id` | `LowCardinality(String)` | Organization id |
| `website_id` | `LowCardinality(Nullable(String))` | Website id; NULL for events sent without one |
| `timestamp` | `DateTime64(3, 'UTC')` |  |
| `event_name` | `LowCardinality(String)` |  |
| `anonymous_id` | `Nullable(String)` |  |
| `session_id` | `Nullable(String)` |  |
| `profile_id` | `String` | Identified user id from identify(), '' when anonymous |
| `property_keys` | `Array(String)` | Top-level event property names. |
| `flag_key` | `Nullable(String)` | Flag key on exposure rows. |
| `flag_variant` | `Nullable(String)` | Variant served on a multivariant flag exposure. |
| `flag_value` | `Nullable(String)` | Evaluated value as JSON, including true or false for a boolean flag. |
| `groups` | `Map(String, String)` | Groups from group() on the event, by type: groups['company'] is its company key, matching group_key in analytics.group_traits; \{\} when none |

## analytics.engagement_spans

One row per page view, written when the visitor leaves the page: attention, interaction, frustration, and form activity

Rates should divide by page views (COUNT(\*)) or by active_time, never by session count. Targets are UI locations, not identifiers; group by them to find the control behind a frustration spike. Has a bloom filter index on session_id; no profile_id, resolve identified users via analytics.events anonymous_ids.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` |  |
| `anonymous_id` | `String` |  |
| `session_id` | `String` |  |
| `timestamp` | `DateTime64(3, 'UTC')` | When the page view ended |
| `path` | `String` |  |
| `device_type` | `LowCardinality(String)` | mobile/desktop/tablet |
| `browser_name` | `LowCardinality(String)` |  |
| `country` | `LowCardinality(String)` | ISO country code |
| `page_index` | `UInt16` | Position of the page view in the session |
| `exit_type` | `LowCardinality(String)` | spa (route change) or unload (tab closed or navigated away) |
| `time_on_page` | `UInt32` | Seconds on page |
| `active_time` | `UInt32` | Seconds the tab was visible and focused; use as the denominator for engagement rates |
| `time_to_first_interaction` | `UInt32` | Milliseconds until the first click, key, or scroll; 0 when none |
| `max_scroll_depth` | `UInt8` | 0-100 |
| `scroll_count` | `UInt16` |  |
| `click_count` | `UInt16` |  |
| `key_count` | `UInt16` |  |
| `interaction_count` | `UInt16` | All pointer, key, and scroll events |
| `copy_count` | `UInt16` | Copy events on the page view |
| `rage_click_count` | `UInt16` | Bursts of three or more clicks on one element, each within a second of the last, that got no DOM change, navigation, or other response after the first click, counted once per burst; form fields, text selection, canvas, video, and the page background are excluded. Trackers before 2026-10-04 also counted fast clicks on working controls and form fields, and sites with pinned snippets or cached scripts run an older tracker for a while, so a date alone does not mark the cutover |
| `dead_click_count` | `UInt16` | Clicks on buttons, links, and other non-form controls that got no DOM change, navigation, or other response within 2.5 seconds. Trackers before 2026-10-02 also counted form fields and iOS link taps, inflating their rates. A site whose dead_click_target or rage_click_target values start with input, select, textarea, or label is still running an older tracker |
| `rage_click_target` | `LowCardinality(String)` | Descriptor of the last rage-clicked element, at most 64 characters: tag[:role]:label. The label is the data-track, aria-label, data-testid, name, or id, or for links the first path segment (a:/pricing, a:/blog/\*) or the external site's domain (a:stripe.com). Unnamed elements end with their nearest landmark or developer-named container (button:unnamed in dialog:checkout) |
| `dead_click_target` | `LowCardinality(String)` | Descriptor of the last dead-clicked control, same format |
| `form_field_count` | `UInt16` | Distinct form fields focused on the page view |
| `form_submit_count` | `UInt16` | Form submits on the page view |
| `last_form_field` | `LowCardinality(String)` | Descriptor of the last focused field, e.g. input:email:work email |
| `form_abandoned` | `UInt8` | 1 when fields were touched and nothing was submitted |
| `error_count` | `UInt16` | Captured JavaScript errors during the page view |

## analytics.error_spans

JavaScript errors and exceptions

Error queries filter on path, message and error_type, and recent_errors also on country, region, device_type, browser_name and os_name.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` |  |
| `anonymous_id` | `String` |  |
| `session_id` | `String` |  |
| `timestamp` | `DateTime64(3, 'UTC')` |  |
| `path` | `String` | Page where error occurred |
| `message` | `String` | Full error message text (filter on this to search by content; field name is 'message', NOT 'error_message') |
| `filename` | `Nullable(String)` |  |
| `lineno` | `Nullable(Int32)` |  |
| `colno` | `Nullable(Int32)` |  |
| `stack` | `Nullable(String)` | Stack trace (truncated to 1500 chars in recent_errors output) |
| `error_type` | `LowCardinality(String)` | JS error class name (Error, TypeError, ReferenceError, SyntaxError, etc.); not the message. Filter by 'message' to match error text. |

## analytics.events

Main events table with page views and user sessions

Page views have event_name = 'screen_view'. Partitioned by month (toYYYYMM(time)), ordered by (client_id, time, id). Count visitors with uniq(anonymous_id), one per device. To count people, group by profile_id when present and anonymous_id otherwise.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` | Website/project identifier |
| `event_name` | `LowCardinality(String)` | Event type |
| `anonymous_id` | `String` | Anonymous device identifier |
| `time` | `DateTime64(3, 'UTC')` | Event timestamp |
| `session_id` | `String` | Session identifier |
| `referrer` | `Nullable(String)` |  |
| `path` | `String` | URL path |
| `browser_name` | `LowCardinality(Nullable(String))` |  |
| `os_name` | `LowCardinality(Nullable(String))` |  |
| `device_type` | `LowCardinality(Nullable(String))` | mobile/desktop/tablet |
| `time_on_page` | `Nullable(Float32)` | Seconds spent on page |
| `country` | `LowCardinality(Nullable(String))` | Country name such as 'United States', or its ISO code when the edge supplied it; match both spellings |
| `region` | `LowCardinality(Nullable(String))` | State/province |
| `city` | `Nullable(String)` |  |
| `utm_source` | `Nullable(String)` |  |
| `utm_medium` | `Nullable(String)` |  |
| `utm_campaign` | `Nullable(String)` |  |
| `utm_term` | `Nullable(String)` |  |
| `utm_content` | `Nullable(String)` |  |
| `scroll_depth` | `Nullable(Float32)` | Max scroll percentage (0-100) |
| `profile_id` | `String` | Identified user id from identify(), '' when anonymous |
| `property_keys` | `Array(String)` | Top-level event property names. |
| `groups` | `Map(String, String)` | Groups from group() on the event, by type: groups['company'] is its company key, matching group_key in analytics.group_traits; \{\} when none |

## analytics.group_traits

Current traits of groups (companies, workspaces, teams) from group() and connected billing providers: one row per group and trait key.

Read it with FINAL (FROM analytics.group_traits FINAL): every change adds a version, and FINAL keeps only the newest per group and key and drops removed traits; without FINAL a changed trait counts once per version and removed traits still appear. Count groups with uniqExactIf(group_key, key = concat(char(0), 'group')) per group_type, which includes groups without traits, and leave that marker out of trait breakdowns with NOT startsWith(key, char(0)). A group's members are the people whose events carry it: analytics.events and custom_events WHERE groups['company'] = group_key for group_type 'company'.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` | Website id |
| `group_type` | `LowCardinality(String)` | Kind of group passed to group(), such as company or workspace |
| `group_key` | `String` | Group id within its type; events carry it as groups[group_type] |
| `key` | `LowCardinality(String)` | Trait name; concat(char(0), 'group') is the marker row every group has |
| `value` | `String` | Trait value as text: numbers such as '42', booleans 'true' or 'false'; compare numbers with toFloat64OrNull(value) |
| `updated_at` | `DateTime64(3, 'UTC')` | When this value was stored |
| `is_deleted` | `UInt8` | 1 on the version that removed the trait |

## analytics.identity_anon_pairs

Which identified users each anonymous device belongs to: one pair per anonymous_id and profile_id seen together on an identified event in analytics.events or custom_events.

A pair can have several rows until background merges fold them, so aggregate: SELECT anonymous_id, profile_id, min(identity_time) AS first_identified, max(last_seen) AS last_seen FROM analytics.identity_anon_pairs GROUP BY anonymous_id, profile_id. Use it to credit a device's events from before identify(), whose profile_id is '', to its user. A shared device can belong to several users: check uniqExact(profile_id) per anonymous_id before crediting its anonymous events to one of them.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` | Website id |
| `anonymous_id` | `String` | Anonymous device id, as in analytics.events |
| `identity_time` | `SimpleAggregateFunction(min, DateTime64(3, 'UTC'))` | First identified event of the device as this profile; aggregate with min() |
| `last_seen` | `SimpleAggregateFunction(max, DateTime64(3, 'UTC'))` | Last identified event of the device as this profile; aggregate with max() |
| `profile_id` | `String` | Identified user id the device was seen as |

## analytics.identity_session_pairs

Which identified users each session belongs to: one pair per session_id and profile_id seen together on an identified event in analytics.events or custom_events.

A pair can have several rows until background merges fold them, so aggregate: SELECT session_id, profile_id, min(identity_time) AS first_identified FROM analytics.identity_session_pairs GROUP BY session_id, profile_id. Join analytics.events on session_id to give the events of each session their user. A session that signed in as two users has two pairs, so count users per session before summing per user.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` | Website id |
| `session_id` | `String` | Session id, as in analytics.events |
| `identity_time` | `SimpleAggregateFunction(min, DateTime64(3, 'UTC'))` | First identified event of the session as this profile; aggregate with min() |
| `last_seen` | `SimpleAggregateFunction(max, DateTime64(3, 'UTC'))` | Last identified event of the session as this profile; aggregate with max() |
| `profile_id` | `String` | Identified user id the session was seen as |

## analytics.mcp_spans

Tool calls recorded by MCP servers linked to the selected website.

Calls recorded without a website are omitted. Count failed calls with countIf(is_error).

| Column | Type | Notes |
| --- | --- | --- |
| `owner_id` | `String` | Organization that owns the MCP server. |
| `website_id` | `String` | Website the server recorded for the call. |
| `timestamp` | `DateTime64(3, 'UTC')` | When the call occurred. |
| `environment` | `LowCardinality(String)` |  |
| `server_name` | `LowCardinality(String)` |  |
| `server_version` | `LowCardinality(String)` |  |
| `tool` | `String` | Tool called by the MCP client. |
| `is_error` | `Bool` |  |
| `error` | `String` | Failure message shown in the MCP call details. |
| `error_code` | `LowCardinality(String)` |  |
| `duration_ms` | `UInt32` | Call duration in milliseconds. |
| `output_chars` | `UInt32` | Number of characters returned. |
| `session_id` | `String` |  |
| `profile_id` | `String` | User identified by the MCP server, or empty. |
| `client` | `LowCardinality(String)` | Recorded client label. |
| `client_name` | `LowCardinality(String)` | Name reported by the MCP client. |
| `client_version` | `LowCardinality(String)` |  |
| `groups` | `Map(String, String)` | Groups the MCP server attached to the call, by type: groups['company'] is its company key, matching group_key in analytics.group_traits; \{\} when none |

## analytics.outgoing_links

External links clicked by users

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` |  |
| `anonymous_id` | `String` |  |
| `session_id` | `String` |  |
| `href` | `String` | Destination URL |
| `text` | `Nullable(String)` |  |
| `timestamp` | `DateTime64(3, 'UTC')` |  |

## analytics.profile_traits

Current traits of identified users from identify(): one row per profile and trait key.

Read it with FINAL (FROM analytics.profile_traits FINAL): every change adds a version, and FINAL keeps only the newest per profile and key and drops removed traits; without FINAL a changed trait counts once per version and removed traits still appear. Ordered by (client_id, key, profile_id), so filter on key: SELECT profile_id, value AS plan FROM analytics.profile_traits FINAL WHERE key = 'plan'. Count identified users with uniqExactIf(profile_id, key = concat(char(0), 'profile')), which includes profiles without traits, and leave that marker out of trait breakdowns with NOT startsWith(key, char(0)). Names, usernames and emails are not stored here. Join analytics.events on profile_id; for a visitor's events from before identify(), map anonymous_id through analytics.identity_anon_pairs.

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` | Website id |
| `profile_id` | `String` | Identified user id from identify(), as in profile_id of analytics.events, custom_events and revenue |
| `key` | `LowCardinality(String)` | Trait name; concat(char(0), 'profile') is the marker row every identified profile has |
| `value` | `String` | Trait value as text: numbers such as '42', booleans 'true' or 'false'; compare numbers with toFloat64OrNull(value) |
| `updated_at` | `DateTime64(3, 'UTC')` | When this value was stored |
| `is_deleted` | `UInt8` | 1 on the version that removed the trait |

## analytics.revenue

Revenue transactions from payment providers.

Use FINAL when inspecting payment and adjustment webhook records to read only the latest version of each (owner_id, transaction_id). Stripe can record the same invoice payment under both a PaymentIntent and an InvoicePayment. Use the get_data revenue_\* reports for payment counts and totals. The stored website can be a fallback. The reports resolve the credited website from related payment records.

| Column | Type | Notes |
| --- | --- | --- |
| `owner_id` | `String` | Organization id, or the website id on legacy rows |
| `website_id` | `Nullable(String)` | Website stored at ingestion |
| `transaction_id` | `String` |  |
| `provider` | `LowCardinality(String)` |  |
| `type` | `LowCardinality(String)` | 'sale', 'subscription', 'refund', or 'subscription_event' (no money) |
| `status` | `LowCardinality(String)` | 'completed', 'failed', 'canceled', 'refunded', or 'linked' |
| `amount` | `Decimal(18, 4)` | Transaction amount; cast to Float64 for percentiles |
| `currency` | `LowCardinality(String)` |  |
| `anonymous_id` | `Nullable(String)` |  |
| `customer_id` | `String` |  |
| `created` | `DateTime('UTC')` | Transaction timestamp |
| `profile_id` | `String` | Identified user id from identify(), '' when anonymous |

## analytics.web_vitals_spans

Core Web Vitals measurements (FCP, LCP, CLS, INP, TTFB, FPS)

Rating thresholds (computed at query time):
- LCP: good \< 2500ms, poor \> 4000ms
- FCP: good \< 1800ms, poor \> 3000ms
- CLS: good \< 0.1, poor \> 0.25
- INP: good \< 200ms, poor \> 500ms
- TTFB: good \< 800ms, poor \> 1800ms
- FPS: good \> 55, poor \< 30

| Column | Type | Notes |
| --- | --- | --- |
| `client_id` | `String` |  |
| `anonymous_id` | `String` |  |
| `session_id` | `String` |  |
| `timestamp` | `DateTime64(3, 'UTC')` |  |
| `path` | `String` |  |
| `metric_name` | `LowCardinality(String)` | One of: FCP, LCP, CLS, INP, TTFB, FPS |
| `metric_value` | `Float64` | Metric value |

## uptime.uptime_monitor

Uptime checks of the website's monitors: one row per check with status, response timings and TLS certificate state.

A website can have several monitors; they share site_id, so group or filter by url. The share of checks up is countIf(status = 1) / count(); downtime lasts from a down check to the next check that is up, which the get_data uptime_\* query types compute. Find outages with failure_streak, and certificates close to expiry with max(ssl_expiry). Monitors not linked to a website are not here.

| Column | Type | Notes |
| --- | --- | --- |
| `site_id` | `String` | Website id of the monitor |
| `url` | `String` | URL the monitor checks, set by the site owner; tells a website's monitors apart |
| `timestamp` | `DateTime64(3, 'UTC')` | When the check ran |
| `status` | `UInt8` | 1 up, 0 down |
| `http_code` | `UInt16` | HTTP status returned; 0 when no response arrived (timeout, DNS or connection failure) |
| `ttfb_ms` | `UInt32` | Milliseconds to the first response byte |
| `total_ms` | `UInt32` | Milliseconds for the whole response |
| `failure_streak` | `UInt16` | Consecutive down checks up to and including this one; 0 when up |
| `response_bytes` | `UInt32` | Response size; 0 when down |
| `redirect_count` | `UInt8` | Redirects followed; 0 when down |
| `probe_region` | `LowCardinality(String)` | Region the check ran from |
| `ssl_expiry` | `Nullable(DateTime64(3, 'UTC'))` | TLS certificate expiry; NULL when it could not be read |
| `ssl_valid` | `UInt8` | 1 when the TLS certificate was valid |
| `error` | `String` | Why the check failed; '' when up |
