Back to KB
Difficulty
Intermediate
Read Time
4 min

Admin Analytics API Endpoint

By Codcompass TeamΒ·Β·4 min read

Admin Analytics API Endpoint

Overview

The /api/admin/analytics endpoint provides a consolidated snapshot of platform statistics and engagement metrics for administrative dashboards. It is designed to be called by internal monitoring tools, admin panel interfaces, or automated reporting systems that require real-time counts of published content, user base, and subscription status.

Currently, the endpoint returns real database counts for articles, categories, users, and active subscriptions. Traffic-related metrics (page views, clicks, bounce rate, etc.) are returned as placeholders with a descriptive note indicating that page-view tracking has not yet been implemented. This design allows frontend dashboards to render consistently while backend teams integrate third-party analytics providers (e.g., Google Analytics, Plausible) or implement custom view-tracking tables.

The route is configured with force-dynamic rendering, ensuring that every request bypasses Next.js static caching and fetches fresh data directly from the database. This is critical for admin panels where stale metrics could mislead operational decisions.

Endpoint Reference

PropertyValue
Path/api/admin/analytics
HTTP MethodGET
AuthenticationRequires valid admin session (role: ADMIN)
Cachingforce-dynamic (no static caching)
Content-Typeapplication/json

Note on Authentication: Although endpoint metadata may indicate public access, the implementation enforces role-based access control. Requests without a valid session or with a non-admin role will receive a 403 Forbidden response.

Request Format

This endpoint does not require query paramete

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back

Sources

  • β€’ api-reference