API reference

SQL tables

These are the tables and columns you can read with 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.

ColumnTypeNotes
client_idString
timestampDateTime64(3, 'UTC')
bot_typeLowCardinality(String)ai_crawler | ai_assistant, or the detector category for other bots
bot_nameStringDetector bot name; rows written before the October 2026 detector fix can hold browser engines such as 'WebKit', so use agent_id instead
pathStringRequested path, or full URL on tracker rows
referrerNullable(String)Referrer sent with the request; tracker rows written before the October 2026 tracker fix can hold the page's own URL
agent_idLowCardinality(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_purposeLowCardinality(String)training | search_index | user_fetch (fetched live to answer a user) | agent (acting for a user)
verificationLowCardinality(String)'host_unchecked' when stored during a website lookup outage, otherwise ''
sourceLowCardinality(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
formatLowCardinality(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
hostLowCardinality(String)Host the request was made to; '' on tracker rows
acceptStringRequest Accept header; '' when absent, on tracker rows and on vercel rows
status_codeUInt16HTTP 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.

ColumnTypeNotes
client_idString
timestampDateTime64(3, 'UTC')
pathNullable(String)
block_reasonLowCardinality(String)Why the request was rejected
bot_nameNullable(String)Detected bot, if any
request_pathLowCardinality(String)Ingestion endpoint the request was sent to
issueStringFirst 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.

ColumnTypeNotes
owner_idLowCardinality(String)Organization id
website_idLowCardinality(Nullable(String))Website id; NULL for events sent without one
timestampDateTime64(3, 'UTC')
event_nameLowCardinality(String)
anonymous_idNullable(String)
session_idNullable(String)
profile_idStringIdentified user id from identify(), '' when anonymous
property_keysArray(String)Top-level event property names.
flag_keyNullable(String)Flag key on exposure rows.
flag_variantNullable(String)Variant served on a multivariant flag exposure.
flag_valueNullable(String)Evaluated value as JSON, including true or false for a boolean flag.
groupsMap(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.

ColumnTypeNotes
client_idString
anonymous_idString
session_idString
timestampDateTime64(3, 'UTC')When the page view ended
pathString
device_typeLowCardinality(String)mobile/desktop/tablet
browser_nameLowCardinality(String)
countryLowCardinality(String)ISO country code
page_indexUInt16Position of the page view in the session
exit_typeLowCardinality(String)spa (route change) or unload (tab closed or navigated away)
time_on_pageUInt32Seconds on page
active_timeUInt32Seconds the tab was visible and focused; use as the denominator for engagement rates
time_to_first_interactionUInt32Milliseconds until the first click, key, or scroll; 0 when none
max_scroll_depthUInt80-100
scroll_countUInt16
click_countUInt16
key_countUInt16
interaction_countUInt16All pointer, key, and scroll events
copy_countUInt16Copy events on the page view
rage_click_countUInt16Bursts 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_countUInt16Clicks 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_targetLowCardinality(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_targetLowCardinality(String)Descriptor of the last dead-clicked control, same format
form_field_countUInt16Distinct form fields focused on the page view
form_submit_countUInt16Form submits on the page view
last_form_fieldLowCardinality(String)Descriptor of the last focused field, e.g. input:email:work email
form_abandonedUInt81 when fields were touched and nothing was submitted
error_countUInt16Captured 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.

ColumnTypeNotes
client_idString
anonymous_idString
session_idString
timestampDateTime64(3, 'UTC')
pathStringPage where error occurred
messageStringFull error message text (filter on this to search by content; field name is 'message', NOT 'error_message')
filenameNullable(String)
linenoNullable(Int32)
colnoNullable(Int32)
stackNullable(String)Stack trace (truncated to 1500 chars in recent_errors output)
error_typeLowCardinality(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.

ColumnTypeNotes
client_idStringWebsite/project identifier
event_nameLowCardinality(String)Event type
anonymous_idStringAnonymous device identifier
timeDateTime64(3, 'UTC')Event timestamp
session_idStringSession identifier
referrerNullable(String)
pathStringURL path
browser_nameLowCardinality(Nullable(String))
os_nameLowCardinality(Nullable(String))
device_typeLowCardinality(Nullable(String))mobile/desktop/tablet
time_on_pageNullable(Float32)Seconds spent on page
countryLowCardinality(Nullable(String))Country name such as 'United States', or its ISO code when the edge supplied it; match both spellings
regionLowCardinality(Nullable(String))State/province
cityNullable(String)
utm_sourceNullable(String)
utm_mediumNullable(String)
utm_campaignNullable(String)
utm_termNullable(String)
utm_contentNullable(String)
scroll_depthNullable(Float32)Max scroll percentage (0-100)
profile_idStringIdentified user id from identify(), '' when anonymous
property_keysArray(String)Top-level event property names.
groupsMap(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'.

ColumnTypeNotes
client_idStringWebsite id
group_typeLowCardinality(String)Kind of group passed to group(), such as company or workspace
group_keyStringGroup id within its type; events carry it as groups[group_type]
keyLowCardinality(String)Trait name; concat(char(0), 'group') is the marker row every group has
valueStringTrait value as text: numbers such as '42', booleans 'true' or 'false'; compare numbers with toFloat64OrNull(value)
updated_atDateTime64(3, 'UTC')When this value was stored
is_deletedUInt81 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.

ColumnTypeNotes
client_idStringWebsite id
anonymous_idStringAnonymous device id, as in analytics.events
identity_timeSimpleAggregateFunction(min, DateTime64(3, 'UTC'))First identified event of the device as this profile; aggregate with min()
last_seenSimpleAggregateFunction(max, DateTime64(3, 'UTC'))Last identified event of the device as this profile; aggregate with max()
profile_idStringIdentified 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.

ColumnTypeNotes
client_idStringWebsite id
session_idStringSession id, as in analytics.events
identity_timeSimpleAggregateFunction(min, DateTime64(3, 'UTC'))First identified event of the session as this profile; aggregate with min()
last_seenSimpleAggregateFunction(max, DateTime64(3, 'UTC'))Last identified event of the session as this profile; aggregate with max()
profile_idStringIdentified 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).

ColumnTypeNotes
owner_idStringOrganization that owns the MCP server.
website_idStringWebsite the server recorded for the call.
timestampDateTime64(3, 'UTC')When the call occurred.
environmentLowCardinality(String)
server_nameLowCardinality(String)
server_versionLowCardinality(String)
toolStringTool called by the MCP client.
is_errorBool
errorStringFailure message shown in the MCP call details.
error_codeLowCardinality(String)
duration_msUInt32Call duration in milliseconds.
output_charsUInt32Number of characters returned.
session_idString
profile_idStringUser identified by the MCP server, or empty.
clientLowCardinality(String)Recorded client label.
client_nameLowCardinality(String)Name reported by the MCP client.
client_versionLowCardinality(String)
groupsMap(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

External links clicked by users

ColumnTypeNotes
client_idString
anonymous_idString
session_idString
hrefStringDestination URL
textNullable(String)
timestampDateTime64(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.

ColumnTypeNotes
client_idStringWebsite id
profile_idStringIdentified user id from identify(), as in profile_id of analytics.events, custom_events and revenue
keyLowCardinality(String)Trait name; concat(char(0), 'profile') is the marker row every identified profile has
valueStringTrait value as text: numbers such as '42', booleans 'true' or 'false'; compare numbers with toFloat64OrNull(value)
updated_atDateTime64(3, 'UTC')When this value was stored
is_deletedUInt81 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.

ColumnTypeNotes
owner_idStringOrganization id, or the website id on legacy rows
website_idNullable(String)Website stored at ingestion
transaction_idString
providerLowCardinality(String)
typeLowCardinality(String)'sale', 'subscription', 'refund', or 'subscription_event' (no money)
statusLowCardinality(String)'completed', 'failed', 'canceled', 'refunded', or 'linked'
amountDecimal(18, 4)Transaction amount; cast to Float64 for percentiles
currencyLowCardinality(String)
anonymous_idNullable(String)
customer_idString
createdDateTime('UTC')Transaction timestamp
profile_idStringIdentified 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
ColumnTypeNotes
client_idString
anonymous_idString
session_idString
timestampDateTime64(3, 'UTC')
pathString
metric_nameLowCardinality(String)One of: FCP, LCP, CLS, INP, TTFB, FPS
metric_valueFloat64Metric 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.

ColumnTypeNotes
site_idStringWebsite id of the monitor
urlStringURL the monitor checks, set by the site owner; tells a website's monitors apart
timestampDateTime64(3, 'UTC')When the check ran
statusUInt81 up, 0 down
http_codeUInt16HTTP status returned; 0 when no response arrived (timeout, DNS or connection failure)
ttfb_msUInt32Milliseconds to the first response byte
total_msUInt32Milliseconds for the whole response
failure_streakUInt16Consecutive down checks up to and including this one; 0 when up
response_bytesUInt32Response size; 0 when down
redirect_countUInt8Redirects followed; 0 when down
probe_regionLowCardinality(String)Region the check ran from
ssl_expiryNullable(DateTime64(3, 'UTC'))TLS certificate expiry; NULL when it could not be read
ssl_validUInt81 when the TLS certificate was valid
errorStringWhy the check failed; '' when up

How is this guide?