-
Notifications
You must be signed in to change notification settings - Fork 16
[Bug] Admin bar real-time chart data diverges from Live Analytics chart #221
Description
Bug Report
Summary
The admin bar dropdown real-time chart (CSS bars) and the Live Analytics page chart (Chart.js) show different visitor counts for the same 30-minute window. The admin bar chart shows zeros in minutes where visitors had no new page loads, while the Live Analytics chart correctly shows those visitors as still present.
Root Cause
The two charts use fundamentally different SQL queries:
Admin bar chart (admin/index.php:1186-1194) — simple per-hit query:
SELECT FLOOR(dt / 60) * 60 AS minute_bucket,
COUNT(DISTINCT visit_id) AS visitor_count
FROM {table}
WHERE dt >= {start} AND dt <= {end} AND visit_id > 0
GROUP BY minute_bucket- Only counts visitors in minutes where they generated a page hit (
dt) - Ignores
dt_outentirely - A visitor idle between page loads disappears from intermediate minutes
Live Analytics chart (src/Reports/Types/Analytics/LiveAnalyticsReport.php:324-360) — session-spanning query:
-- Uses first_minute to last_minute span with dt_out
-- LEFT JOIN ensures all 30 minute slots exist
-- Visitor counted as present across ALL minutes of their session- Uses
dt_outto determine session end time - Counts a visitor as present in every minute from first hit to last activity
- Correctly represents continuous presence
Reproduction Steps
- Have real visitor traffic on a WordPress site with wp-slimstat + wp-slimstat-pro active
- Open the wp-slimstat Live Analytics admin page (shows gray bar chart)
- Click the SlimStat icon in the WordPress admin bar (opens dark dropdown with red CSS bar chart)
- Compare the two 30-minute charts
Expected: Both charts show identical visitor counts per minute
Actual: Admin bar chart shows zeros in minutes where visitors had no new page loads but were still actively browsing (tracked via dt_out)
Suggested Fix
Replace the inline SQL in admin/index.php:1184-1204 with a call to LiveAnalyticsReport::get_users_chart_data(), or replicate its session-spanning SQL logic. This ensures both charts use identical data sources.
Code References
| File | Lines | Description |
|---|---|---|
admin/index.php |
1184-1204 | Admin bar chart: simple dt-only query |
src/Reports/Types/Analytics/LiveAnalyticsReport.php |
280-393 | Live Analytics chart: session-spanning query with dt_out |
admin/assets/css/admin-bar-modal.css |
222-252 | CSS chart bar styling |
Severity
Medium — visual data inconsistency between two views of the same metric; does not affect data collection or accuracy of the Live Analytics report itself.