POST /api/components/track
Records a user interaction with a UI component. This endpoint is used to track how users engage with different components in the T1 Component Library, supporting both anonymous and registered users.Endpoint
Request Body
Name of the component being tracked
- Examples: “Button”, “Modal”, “Card”, “Tooltip”
- Will be trimmed of whitespace
- Used to aggregate statistics by component
Action performed on the component
- Examples: “click”, “hover”, “open”, “close”, “focus”
- Will be trimmed of whitespace
- Used to track specific user interactions
Type of user performing the action
anonymous: User is not logged in (default)registered: User is authenticated- Optional field, defaults to “anonymous” if not provided
MongoDB ObjectId of the registered user
- Required only when
tipo_usuariois “registered” - Must be a valid MongoDB ObjectId
- Links the interaction to a specific user account
Response Fields
Indicates if the interaction was recorded successfully
Success message: “Interacción registrada”
Created tracking record
Response Examples
Example Requests
Error Codes
| Code | Message | Cause |
|---|---|---|
400 | Errores de validación | Required fields missing or invalid format |
500 | Error interno del servidor | Database error or other unexpected error |
Common Use Cases
- Component Analytics: Track which components are most frequently used
- Interaction Patterns: Understand how users interact with specific components
- A/B Testing: Compare interaction rates between different component variants
- User Behavior: Analyze differences between anonymous and registered user interactions
Implementation Notes
- The timestamp is automatically set to the current time when the record is created
- If
tipo_usuariois omitted, it defaults to “anonymous” (see tracking.service.ts:41) - The
usuariofield is optional and should only be provided for registered users - All tracking data can be viewed and exported using the export endpoints (requires authentication)