Analytics

Analytics Overview

Kitbix Commerce ships with a zero-config analytics dashboard. It pulls directly from the kitbix_commerce_orders and kitbix_commerce_products tables via AnalyticsController::index() and renders the React SPA shown below.

Range selector

  • Presets: Last 24 Hours (24h), 7 Days (7d default), 30 Days (1m), 6 Months (6m), 12 Months (1y), All Time (all), Custom Range (custom).
  • The dropdown calls /kitbix-commerce/v1/admin/analytics?range=.... Custom range sends start_date and end_date ISO strings.
  • Ranges are timezone-aware using wp_timezone(); daily buckets reset at 00:00 in the site timezone.
  • When presets change, Redux state in analyticsSlice records the new filters so future sessions remember the choice.

Top-line KPIs

Card Data source Notes
Products Added COUNT(*) of kitbix_commerce_products created within the range. Useful for monitoring catalog velocity after launches.
Orders Created COUNT(*) of orders created in the range. Feeds the Orders KPI card and sparkline.
Revenue SUM(total) from orders. Subtotal, tax, and shipping are also returned for reporting.
New Customers First order date per unique customer email. Only counts the earliest order per email to avoid duplicates.

Charts & widgets

  1. Sparklines: Each KPI card includes a sparkline built from the timeline buckets (buildKpis()).
  2. Orders chart: Bar chart showing timeline.orders values per bucket.
  3. Revenue trend: Line graph using timeline.revenue.
  4. New customers chart: Column chart using timeline.new_customers.
  5. Order status ring: Breakdown of pending, processing, completed, cancelled counts for the selected range.
  6. Revenue overview panel: Shows total net revenue, orders, and customers plus a textual description of the active range.
Screenshot: Analytics dashboard (Last 7 Days) showing KPI tiles, order status donut, revenue trend, orders/new customers bar charts, and revenue overview panel.

Replace with your latest capture when publishing release notes.

REST/Redux overview

  • AnalyticsController::index() handles /admin/analytics (GET). It validates ranges, builds SQL buckets, and returns { range, totals, series, kpis }.
  • analyticsSlice.js stores the payload. fetchAnalytics thunk wraps the REST request and handles loading states + errors.
  • useAnalyticsFeature() provides helpers for preset changes and custom range submissions, bubbling toast errors if requests fail.
  • All data is computed server-side; no third-party tracking or external services are required.

Tips & best practices

Tip: Clear caching plugins for /wp-json/kitbix-commerce/v1/admin/analytics if numbers look stale—responses are personalized and should never be cached publicly.
Tip: Bookmark custom ranges (e.g., seasonal campaigns) by copying the query parameters from the browser bar.
Tip: Use the exported JSON to feed external dashboards if you need more advanced visualization.

Common pitfalls

  • Missing capabilities: the route requires manage_options. Ensure your wp-admin user has the appropriate role.
  • Empty charts on fresh installs: you need orders/products within the selected range to populate the data.
  • Using server time instead of store time: always confirm Settings → General → Timezone is set correctly so buckets align with real business hours.
Reminder: Analytics uses direct SQL aggregations. Avoid editing Kitbix tables with unprepared statements, or you risk corrupting the data driving these reports.