Admin Dashboard
Analytics dashboard for ActiveAdmin displaying user metrics with time range filters and background refresh capability.
Features
- Time Range Filters: Day, Week, Month, 6 Months, Year, All
- Metrics Display: Signups, Active Users, Reviews with totals and charts
- Manual Refresh: One-click data refresh with background job processing
- Audit Trail: Recent refresh runs table with status and timing
- Admin Only: Restricted to users with
adminuser_type
Setup
1. Run Migrations
rails db:migrate
2. Initial Data Load
# Backfill historical data
rails reporting:backfill_all
# Or refresh last 13 months
rails reporting:refresh_metrics
3. Schedule Regular Updates (Optional)
Add to config/schedule.yml:
:schedule:
reporting_metrics:
cron: "0 2 * * *" # Daily at 2 AM
class: "Reporting::UserMetricsRefreshJob"
queue: low
args: []
Usage
Access Dashboard
- Navigate to
/admin(admin users only) - Click “Dashboard” in the navigation
Refresh Data
- Manual: Click “Refresh now” button
- Command Line:
rails reporting:refresh_metrics - With Date Range:
FROM=2024-01-01 TO=2024-12-31 rails reporting:refresh_metrics
View Metrics
- Use time range buttons to filter data
- View totals in the “Totals” panel
- Check charts for trends over time
- Monitor refresh status in “Recent Refresh Runs” table
Architecture
Models
Reporting::UserMetricsDaily- Daily aggregated metricsReporting::RefreshRun- Audit trail for refresh jobs
Services
Reporting::UserMetricsRefresher- Core aggregation logic with error handling
Jobs
Reporting::UserMetricsRefreshJob- Background refresh processing
Database Tables
reporting_user_metrics_dailies- Daily metrics (day as primary key)reporting_refresh_runs- Job audit trail- Indexes on
users.created_at,users.last_sign_in_at,reviews.created_at
Performance
- Query Speed: Pre-aggregated data loads in milliseconds
- Refresh Speed: ~1 second per year of data
- Storage: Minimal (1 row per day)
- Scalability: Linear with date range, supports incremental updates
Troubleshooting
No Data Showing
- Run initial backfill:
rails reporting:backfill_all - Check refresh runs table for errors
- Verify user data exists in source tables
Refresh Jobs Failing
- Check
reporting_refresh_runstable for error messages - Verify database indexes are present
- Check job queue status
Access Issues
- Ensure user has
adminuser_type - Check authentication is working
- Verify ActiveAdmin configuration
Rake Tasks
# Refresh with optional date range
rails reporting:refresh_metrics [FROM=date] [TO=date]
# Backfill all historical data
rails reporting:backfill_all
Testing
# Run all dashboard tests
bin/rails test test/models/reporting/ test/services/reporting/ test/jobs/reporting/ test/controllers/admin/dashboard_controller_test.rb