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 admin user_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

  1. Navigate to /admin (admin users only)
  2. 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 metrics
  • Reporting::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

  1. Run initial backfill: rails reporting:backfill_all
  2. Check refresh runs table for errors
  3. Verify user data exists in source tables

Refresh Jobs Failing

  1. Check reporting_refresh_runs table for error messages
  2. Verify database indexes are present
  3. Check job queue status

Access Issues

  1. Ensure user has admin user_type
  2. Check authentication is working
  3. 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

This site uses Just the Docs, a documentation theme for Jekyll.