Overview
The v2 analytics system represents a complete redesign of how you query your verification data, moving from predefined parameters to full SQL flexibility.Key Changes in v2:
- Flexibility: Predefined aggregations → Full SQL with custom queries
- Response Format: Direct array →
{meta, data}envelope
Migration Impact:
- Existing in v1: Predefined analytics with limited filtering options
- Enhanced in v2: Complete SQL flexibility, custom aggregations, and powerful filtering
Access and Authentication
V1: Automatic Access
V1 analytics was automatically available withapi.*.read_api permission:
v1 Analytics Access
V2: Opt-in Access Required
V2 analytics requires explicit opt-in and dedicated permissions:Comprehensive Analytics Documentation AvailableThis migration guide covers the technical differences between v1 and v2 analytics. For complete documentation on v2 analytics capabilities, including:
- Detailed schema reference with all tables and columns
- 30+ query examples for common use cases
- Performance optimization tips
- Query restrictions and error handling
v2 Example
Permission Changes
| V1 Permission | V2 Permission | Description |
|---|---|---|
api.*.read_api | api.*.read_analytics | Access analytics for all APIs |
api.api_123.read_api | api.api_123.read_analytics | Access analytics for specific API |
We automatically filter queries based on your permissions. If you have
api.api_123.read_analytics, your queries will only return data from that API. Wildcard api.*.read_analytics allows access to all APIs in your workspace and you can filter by apiId in your query.Request Format Changes
V1: Query Parameters
V1 used predefined query parameters with limited flexibility:v1 Request Structure
V2: SQL Queries
V2 uses full SQL queries for complete flexibility with automatic security filtering:v2 Request Structure
Automatic Security Filtering: V2 automatically applies security filters based on your root key permissions. You don’t need to manually filter by
workspace_id - the system handles this for you.Response Format Changes
V1 Response Format
V1 returned a direct array with predefined outcome fields:v1 Response Structure
V2 Response Format
V2 uses standard envelope format with your custom query results:v2 Response Structure
Dynamic Response Structure: The
data array contains objects with fields determined by your SQL SELECT clause. Unlike v1’s fixed structure, v2 returns exactly what you query for.Common Migration Patterns
Basic Usage Count
V1: Basic Query
V2: SQL Equivalent
Filter by User
V1: External ID Filter
V2: SQL Filter
Outcome Breakdown
V1: Automatic Outcome Fields
V2: Custom Outcome Aggregation
Top Users by Usage
V1: Group by Identity
V2: SQL with Ranking
Getting Help
- Analytics Documentation: https://unkey.com/docs/analytics
- Getting Started - Request access and run your first query
- Schema Reference - Complete table and column documentation
- Query Examples - 30+ ready-to-use SQL queries
- Quick Reference - Common patterns and functions
- Query Restrictions - Limits and error codes
- Troubleshooting - Common issues and solutions
- Migration Support: https://unkey.com/docs/api-reference/v1/migration
- Discord: https://unkey.com/discord
- Email Support: support@unkey.dev
- Book a Call: https://cal.com/team/unkey/founders - Schedule time with our team for migration help