Analytics dashboard
_chris
Full Stack Developer · 2024-01-03
Hi all, I'm in the process of creating an admin dashboard which will be used to monitor several other applications remotely. The webapp will include an analytics page which shows the analytics of the other applications it is monitoring. Before writing my own analytics code from scratch I'm wondering whether there are any packages which do this? I've looked at Spatie's analytics
Building a multi-application analytics dashboard is a classic integration problem: you want per-application visibility without forcing each app to report to a third-party hosted service. Open-source packages like Spatie Laravel Analytics let you pull Google Analytics data into your Laravel models, while Prometheus exposes custom metrics endpoints for real-time ingestion. Choosing between them depends on whether you need raw event data, trend summaries, or alert-driven thresholds. This post surveys practical options, their tradeoffs, and how to extend a dashboard with financial data from tools like FINANCE - Self-hosted personal finance tracking web app or PDF reporting integrations discussed in Issue with Embedding Custom Fonts in PDF using Spatie Browsershot in Laravel.
Spatie Laravel Analytics
Spatie's package is a thin wrapper around the Google Analytics Reporting API. After authenticating with a service account, you can fetch visitors, pageviews, top referrers, and most visited pages for arbitrary periods. Because it returns Eloquent-friendly collections, you can cache results in your database and chart them without additional transformation. The main caveat is dependence on GA's sampling thresholds: when a property exceeds ten million hits per month, aggregation latency rises and some dimensions become unavailable. For an internal admin dashboard, this is acceptable.
Prometheus and Grafana
If you need metrics closer to real-time, Prometheus scrapes HTTP /metrics endpoints exposed by each monitored application. Laravel packages such as spatie/laravel-prometheus simplify instrumenting routes, queue throughput, and database query counts. Pairing Prometheus with Grafana gives you dozens of prebuilt dashboards and alert rules that respond when error rates spike or memory usage climbs. The downside is operational overhead: you must run a time-series database, manage retention, and ensure each target app exposes standardized metric labels.
Building a Unified Data Model
Treat each external application as a data source rather than a database to join directly. Normalize application identifiers in a monitored_apps table, store daily snapshots in a analytics_snapshots table, and pre-aggregate weekly and monthly trends. This design makes it easy to add new apps without migrating schema, and it keeps reporting queries fast. Use database indexes on composite keys of app_id and date, and prune rows older than your retention window with a scheduled command.
Frontend Presentation
Charts should be interactive: allow date range selection, allow administrators to focus on one monitored app while blurring others, and export charts as PNG or PDF. For PDF generation, you might rely on the same Spatie Browsershot integration mentioned earlier if you need formatted reports. The key is to keep rendering logic on the frontend where interactivity is natural and push expensive aggregation to backend jobs or database materialized views.
Alerting and Maintenance
A dashboard is only useful if it tells you when something is wrong. Configure alerts for error rate increases, response time regressions, or quota exhaustion in upstream APIs. Deliver alerts through Slack, email, or PagerDuty. Periodically audit which applications are still monitored and archive or delete data from decommissioned apps to prevent your analytics database from growing without bound.
Conclusion
Rather than inventing analytics primitives, start with Spatie's or Prometheus's well-tested abstractions and extend them only where your monitoring requirements diverge. A unified schema with daily snapshots gives you flexibility, while frontend charting and alerting turns raw numbers into actionable operational awareness.
Related Posts
- FINANCE - Self-hosted personal finance tracking web app
- Issue with Embedding Custom Fonts in PDF using Spatie Browsershot in Laravel
- Analytics dashboard
These related posts cover self-hosted finance apps, PDF capabilities, and dashboard design patterns that complement multi-app monitoring.
Visualization Best Practices
Dashboards should answer questions, not just display data. Start with user personas: what does a product manager need versus a DevOps engineer? Use appropriate chart types: line charts for trends, bar charts for comparisons, gauges for SLA compliance. Avoid overcrowding; group related metrics into widgets with clear titles and units. Provide time range selectors and export options.
Performance matters: aggregate queries should use pre-computed rollups, not raw event tables. Limit default time ranges to seven or thirty days. For real-time dashboards, use websockets or short polling to push updates. Laravel Echo with Redis broadcasting is a proven approach.
Security Hardening
Role-based access control (RBAC) determines who sees which widgets. Enforce authorization at the API layer, not just the UI. Log all dashboard access with user ID, filters applied, and export actions. Rate-limit the dashboard API to prevent abuse. If embedding third-party charts or iframes, apply Content-Security-Policy headers to restrict script sources.
Related: FINANCE - Self-hosted personal finance tracking web app and Issue with Embedding Custom Fonts in PDF using Spatie Browsershot.
Choosing Time-Series Storage
For time-series data like request counts, job durations, or revenue per hour, a relational database works up to a point. Beyond that, InfluxDB, TimescaleDB, or ClickHouse offer superior compression and query speed for rollups. Laravel doesn't have native support for these databases, but you can use raw queries or packages like prettytown/laravel-clickhouse. Aggregate data in a separate database to avoid impacting transactional workloads.
Privacy and Data Retention
Dashboard data often includes PII via user identifiers or IP addresses. Anonymize or aggregate data before storage when possible. Set retention policies aligned with your analytics needs: fine granularity for recent data, coarser rollups for historical data. Implement GDPR-compliant deletion endpoints so users can request removal of their metrics.
See FINANCE - Self-hosted personal finance tracking web app for self-hosted analytics alternatives, Laravel Octane benchmark comparing Swoole, OpenSwoole, RoadRunner, FrankenPHP for runtime performance, and Yajra datatables questions for rendering large datasets.
Laravel Analytics Packages Compared
Spatie's Laravel Analytics package is a solid starting point for Google Analytics integration, but it only covers GA4. For multi-application monitoring, you might need additional sources: Mixpanel for product analytics, Sentry for error tracking, or Prometheus/Grafana for infrastructure metrics. Packages like Laravel Pulse (official Laravel) provide application-level insights out of the box, while Horizon gives deep visibility into queues.
For a unified dashboard, consider building an API layer that normalizes data from different sources. Each application sends metrics to your dashboard backend, which stores them in a time-series format. InfluxDB or TimescaleDB are excellent choices for this. The frontend can then use libraries like Chart.js, ApexCharts, or D3.js to render the data. If you need a self-hosted analytics platform, alternatives like Plausible or Umami exist, but for monitoring other applications, a custom aggregation layer often works best.
Data Aggregation Strategies
Polling multiple applications for raw data is inefficient. Instead, push metrics from each application to a central store using webhooks, statsd, or a message queue. Laravel's event system makes this straightforward: each monitored application dispatches events like OrderCompleted or JobProcessed, and your dashboard listens and aggregates. This decouples the applications from the dashboard and scales better.
For historical data, pre-compute aggregates using scheduled commands. Materialized views in PostgreSQL or Laravel cache tags can store hourly/daily rollups. This ensures dashboard loads remain fast even when querying months of data.
Security and Multi-Tenancy
If the dashboard monitors client applications, you need strong multi-tenancy. Each client should only see their own data. Use Laravel's built-in tenancy features or packages like Stancl/tenancy. API tokens should be scoped per client, and all queries must filter by tenant. Audit logging is also essential to track who accessed what metrics and when.