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.
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.
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.
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.
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.
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.
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'.
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.
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.
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).
analytics.outgoing_links
External links clicked by users
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.
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.
analytics.web_vitals_spans
Core Web Vitals measurements (FCP, LCP, CLS, INP, TTFB, FPS)
Rating thresholds (computed at query time):
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.
How is this guide?