# BackOffice Coupon Analytics ES Queries (v1)

Source of truth:
- Service: `app/Services/Elasticsearch/BackOfficeCouponAnalyticsElasticsearchService.php`
- Controller: `app/Http/Controllers/BackOffice/BackOfficeWidgetController.php`
- Index: `customer_subscription_v1`

## ES-backed service methods
- `fetchCouponAnalytics(int $appId, ?string $couponCode = null, bool $includeTopCodes = true)`

## API endpoints
- `GET /admin/api/back-office/coupons/analytics/global`
- `GET /admin/api/back-office/coupons/analytics/{couponId}`

## Notes
- Coupon metrics are computed from nested `orders` aggregations (usage, success, discount, revenue).
- Optional coupon-specific query narrows to exact code in service layer.
