Skip to content

docs: explain analytics migration#4298

Merged
chronark merged 5 commits intomainfrom
11-10-docs_explain_analytics_migration
Nov 10, 2025
Merged

docs: explain analytics migration#4298
chronark merged 5 commits intomainfrom
11-10-docs_explain_analytics_migration

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Nov 10, 2025

What does this PR do?

Add a comprehensive analytics migration guide for transitioning from v1 to v2 analytics system. The guide explains the shift from predefined parameters to SQL-based querying, covering key changes in access permissions, request formats, response structures, and common migration patterns.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Verify all links in the migration guide work correctly
  • Check that the SQL query examples are valid and properly formatted
  • Ensure the guide accurately represents the differences between v1 and v2 analytics
  • Confirm the guide is added to the migration index page with proper navigation

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@vercel
Copy link

vercel bot commented Nov 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
dashboard Ignored Ignored Preview Nov 10, 2025 1:35pm
engineering Ignored Ignored Preview Nov 10, 2025 1:35pm

@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2025

⚠️ No Changeset found

Latest commit: 1e5b017

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a new v1→v2 analytics migration guide MDX, inserts an "Analytics Endpoints" card into the v1 migration index, and registers the new page in the docs manifest.

Changes

Cohort / File(s) Summary
New analytics migration guide
apps/docs/api-reference/v1/migration/analytics.mdx
New MDX documenting v1→v2 analytics migration: overview of SQL-based redesign, key changes, access/auth (v1 auto vs v2 opt‑in/beta), permission mappings, request/response format differences, migration patterns with examples, and support links.
Migration index update
apps/docs/api-reference/v1/migration/index.mdx
Inserted an "Analytics Endpoints" card into the Detailed Migration by Category list (positioned after Rate Limiting Endpoints).
Docs manifest update
apps/docs/docs.json
Added "analytics" entry under the deprecated api.unkey.dev/v1 dropdown to register the new migration page.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Documentation-only additions and small navigation/config edits; review should focus on content accuracy and config correctness.
  • Areas to check:
    • Internal links and anchors inside analytics.mdx.
    • That apps/docs/docs.json entry path exactly matches the new file location and key naming.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'docs: explain analytics migration' clearly and specifically summarizes the main change: adding documentation that explains the analytics migration process.
Description check ✅ Passed The description comprehensively covers the PR purpose, type of change, testing instructions, and includes a completed checklist. All required sections are present and properly filled out.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7200ec3 and 1e5b017.

📒 Files selected for processing (1)
  • apps/docs/api-reference/v1/migration/analytics.mdx (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/docs/api-reference/v1/migration/analytics.mdx (2)

185-248: Add descriptive labels to code blocks for consistency.

The Common Migration Patterns section uses unlabeled code blocks, while earlier sections (like Access and Authentication and Request Format Changes) include descriptive labels (e.g., "v1 Request Structure", "v2 Response Structure"). Add labels to all code blocks for consistency and clarity.

Update code blocks to match the labeling pattern used elsewhere:

- ```bash
+ ```bash v1: Basic Query
  curl -X GET "https://api.unkey.dev/v1/analytics.getVerifications?apiId=api_123&start=1620000000000&groupBy=day"

V2: SQL Equivalent

  • curl -X POST https://api.unkey.com/v2/analytics.getVerifications \
      -H "Authorization: Bearer <root-key>" \
      -H "Content-Type: application/json" \
      -d '{
        "query": "SELECT time, SUM(count) as total FROM key_verifications_per_day_v1 WHERE key_space_id = '\''ks_123'\'' AND time >= now() - INTERVAL 30 DAY GROUP BY time ORDER BY time"
      }'

Apply the same pattern to the remaining examples: Filter by User, Outcome Breakdown, and Top Users by Usage.

---

`252-264`: **Standardize link formats in Getting Help section.**

The links in Getting Help mix absolute and relative URLs inconsistently:
- Line 254: `https://unkey.com/docs/analytics` (absolute)
- Lines 255–260: `/analytics/...` (relative)
- Line 261: `https://unkey.com/docs/api-reference/v1/migration` (absolute)

Compare this to the Getting Help section in index.mdx (lines 119-125), which uses consistent absolute URLs for all external and internal links. For maintainability, standardize all links in this section to use either:
1. **All absolute URLs** (recommended for consistency with the migration index): `https://unkey.com/docs/analytics`, `https://unkey.com/docs/api-reference/v1/migration`
2. **Or all relative links** for internal docs (if that's a project convention)

Choose one approach and apply it consistently.

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: CodeRabbit UI

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 6a3148c3484598966be17243eb3755e394d820a1 and f213a56d491150b242470a51da4f5924129e8b43.

</details>

<details>
<summary>📒 Files selected for processing (3)</summary>

* `apps/docs/api-reference/v1/migration/analytics.mdx` (1 hunks)
* `apps/docs/api-reference/v1/migration/index.mdx` (1 hunks)
* `apps/docs/docs.json` (1 hunks)

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)</summary>

* GitHub Check: Analyze (javascript-typescript)

</details>

<details>
<summary>🔇 Additional comments (6)</summary><blockquote>

<details>
<summary>apps/docs/api-reference/v1/migration/index.mdx (1)</summary><blockquote>

`110-112`: **LGTM!**

The new Analytics card is well-placed, properly formatted, and consistent with other migration category cards. The icon and description clearly communicate the purpose.

</blockquote></details>
<details>
<summary>apps/docs/api-reference/v1/migration/analytics.mdx (4)</summary><blockquote>

`1-21`: **LGTM!**

Clear, well-structured introduction to the migration guide with good context on the v1-to-v2 transition.

---

`24-80`: **LGTM!**

Clear explanation of access changes from automatic v1 to opt-in v2. Permission table is well-organized and the private beta context is helpful for users.

---

`84-176`: **LGTM!**

Request and response format sections are clear with good examples showing v1-to-v2 transformation. The automatic security filtering explanation is valuable.

---

`71-79`: **Clarify apiId vs key_space_id terminology.**

Line 79 states "you can filter by `apiId` in your query," but all SQL examples use `key_space_id` instead. This is confusing for users migrating from v1 to v2:

- V1 examples (line 98, 203, 220, 237) use `apiId` as a parameter
- V2 examples (lines 195, 212, 229, 246) use `key_space_id` in SQL WHERE clauses
- Line 79 mentions `apiId` as a filterable field

Please clarify the relationship between these fields:
1. Are `apiId` and `key_space_id` the same thing with different names (v1 vs v2)?
2. Or are they different fields that need different handling?

If they're the same, consider updating line 79 to explicitly say "you can filter by `key_space_id` (the v2 equivalent of `apiId`)" or update the note to mention both names. If they're different, add an explanation of the mapping.



Also applies to: 195-195, 212-212, 229-229, 246-246

</blockquote></details>
<details>
<summary>apps/docs/docs.json (1)</summary><blockquote>

`309-309`: **LGTM!**

The analytics entry is correctly placed in the migration guides list with proper JSON formatting and sequencing.

</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link
Member

@perkinsjr perkinsjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

EXTREMELY minor nit, maybe we make the opt in a warning? This double info block is fine and can go to prod.

Image

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/docs/api-reference/v1/migration/analytics.mdx (1)

106-113: Consider clarifying the bash quote escaping syntax.

The pattern '\''ks_123'\'' for escaping quotes within bash single-quoted strings is technically correct but may confuse users. Consider adding a brief comment or showing the raw JSON structure separately for clarity.

You could add a note like:

# Raw JSON payload (before bash escaping):
# {"query": "SELECT time, SUM(count) as total FROM key_verifications_per_day_v1 WHERE key_space_id = 'ks_123' ..."}

# Bash command with escaped quotes:
curl -X POST https://api.unkey.com/v2/analytics.getVerifications ...

Alternatively, keep the current examples but add inline comments explaining the escaping.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f213a56 and 7200ec3.

📒 Files selected for processing (1)
  • apps/docs/api-reference/v1/migration/analytics.mdx (1 hunks)
🔇 Additional comments (6)
apps/docs/api-reference/v1/migration/analytics.mdx (6)

1-4: Front matter looks good.

Metadata is correctly formatted and descriptive for the guide.


6-21: Clear, focused overview.

Effectively frames the v1→v2 transition with key changes and benefits. Good foundation for the detailed sections that follow.


121-176: Response format section is clear and well-structured.

The comparison effectively shows the shift from fixed V1 schema to flexible V2 SQL-based responses. The meta/data envelope pattern is clearly illustrated with the dynamic fields note.


252-263: Verify all documentation links resolve correctly and consider URL consistency.

The help section mixes absolute URLs (line 254) and relative URLs (lines 255-260). While this may be intentional, ensure:

  1. The absolute URL https://unkey.com/docs/analytics is correct and up-to-date
  2. All relative paths /analytics/getting-started, /analytics/schema-reference, etc. exist and are correct
  3. Consistency in URL format (standardize to all relative or all absolute where possible)

26-69: All links and endpoints verified — no issues found.

The documentation links and endpoint URLs are correct and properly configured:

  • Endpoints: v1 uses api.unkey.dev, v2 uses api.unkey.com (confirmed throughout the file)
  • Documentation links: All relative links (/analytics, /analytics/getting-started, /analytics/schema-reference, etc.) are properly registered in apps/docs/docs.json and resolve correctly
  • Permissions: The permission names api.*.read_analytics and api.{apiId}.read_analytics match the actual v2 permissions system (confirmed in packages/rbac/src/permissions.ts)

180-248: All migration patterns verified as correct.

Field names (key_space_id, external_id, outcome, time, count), table name (key_verifications_per_day_v1), outcome values (VALID, RATE_LIMITED, INVALID), and SQL functions (sumIf, SUM, GROUP BY, ORDER BY, LIMIT) are all consistent with the analytics schema and working examples in query-examples.mdx. The migration patterns accurately represent V1-to-V2 migration scenarios.

Copy link
Collaborator Author

yes

@chronark chronark merged commit c129cc9 into main Nov 10, 2025
9 of 13 checks passed
@chronark chronark deleted the 11-10-docs_explain_analytics_migration branch November 10, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants