WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / WPResidence / WPEstate CRM / WPResidence CRM Stats — Developer Reference

WPResidence CRM Stats — Developer Reference

48 views 0

Developer documentation for the Stats module of the WPResidence real estate CRM. Covers the stats-functions API, Chart.js integration, deferred loading, and scope filtering.

Files

  • libs/stats-functions.php — aggregate queries and counters.
  • page-templates/wpestate-crm-dashboard_stats.php — dashboard template.

Server-Side KPI Functions

Function Returns
wpestate_crm_get_lead_stats() total, by_status, by_source, by_type
wpestate_crm_get_enquiry_stats() Counts keyed by status
wpestate_crm_get_deal_stats() total, value_sum, by_stage, avg_value, won_count, lost_count
wpestate_crm_get_tasks_by_priority() Task counts per priority
wpestate_crm_stats_tasks_overdue() int — overdue task count

KPI Tiles (Server-Side Render)

The 5 tiles render synchronously in the template using the stats functions above plus helper date math:

  • first_day_of_month / first_day_of_prev_month — for “this month vs. previous” deltas.
  • monday_this_week / monday_last_week — for weekly activity delta.
  • Overdue tasks: conditional red CSS class applied when count > 0.

Charts (Deferred AJAX Render)

All six charts load after first paint via an AJAX call, to keep the page fast on sites with many records:

Action Purpose
wpestate_crm_get_stats Returns JSON payload with labels and datasets for all six charts.

Chart.js 4.4.7 is enqueued conditionally on the Stats page only (check in wpestate-crm.php around lines 59/90). The chart render logic reads wpestate_crm_vars.nonces for the request.

The Six Charts

  1. Contacts by Lifecycle Stage — doughnut.
  2. Deals by Pipeline Stage — bar with count + value.
  3. New Contacts over Time — line, 30-day rolling.
  4. Activity Volume by Type — bar.
  5. Deal Win/Loss Ratio — pie.
  6. Task Completion Rate — bar (% completed vs. total).

Scope Filtering

Every stats function respects wpestate_crm_get_ownership_where(). Admins receive unfiltered queries; agents get WHERE clauses scoped to their user_id and assigned agent ID.

Capabilities

The template is gated by wpestate_dashboard_header_permissions() (login required) and individual functions also respect wpestate_crm_user_can(‘activities’, ‘view’) where applicable.

Customizing Charts

  • To add a metric, extend libs/stats-functions.php from a child plugin (do not edit the CRM plugin directly).
  • Inject your new dataset into the wpestate_crm_get_stats AJAX response with a priority-20 filter on the response JSON.
  • Add a <canvas> element in a child template override of wpestate-crm-dashboard_stats.php and wire it to a Chart.js constructor on DOM ready.

Performance Notes

  • Pipeline summary uses a single GROUP BY deal_stage query.
  • Contacts-by-lifecycle uses a single GROUP BY lifecycle_stage query.
  • Activity volume uses a GROUP BY type with a WHERE created_at >= filter (last 30 days by default).
  • For sites with 100K+ rows, consider adding materialized summary tables and a daily cron to refresh them.
WPResidence / WPEstate CRM

Related Articles

  • WPResidence CRM Security Model — Developer Reference
  • CRM Security and Data Privacy
  • WPResidence CRM Installation and Updates — Developer Reference
  • Installing and Updating the WPResidence CRM

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language Third Party Plugins
  • 6Other Third party Plugins
  • 19Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 36Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 6Translations & Languages
  • 16WPBakery Shortcodes
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio
  • 50WPResidence Translate Plugin

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API