Skip to main content

GET /api/components/stats

Retrieves aggregated statistics about component usage and interactions. This endpoint provides insights into which components are most popular, what actions users perform, and the distribution between anonymous and registered users.

Endpoint

GET /api/components/stats
Authentication: None (Public endpoint)

Response Fields

success
boolean
required
Indicates if the statistics were retrieved successfully
data
object
required
Aggregated statistics data

Response Example

200 - Success
{
  "success": true,
  "data": {
    "totalInteracciones": 1500,
    "porComponente": [
      { "_id": "Button", "count": 500 },
      { "_id": "Modal", "count": 300 },
      { "_id": "Card", "count": 250 },
      { "_id": "Tooltip", "count": 200 },
      { "_id": "Dropdown", "count": 150 },
      { "_id": "Input", "count": 100 }
    ],
    "porAccion": [
      { "_id": { "componente": "Button", "accion": "click" }, "count": 400 },
      { "_id": { "componente": "Button", "accion": "hover" }, "count": 100 },
      { "_id": { "componente": "Card", "accion": "click" }, "count": 150 },
      { "_id": { "componente": "Card", "accion": "hover" }, "count": 100 },
      { "_id": { "componente": "Modal", "accion": "open" }, "count": 200 },
      { "_id": { "componente": "Modal", "accion": "close" }, "count": 100 },
      { "_id": { "componente": "Tooltip", "accion": "hover" }, "count": 200 }
    ],
    "porTipoUsuario": [
      { "_id": "anonymous", "count": 1000 },
      { "_id": "registered", "count": 500 }
    ]
  }
}

Example Request

curl http://localhost:3001/api/components/stats

Error Codes

CodeMessageCause
500Error interno del servidorDatabase error or aggregation failure

Data Insights

Total Interactions

Provides a quick overview of overall component library usage. Useful for tracking growth and engagement over time.

By Component (porComponente)

  • Limited to top 10 components to focus on most popular items
  • Sorted by count in descending order
  • Helps identify which components are most valuable to users
  • Can guide prioritization for component improvements and documentation

By Action (porAccion)

  • Shows every unique component-action combination
  • Sorted alphabetically by component name, then by count
  • Reveals how users interact with each component
  • Example insights:
    • High “hover” counts may indicate users exploring functionality
    • High “click” counts show active engagement
    • Modal “open” vs “close” ratios can reveal UX issues

By User Type (porTipoUsuario)

  • Compares anonymous vs registered user engagement
  • Helps understand authentication impact on usage
  • Can inform decisions about feature gating or user experience

Implementation Details

The statistics are calculated using MongoDB aggregation pipelines:
  • Total Interactions: Simple document count (tracking.service.ts:51)
  • By Component: Groups by component name, limits to 10 results (tracking.service.ts:52-56)
  • By Action: Groups by component and action combination (tracking.service.ts:57-60)
  • By User Type: Groups by user type field (tracking.service.ts:61-63)
All aggregations run in parallel for optimal performance.

Use Cases

  • Dashboard Visualization: Display real-time component usage metrics
  • Product Analytics: Identify most/least popular components
  • UX Research: Understand user interaction patterns
  • Resource Allocation: Prioritize development based on usage data
  • Marketing: Showcase popular components to potential users

Build docs developers (and LLMs) love