Skip to main content

Quick Reference

Quick lookup for common Unkey Analytics SQL patterns, available tables, aggregate functions, and filtering syntax for verification data.
2 min read

Analytics Quick Reference#

Essential Query Patterns#

Usage Analytics#

Use for: High-level usage metrics and health monitoring

User Analytics#

Use for: Understanding user behavior and identifying power users

Keyspace Analytics#

Use for: Comparing keyspace performance and usage

Billing Queries#

Use for: Usage-based billing and credit tracking

Tag-Based Filtering#

Use for: Custom metadata filtering and endpoint analysis

Filling Gaps in Time Series#

Use for: Charts and visualizations that need consistent time intervals

Tip

See Query Examples - WITH FILL for hourly, daily, and monthly examples with outcome breakdowns.

Table Selection Guide#

Choose the right table based on your time range:

Time RangeRecommended TableWhen to Use
< 1 hourkey_verifications_v1Real-time analysis, detailed debugging
< 24 hourskey_verifications_per_minute_v1Hourly/daily trends, recent activity
< 30 dayskey_verifications_per_hour_v1Daily/weekly analysis, user behavior
< 1 yearkey_verifications_per_day_v1Monthly/quarterly reports, billing cycles
> 1 yearkey_verifications_per_month_v1Annual trends, long-term analytics

Performance Tips:

  • Always filter by time first (uses indexes)
  • Use SUM(count) with aggregated tables, not COUNT(*)
  • Add LIMIT clauses to prevent large result sets
  • Filter before grouping when possible

Common Filters#

Note

Automatic filtering: All queries are automatically filtered based on your root key permissions:

  • Workspace: All queries are scoped to your workspace (no need to filter workspace_id)
  • API: If your root key is scoped to a specific API (api.<api_id>.read_analytics), queries are filtered to that API's key_space_id. With api.*.read_analytics permissions, filter by key_space_id yourself.

Time Ranges#

User & Keyspace Filters#

Tag Filters#

Outcome Filters#

Gateway filters#

Use source to select gateway traffic and app_id to select one app.

Need More Functions?#

ClickHouse Function Reference
ClickHouse SQL Documentation