- Docs
- Specs
- Analytics
- Analytics overview
Analytics Overview¶
This page specifies the company-scoped analytics overview for the Fleet Dashboard. It provides Manager-only KPIs over a date range for trips, bookings, trip-seat utilization, D2D requests, enrollments, reviews, and documented performance rates.
Sources: Analytics index, Trip Analysis, Reviews, API Conventions, Domain Glossary, Fleet Dashboard.
1. Purpose and scope¶
GET /api/company/analytics/overview returns an aggregate KPI snapshot for the authenticated Manager's Company. The endpoint is read-only, company-scoped, and contains no payment/revenue fields.
The overview is computed from existing company records (Trips, Bookings, D2D Requests, Memberships/Enrollments, Reviews). It does not create a new analytics table. Trip Analysis records (trip_analytics) are not required by this slice; on-time departure rate is null when no documented on-time source is available.
2. Authorization and tenancy¶
| Rule | Contract |
|---|---|
| Authentication | auth:sanctum required. |
| Role | Manager only. Non-manager company users receive 403. |
| Company scope | Company is derived from authenticated membership via TenantContext; company_id is never accepted from client. |
| Cross-tenant | No cross-tenant data is returned. Company routes return 404 when no company membership resolves. |
| Suspended company | Returns 403 with the standard suspended-company message on all company routes. |
3. Endpoint¶
| Method | Path | Audience | Purpose |
|---|---|---|---|
GET |
/api/company/analytics/overview |
Manager | Return company-scoped KPI overview for a date range. |
4. Filters¶
| Filter | Type | Default | Behavior |
|---|---|---|---|
date_from |
Y-m-d |
date_to - 29 days |
Inclusive lower bound (UTC date). |
date_to |
Y-m-d |
current UTC date | Inclusive upper bound (UTC date). Must be on or after date_from. |
Invalid date format or date_to < date_from returns 422 with field-level errors.
The date window applies to records whose relevant activity timestamp falls within the inclusive UTC date range:
| KPI group | Date field |
|---|---|
| Trips | trips.departure_at |
| Bookings | bookings.created_at (request time) |
| D2D Requests | d2d_requests.created_at (request time) |
| Enrollments | memberships.created_at for Passenger/Driver enrollment memberships |
| Reviews | trip_reviews.created_at |
| Completion/on-time performance | Trips in range by departure_at |
Subscription seat counts are current company state (not date-windowed) because seats represent active Passenger Memberships against the Tier limit.
5. Response shape¶
200 response (JsonResource, unwrapped):
{
"date_from": "2026-10-29",
"date_to": "2026-11-27",
"trips": {
"total": 12,
"scheduled": 3,
"in_transit": 1,
"completed": 7,
"cancelled": 1
},
"bookings": {
"total": 40,
"pending": 4,
"approved": 30,
"rejected": 3,
"cancelled": 3
},
"seats": {
"used": 30,
"available": 10,
"capacity": 40,
"utilization_percent": 75.0
},
"d2d_requests": {
"total": 5,
"pending": 1,
"approved": 2,
"rejected": 1,
"cancelled": 1
},
"enrollments": {
"pending": 2,
"approved": 18,
"rejected": 1,
"suspended": 0
},
"reviews": {
"average_rating": 4.5,
"review_count": 12
},
"performance": {
"completion_rate_percent": 87.5,
"on_time_departure_rate_percent": null
}
}
5.1 Field definitions¶
| Field | Definition |
|---|---|
date_from, date_to |
Applied inclusive UTC date range as Y-m-d. |
trips.total |
Count of company Trips with departure_at in range. |
trips.scheduled/in_transit/completed/cancelled |
Trip counts by status in range. |
bookings.total |
Count of company Bookings created in range. |
bookings.pending/approved/rejected/cancelled |
Booking counts by status in range. |
seats.used |
Sum of approved Bookings for company Trips with departure_at in range. |
seats.capacity |
Sum of seat_capacity for company Trips with departure_at in range. |
seats.available |
max(capacity - used, 0). |
seats.utilization_percent |
used / capacity * 100, rounded to two decimals; 0.0 when capacity is zero. |
d2d_requests.total |
Count of company D2D Requests created in range. |
d2d_requests.pending/approved/rejected/cancelled |
D2D Request counts by status in range. |
enrollments.pending/approved/rejected/suspended |
Counts of Passenger/Driver Memberships created in range by enrollment status. approved maps to Membership active. Manager memberships are excluded. |
reviews.average_rating |
Average rating for company Reviews created in range, rounded to two decimals; null when review_count is zero. |
reviews.review_count |
Count of company Reviews created in range. |
performance.completion_rate_percent |
completed / total * 100 for Trips in range, rounded to two decimals; 0.0 when total is zero. |
performance.on_time_departure_rate_percent |
null in this slice. The Trip Analysis spec defines late departure metrics, but trip_analytics computation/storage is not implemented; returning null is null-safe and avoids inventing data. |
6. Empty and null-safe behavior¶
When no data exists in range, counts are 0, rates are 0.0 where mathematically defined with zero denominator fallback, reviews.average_rating is null, and performance.on_time_departure_rate_percent is null.
7. Errors¶
Errors follow { "message": string, "errors"?: Record<string, string[]> }.
| Case | Status | Envelope |
|---|---|---|
Invalid date format or invalid range (date_to < date_from) |
422 | message + field errors |
| Non-manager / inactive role denied by middleware | 403 | message only |
| Suspended Company | 403 | message only |
| Missing company membership | 404 | message only |
8. Open questions¶
- On-time source: When
trip_analyticsis implemented,performance.on_time_departure_rate_percentshould be defined as percentage of completed analyzed trips in range withlate_departure_minutes <= 0(or another documented threshold). Until then it remainsnull. - Subscription seat KPI: The Dashboard Overview currently shows seats used vs tier limit. A future extension may add
subscription_seatswithout breaking this response. - Grouping: No daily/weekly grouping is defined; this endpoint returns a single aggregate for the selected range.