Skip to main content

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.

Separate from Email Reports

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:

KPIDescription
Total OrdersCount of distinct orders in the date range
Total RevenueSum of line item revenue (price ร— quantity)
Avg Order ValueRevenue รท Total Orders
Pending OrdersOrders with ship_status = 0
Shipped OrdersOrders with ship_status = 2
Items ProcessedSum of product line item quantities
Chargeback RateChargebacks รท Total Orders (percentage)
Avg Fulfillment TimeAverage 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โ€‹

ReportDescriptionChart Type
Sales SummaryOrder totals and revenue by dateLine chart
Revenue by SiteRevenue breakdown per storeBar chart
Payment Method BreakdownOrder count and revenue by payment methodPie chart
Geographic SalesRevenue by shipping regionBar chart

Category: Operationsโ€‹

ReportDescriptionChart Type
Orders by StatusOrder distribution by processing statusPie chart
Top Selling ProductsHighest quantity products by SKU and nameBar chart
Shipping PerformanceShipping metrics by carrierBar chart
Order Volume TrendsOrder volume over timeArea chart

Category: Health & Monitoringโ€‹

ReportDescriptionChart Type
Chargeback SummaryDispute trends and analysisLine chart
Queue HealthQueue job status and processing metricsBar 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:

  1. Date range picker โ€” Set start and end dates (12-month max)
  2. Site filter โ€” Filter by specific site or view all sites
  3. Chart visualization โ€” Interactive Recharts chart (hover for tooltips)
  4. Data table โ€” Sortable columns with automatic totals row
  5. 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:

ParameterTypeRequiredDescription
start_datestringYesStart date (YYYY-MM-DD)
end_datestringYesEnd date (YYYY-MM-DD)
site_idintegerNoFilter 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:

ParameterTypeRequiredDescription
start_datestringYesStart date (YYYY-MM-DD)
end_datestringYesEnd date (YYYY-MM-DD)
site_idintegerNoFilter 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 SELECT statements 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:

TableIndexPurpose
rm_lineitemsidx_itemTop Selling Products report (2.6M+ rows)
shipmentsidx_order_idShipping Performance and fulfillment KPI
shipmentsidx_shipping_providerShipping Performance GROUP BY
rm_orderidx_site_dateaddedSite-filtered date range queries (all reports)
rm_addressidx_order_typeGeographic Sales report (1.7M+ rows)
rm_itemsidx_skuSKU lookups in reports and order processing

Architectureโ€‹

Data Flowโ€‹

  1. User selects report, date range, and optional site filter
  2. React app sends POST to /analytics/reports/{slug}/execute
  3. Report_Executor validates parameters (date format, 12-month max range)
  4. SQL query runs against the tasks database with parameterized inputs
  5. cast_column_types() converts string values to proper numeric types (required for Recharts)
  6. 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)