3.8 KiB
Analytics Dashboard Fix - Summary
Problem
The admin dashboard was showing empty analytics data (zeros and dashes) even though the /admin/analytika page displayed correct Umami analytics data.
Root Cause
The system has two separate analytics systems:
- Umami Analytics - External analytics service (working correctly, used by
/admin/analytika) - Internal Analytics -
visitor_eventsdatabase table (empty, was being used by dashboard)
The dashboard was trying to fetch data from the internal visitor_events table, which was empty because tracking events weren't being recorded there.
Solution
Modified the analytics controller to fetch data from Umami instead of the internal database:
Changes Made
1. Updated analytics_controller.go
- Added Umami service integration to
AnalyticsController - Added
resolveWebsiteID()method to get the Umami website ID - Modified endpoints to fetch from Umami first, with fallback to internal DB:
GetAnalytics()- Now returns proper users, events, and articles statsGetAnalyticsOverview()- Fetches page views and visitors from UmamiGetTopPages()- Gets top pages from Umami URL metrics
Affected Dashboard Stats
The following dashboard statistics now display correctly:
✅ Uživatelé (admin) - Total users and new this week (from database)
✅ Události - Total events and upcoming events (from database)
✅ Články - Total articles and published count (from database)
✅ Zobrazení stránek - Total page views from Umami
✅ Unikátní návštěvníci - Unique visitors from Umami
✅ Zobrazení (týden) - Page views last 7 days from Umami
✅ Nejnavštěvovanější stránky - Top pages from Umami
✅ Nejčastější interakce - Will show data when interaction events are tracked
How It Works
- Umami Integration: The controller now queries Umami's API for web analytics
- Time Ranges:
- Overall stats: Last 365 days
- Today's stats: Current day (00:00 - now)
- Week stats: Last 7 days
- Fallback: If Umami is unavailable, falls back to internal
visitor_eventstable
Testing
-
Restart the backend:
# Stop the current server # Then start it again go run main.go # Or use your deployment method -
Check the dashboard:
- Go to
/adminin your browser - You should now see analytics data populated from Umami
- Go to
-
Verify Umami is configured:
- Check
.envfile has:UMAMI_URL=https://your-umami-instance.com UMAMI_USERNAME=admin UMAMI_PASSWORD=your-password UMAMI_WEBSITE_ID=your-website-id
- Check
Expected Results
After restarting the backend, the dashboard should display:
- Users count: Number of admin users in the system
- Events count: Number of events (matches, trainings, etc.)
- Articles count: Number of articles and published articles
- Page views: Real visitor statistics from Umami
- Top pages table: Most visited pages from Umami
- Visitor chart (if GetVisitors is updated): Daily visitor trends
Notes
- The
GetVisitorsfunction (used by VisitorsWidget) still uses internal DB. If you need this to work with Umami, you'll need to fetch time-series data from Umami's pageviews endpoint - Umami must be properly configured and accessible for the stats to appear
- If Umami is not configured, the dashboard will fallback to internal analytics (which may be empty)
Next Steps (Optional)
If you want the visitor chart widget to also use Umami data:
- Update
GetVisitors()to fetch time-series data from Umami - Use Umami's
/api/websites/{websiteId}/pageviewsendpoint - Group the data by day and format it for the chart
Files Modified
internal/controllers/analytics_controller.go- Added Umami integration for dashboard stats