jeffersongoncalves/laravel-metrics-ga4
Laravel package for pulling Google Analytics 4 metrics into your app, making it easy to query GA4 data and surface reports or dashboard stats without writing boilerplate API code.
visitors, visits, pageviews, bounce_rate, visit_duration) onto GA4's metric names. That is exactly the undifferentiated code a team would otherwise hand-roll and maintain across GA4 API version changes — a strong argument for adopting rather than building.timeseries and breakdown for trend charts, pages/sources/countries/browsers/devices for standard report tabs, realtimeVisitors for a live-now widget, runReport as the escape hatch for anything custom. If the roadmap includes an internal dashboard, admin reporting, or "audience" panels, this package shortens the estimate to roughly UI work plus query design.GA4_PROPERTY_ID and GA4_SERVICE_ACCOUNT_JSON and is persisted through spatie/laravel-settings, which reads as one property per application instance. For a multi-tenant SaaS where each customer connects their own GA4 property, plan for per-tenant settings, credential isolation, and a connection/verification flow — that is net-new work this release does not cover.RateLimitException and AuthenticationException are separately catchable, which makes quota-aware backoff, alerting, and graceful degradation (stale cache vs. error state) explicit product decisions rather than incidental code paths.spatie/laravel-settings adds a dependency and a key-rotation/secret-management obligation. Worth confirming with security before it becomes a launch blocker.Adopt when most of the following hold:
spatie/laravel-settings is acceptable as a dependency.Look elsewhere — or budget for extra build — when:
For executives: A small, focused integration that lets our Laravel application pull Google Analytics 4 numbers directly — traffic trends, top pages, acquisition sources, geography, device and browser splits, and a live-visitor count — without us building or maintaining the authentication and API plumbing ourselves. It replaces custom code with a supported dependency at 1.0.0, which means we get the analytics capability faster and carry less long-term maintenance risk. Cost is effectively our engineering time; the GA4 Data API itself is free, though subject to Google's rate limits.
For engineering: ~10 lines of surface area: a GA4 facade with report-shaped methods, a product-metric vocabulary mapped to GA4 metrics, runReport as the raw escape hatch, and three typed exceptions including a distinct RateLimitException for quota handling. Auth is self-contained — JWT signed locally with OpenSSL, access tokens cached, service-account key encrypted at rest via spatie/laravel-settings and seeded from GA4_PROPERTY_ID / GA4_SERVICE_ACCOUNT_JSON. Constraints to design around: one property per instance (multi-tenancy is our work), no report caching or scheduling (ours to add), PHP 8.2+ and Laravel 11–13 only. Treat the service-account key as a production secret with a rotation plan from day one.
How can I help you explore Laravel packages today?