| 1 |
<?php //phpcs:ignore |
| 2 |
|
| 3 |
/** |
| 4 |
* Analytics API — Orchestrator |
| 5 |
* |
| 6 |
* @package Disco |
| 7 |
* @subpackage \Rest |
| 8 |
* @since 1.1.13 |
| 9 |
* @category Rest |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Disco\Rest; |
| 13 |
|
| 14 |
use Disco\Rest\Analytics\CampaignsApi; |
| 15 |
use Disco\Rest\Analytics\CustomersApi; |
| 16 |
use Disco\Rest\Analytics\IntentApi; |
| 17 |
use Disco\Rest\Analytics\OrdersApi; |
| 18 |
use Disco\Rest\Analytics\ProductsApi; |
| 19 |
use Disco\Rest\Analytics\RevenueChartApi; |
| 20 |
use Disco\Rest\Analytics\SummaryApi; |
| 21 |
use WP_REST_Controller; |
| 22 |
|
| 23 |
/** |
| 24 |
* Class AnalyticsApi |
| 25 |
* |
| 26 |
* Thin orchestrator that delegates route registration to focused sub-controllers |
| 27 |
* under the Disco\Rest\Analytics namespace. |
| 28 |
* |
| 29 |
* Routes registered (via sub-controllers): |
| 30 |
* |
| 31 |
* - GET /disco/v1/analytics/intents-performance — Intent-wise performance (no comparison). |
| 32 |
* - GET /disco/v1/analytics/revenue-chart — Time-bucketed revenue data. |
| 33 |
* - GET /disco/v1/analytics/summary — Top-level KPI summary. |
| 34 |
* - GET /disco/v1/analytics/campaigns — Paginated campaign list. |
| 35 |
* - GET /disco/v1/analytics/campaigns/{id} — Single campaign KPIs + chart. |
| 36 |
* - GET /disco/v1/analytics/products — Paginated products sold via campaigns. |
| 37 |
* - GET /disco/v1/analytics/products/{id} — Single product detail. |
| 38 |
* - GET /disco/v1/analytics/orders — Paginated campaign-linked orders. |
| 39 |
* - GET /disco/v1/analytics/orders/{id} — Single order with full line items. |
| 40 |
* - GET /disco/v1/analytics/customers — Paginated customers who bought via campaigns. |
| 41 |
* - GET /disco/v1/analytics/customers/{id} — Single customer detail. |
| 42 |
* |
| 43 |
* @package Disco |
| 44 |
* @subpackage \Rest |
| 45 |
* @author Ohidul Islam <wahid0003@gmail.com> |
| 46 |
* @link https://webappick.com |
| 47 |
* @license https://opensource.org/licenses/gpl-license.php GNU Public License |
| 48 |
* @category Rest |
| 49 |
*/ |
| 50 |
class AnalyticsApi extends WP_REST_Controller { //phpcs:ignore |
| 51 |
|
| 52 |
/** |
| 53 |
* The route base name for analytics endpoints. |
| 54 |
* |
| 55 |
* @since 1.1.13 |
| 56 |
*/ |
| 57 |
public const ROUTE_NAME = 'analytics'; |
| 58 |
|
| 59 |
/** |
| 60 |
* AnalyticsApi constructor. |
| 61 |
* |
| 62 |
* Sets the namespace and rest base for all analytics routes. |
| 63 |
*/ |
| 64 |
public function __construct() { |
| 65 |
$this->namespace = Api::NAMESPACE_NAME . '/' . Api::VERSION; |
| 66 |
$this->rest_base = self::ROUTE_NAME; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Delegates route registration to each analytics sub-controller. |
| 71 |
* |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
public function register_routes() { //phpcs:ignore |
| 75 |
( new IntentApi )->register_routes(); |
| 76 |
( new RevenueChartApi )->register_routes(); |
| 77 |
( new SummaryApi )->register_routes(); |
| 78 |
( new CampaignsApi )->register_routes(); |
| 79 |
( new ProductsApi )->register_routes(); |
| 80 |
( new OrdersApi )->register_routes(); |
| 81 |
( new CustomersApi )->register_routes(); |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|