Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 27 additions & 40 deletions apps/docs/analytics/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,58 @@ Once you have access, execute your first analytics query using the `/v2/analytic

### Count Total Verifications

```sql
SELECT COUNT(*) as total
FROM key_verifications_v1
Count the total number of key verifications in the last 7 days across all your APIs to get a high-level view of your overall usage volume.

<CodeGroup>
```sql SQL
SELECT SUM(count) as total
FROM key_verifications_per_day_v1
WHERE time >= now() - INTERVAL 7 DAY
```

Execute this query with curl:

```bash
```bash cURL
curl -X POST https://api.unkey.com/v2/analytics.getVerifications \
-H "Authorization: Bearer <YOUR_ROOT_KEY>" \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT COUNT(*) as total FROM key_verifications_v1 WHERE time >= now() - INTERVAL 7 DAY"
"query": "SELECT SUM(count) as total FROM key_verifications_per_day_v1 WHERE time >= now() - INTERVAL 7 DAY"
}'
```

</CodeGroup>

### Break Down by Outcome

```sql
Group verifications by their outcome (`VALID`, `RATE_LIMITED`, `USAGE_EXCEEDED`, etc.) over the last 24 hours to understand the distribution of successful vs. failed requests.

<CodeGroup>
```sql SQL
SELECT
outcome,
COUNT(*) as count
FROM key_verifications_v1
SUM(count) as count
FROM key_verifications_per_hour_v1
WHERE time >= now() - INTERVAL 24 HOUR
GROUP BY outcome
ORDER BY count DESC
```

Execute this query with curl:

```bash
```bash cURL
curl -X POST https://api.unkey.com/v2/analytics.getVerifications \
-H "Authorization: Bearer <YOUR_ROOT_KEY>" \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT outcome, COUNT(*) as count FROM key_verifications_v1 WHERE time >= now() - INTERVAL 24 HOUR GROUP BY outcome ORDER BY count DESC"
"query": "SELECT outcome, SUM(count) as count FROM key_verifications_per_hour_v1 WHERE time >= now() - INTERVAL 24 HOUR GROUP BY outcome ORDER BY count DESC"
}'
```

</CodeGroup>

### Top Users by Usage

```sql
Identify your most active users by counting their total verifications over the last 30 days to spot power users or potential abuse patterns.

<CodeGroup>
```sql SQL
SELECT
external_id,
SUM(count) as verifications
Expand All @@ -92,9 +101,7 @@ ORDER BY verifications DESC
LIMIT 10
```

Execute this query with curl:

```bash
```bash cURL
curl -X POST https://api.unkey.com/v2/analytics.getVerifications \
-H "Authorization: Bearer <YOUR_ROOT_KEY>" \
-H "Content-Type: application/json" \
Expand All @@ -103,6 +110,8 @@ curl -X POST https://api.unkey.com/v2/analytics.getVerifications \
}'
```

</CodeGroup>

<Tip>
**Performance tip:** For longer time ranges, use pre-aggregated tables instead of the raw table:
- `key_verifications_per_minute_v1` - For queries spanning hours
Expand Down Expand Up @@ -147,25 +156,3 @@ You can filter queries to specific APIs or users. Use `key_space_id` to filter b
and quota). See [Query Restrictions](/analytics/query-restrictions) for
complete details on limits and error codes.
</Note>

## Next Steps

<CardGroup cols={2}>
<Card title="Query Examples" icon="code" href="/analytics/query-examples">
Explore common SQL patterns for analytics and billing
</Card>
<Card
title="Schema Reference"
icon="table"
href="/analytics/schema-reference"
>
Browse available tables, columns, and data types
</Card>
<Card
title="Query Restrictions"
icon="shield-check"
href="/analytics/query-restrictions"
>
View limits, quotas, and permissions
</Card>
</CardGroup>
35 changes: 21 additions & 14 deletions apps/docs/analytics/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ description: "Query your verification data with SQL"
<Warning>
**Analytics is currently in private beta and available by request only.**

See [Getting Started](/analytics/getting-started) for access instructions.
See [Getting Started](/analytics/getting-started) for access instructions.

</Warning>

## What is Unkey Analytics?
Expand All @@ -32,6 +33,7 @@ graph LR
```

You can query these tables using standard SQL to:

- Aggregate verification counts by time period
- Group by API, user, or outcome
- Filter by region, tags, or custom criteria
Expand All @@ -54,23 +56,28 @@ Every verification event contains:
| `tags` | Array(String) | Custom tags added during verification |
| `spent_credits` | Int64 | Number of credits spent on this verification (0 if no credits were spent) |

## Next Steps
## Use Cases

<CardGroup cols={2}>
<Card title="Getting Started" icon="rocket" href="/analytics/getting-started">
Learn how to request access and execute your first query
</Card>
<Card title="Query Examples" icon="code" href="/analytics/query-examples">
Explore common SQL patterns for analytics and billing
<CardGroup cols={3}>
<Card
title="Billing Teams"
icon="credit-card"
href="/analytics/query-examples#billing-usage-based-pricing"
>
Usage-based billing and credit tracking
</Card>
<Card
title="Schema Reference"
icon="table"
href="/analytics/schema-reference"
title="Monitoring "
icon="chart-line"
href="/analytics/query-examples#usage-analytics"
>
Browse available tables, columns, and data types
API health and performance monitoring
</Card>
<Card title="Query Restrictions" icon="shield-check" href="/analytics/query-restrictions">
View limits, quotas, and permissions
<Card
title="Product Teams"
icon="users"
href="/analytics/query-examples#usage-by-user"
>
User behavior and engagement insights
</Card>
</CardGroup>
Loading
Loading