Skip to content

feat: rework per-link stats onto the new analytics surface - #5

Merged
Zingzy merged 1 commit into
mainfrom
feat/stats-endpoints-migration
Aug 16, 2026
Merged

feat: rework per-link stats onto the new analytics surface#5
Zingzy merged 1 commit into
mainfrom
feat/stats-endpoints-migration

Conversation

@Zingzy

@Zingzy Zingzy commented Aug 14, 2026

Copy link
Copy Markdown
Member

Follows the API change in spoo-me/spoo#291/#292 and removes the v0 stats fallback.

  • Looking up a code now picks the right surface at runtime: signed-in users resolve it via GET /api/v1/urls/{domain}/{alias} and read the authed GET /api/v1/stats/links/{id}; anonymous users, and codes outside the account, use GET /api/v1/public/stats/{code}.
  • Public 404 (unknown or private stats) and 401 (password protected) render as a single quiet unavailable state instead of an error, and those results are not retried.
  • The v0 fallback and its response adapter are deleted.
  • avg_redirection_time is nullable now, matching the wire; the old schema rejected zero-click windows.

Kept tightly scoped to the stats module so the PKCE branch rebases cleanly. Typecheck, lint, and build pass.

Summary by CodeRabbit

  • New Features

    • Added separate account and individual-link analytics retrieval.
    • Added public statistics access for shared links.
    • Link analytics now resolves the selected link automatically.
    • Added support for configurable statistics time ranges and time zones.
  • Bug Fixes

    • Improved handling when public statistics are unavailable, showing an informational message instead of an error.
    • Statistics now support missing average redirection-time measurements without failing.

GET /api/v1/stats is dropping the scope param and going auth-only.
Authed lookups now resolve alias to url_id via /urls/{domain}/{alias}
and read /stats/links/{url_id}; anonymous or foreign links fall back
to /public/stats/{code}. The v0 stats fallback is removed.
Copilot AI lite review requested due to automatic review settings August 14, 2026 20:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: abecade4-3e04-48bd-af76-f2e750ca1dce

📥 Commits

Reviewing files that changed from the base of the PR and between 1bfd643 and 0068c99.

📒 Files selected for processing (6)
  • src/api/stats.ts
  • src/api/types.ts
  • src/api/urls.ts
  • src/components/sidepanel/AnalyticsTab.tsx
  • src/hooks/use-stats.ts
  • src/schemas/api.ts

📝 Walkthrough

Walkthrough

Changes

Statistics flow

Layer / File(s) Summary
Stats contracts and response schemas
src/api/types.ts, src/schemas/api.ts
StatsQuery now targets authenticated endpoints. PublicStatsQuery and PublicStatsResponse support public statistics. avg_redirection_time accepts null.
Endpoint access and URL routing
src/api/urls.ts, src/api/stats.ts
The API adds account, owned-link, and public stats retrieval. URL lookup resolves owned links before public fallback. Legacy v0 and generic stats APIs are removed.
Stats hooks and analytics display
src/hooks/use-stats.ts, src/components/sidepanel/AnalyticsTab.tsx
Account and URL hooks use separate queries. URL requests enable only for selected links, limit retries, and display unavailable public stats as muted information.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 0068c

The change is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant AnalyticsTab
  participant StatsHooks
  participant StatsAPI
  participant URLAPI
  User->>AnalyticsTab: Open analytics
  AnalyticsTab->>StatsHooks: Request account or URL stats
  StatsHooks->>StatsAPI: Fetch statistics
  StatsAPI->>URLAPI: Resolve owned URL
  URLAPI-->>StatsAPI: Return URL or no match
  StatsAPI-->>StatsHooks: Return owned or public stats
  StatsHooks-->>AnalyticsTab: Return data or StatsUnavailableError
  AnalyticsTab-->>User: Render metrics or status text
Loading

Possibly related PRs

  • spoo-me/spoo-snap#2: Introduced the stats APIs and hooks that this change replaces with separate account, owned-link, and public flows.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating per-link statistics to the new analytics API surface.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/stats-endpoints-migration

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.

@Zingzy
Zingzy merged commit 36168ed into main Aug 16, 2026
2 checks passed
@Zingzy
Zingzy deleted the feat/stats-endpoints-migration branch August 16, 2026 12:39
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