Data Analytics
The Data Analytics system provides interactive e-commerce reporting with 10 built-in reports, a KPI dashboard, and CSV export โ all with responsive Recharts visualizations.
This is the interactive analytics hub (formerly labeled "Reports" in the admin menu). For automated email-based reports, see Email Reports.
Overviewโ
Navigate to Reports (Data Analytics) in the WordPress admin menu to access the analytics dashboard and report viewer.
Key Features:
- ๐ KPI Dashboard โ Real-time key metrics with date range selection
- ๐ 10 Built-in Reports โ Sales, shipping, chargebacks, geographic, queue health, and more
- ๐ Interactive Charts โ Bar, line, pie, and area charts via Recharts
- ๐ Sortable Tables โ Click column headers to sort, with automatic totals row
- ๐ฅ CSV Export โ Download any report as a CSV file
- ๐ช Site Filtering โ Filter all reports by individual site
- ๐ Deep Linking โ Shareable URLs for specific reports (e.g.,
?page=gsm-data-reports&report=sales-summary) - ๐ SQL Security โ SELECT-only parser, table allowlist, 10K row limit, 5-second execution timeout
Permission Required: manage_options
Version Added: 1.18.0
KPI Dashboardโ
The dashboard displays at the top of the analytics page with key metrics for the selected date range:
| KPI | Description |
|---|---|
| Total Orders | Count of distinct orders in the date range |
| Total Revenue | Sum of line item revenue (price ร quantity) |
| Avg Order Value | Revenue รท Total Orders |
| Pending Orders | Orders with ship_status = 0 |
| Shipped Orders | Orders with ship_status = 2 |
| Items Processed | Sum of product line item quantities |
| Chargeback Rate | Chargebacks รท Total Orders (percentage) |
| Avg Fulfillment Time | Average days between order creation and shipment |
Date Range Selectionโ
- Select start and end dates via calendar picker
- Maximum 12-month range enforced on both frontend and backend
- KPI data refreshes automatically on date change (400ms debounce to prevent excessive API calls)
- In-flight requests are cancelled when a newer date is selected
Cachingโ
Dashboard KPI results are cached with a 5-minute TTL via WordPress transients, preventing repeated heavy queries on page reload.
Available Reportsโ
Category: Sales & Revenueโ
| Report | Description | Chart Type |
|---|---|---|
| Sales Summary | Order totals and revenue by date | Line chart |
| Revenue by Site | Revenue breakdown per store | Bar chart |
| Payment Method Breakdown | Order count and revenue by payment method | Pie chart |
| Geographic Sales | Revenue by shipping region | Bar chart |
Category: Operationsโ
| Report | Description | Chart Type |
|---|---|---|
| Orders by Status | Order distribution by processing status | Pie chart |
| Top Selling Products | Highest quantity products by SKU and name | Bar chart |
| Shipping Performance | Shipping metrics by carrier | Bar chart |
| Order Volume Trends | Order volume over time | Area chart |
Category: Health & Monitoringโ
| Report | Description | Chart Type |
|---|---|---|
| Chargeback Summary | Dispute trends and analysis | Line chart |
| Queue Health | Queue job status and processing metrics | Bar chart |
Interfaceโ
Report Navigationโ
- Category Tabs โ Reports grouped by Sales & Revenue, Operations, Health & Monitoring
- Search Filter โ Type to filter available reports by name
- Report Submenu โ Each report also appears as a submenu item under Reports in the WordPress admin sidebar for one-click access
Report Viewerโ
After selecting a report:
- Date range picker โ Set start and end dates (12-month max)
- Site filter โ Filter by specific site or view all sites
- Chart visualization โ Interactive Recharts chart (hover for tooltips)
- Data table โ Sortable columns with automatic totals row
- CSV Export โ Download button for the current report data
Deep Linkingโ
Reports support URL-based navigation:
/wp-admin/admin.php?page=gsm-data-reports&report=sales-summary
/wp-admin/admin.php?page=gsm-data-reports&report=payment-method-breakdown
Navigating between reports and tabs updates the URL for shareability and bookmarking.
REST API Endpointsโ
List Available Reportsโ
GET /wp-json/gsm-middleware/v1/analytics/reports
Returns all registered reports with metadata (name, description, category, slug).
Execute a Reportโ
POST /wp-json/gsm-middleware/v1/analytics/reports/{slug}/execute
Body Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
start_date | string | Yes | Start date (YYYY-MM-DD) |
end_date | string | Yes | End date (YYYY-MM-DD) |
site_id | integer | No | Filter by site ID |
Response:
{
"success": true,
"data": {
"columns": [
{ "key": "date", "label": "Date", "type": "date" },
{ "key": "total_orders", "label": "Total Orders", "type": "number" },
{ "key": "revenue", "label": "Revenue", "type": "currency" }
],
"rows": [...],
"totals": { "total_orders": 1523, "revenue": 192456.78 }
}
}
Dashboard KPIsโ
GET /wp-json/gsm-middleware/v1/analytics/dashboard
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
start_date | string | Yes | Start date (YYYY-MM-DD) |
end_date | string | Yes | End date (YYYY-MM-DD) |
site_id | integer | No | Filter by site ID |
List Sitesโ
GET /wp-json/gsm-middleware/v1/analytics/sites
Returns the list of sites for the filter dropdown. Cached for 10 minutes via transient.
SQL Security Layerโ
All report queries are validated through a security layer:
- SELECT-only โ Only
SELECTstatements are permitted; any DML/DDL is rejected - Table allowlist โ Queries can only access approved
rm_*tables - Row limit โ Maximum 10,000 rows returned per query
- Execution timeout โ Queries are killed after 5 seconds
- Parameter binding โ All user inputs (dates, site IDs) are parameterized via
wpdb::prepare()
Performance Indexesโ
Migration 020 adds analytics-specific indexes for high-volume tables:
| Table | Index | Purpose |
|---|---|---|
rm_lineitems | idx_item | Top Selling Products report (2.6M+ rows) |
shipments | idx_order_id | Shipping Performance and fulfillment KPI |
shipments | idx_shipping_provider | Shipping Performance GROUP BY |
rm_order | idx_site_dateadded | Site-filtered date range queries (all reports) |
rm_address | idx_order_type | Geographic Sales report (1.7M+ rows) |
rm_items | idx_sku | SKU lookups in reports and order processing |
Architectureโ
Data Flowโ
- User selects report, date range, and optional site filter
- React app sends POST to
/analytics/reports/{slug}/execute Report_Executorvalidates parameters (date format, 12-month max range)- SQL query runs against the tasks database with parameterized inputs
cast_column_types()converts string values to proper numeric types (required for Recharts)- JSON response rendered as chart + sortable table
Dashboard Loadingโ
Dashboard data is optimized for fast initial render:
- Reports list and sites data are inlined into the page via
wp_localize_script(eliminates 2 REST API calls on load) - Only the KPI dashboard fetch requires a REST API call
- KPI fetch fires immediately on mount (no initial debounce delay)
Related Documentationโ
- Email Reports โ Automated email-based reporting
- Performance Optimization โ Query and index optimizations
- Crontab Generator โ Schedule automated report delivery