spatie/laravel-analytics
Fetch Google Analytics data in Laravel via a simple facade. Query visitors, pageviews, most visited pages and more for a given period, returning Collections. Easy install, configurable credentials, and ready-to-use methods for common reports.
fetchVisitorsAndPageViews for cohort analysis).fetchTopReferrers) or geographies (fetchTopCountries) to optimize campaigns.cache_lifetime_in_minutes) to reduce API costs and latency.FilterExpression supports.offset/maxResults params.For Executives: "This package lets us tap into Google Analytics 4 data directly from our Laravel backend—no more manual exports or third-party tools. We can automate reports (e.g., weekly traffic trends), power personalized user experiences (e.g., ‘Top pages for returning users’), and reduce costs by caching API responses. It’s a 3-month time-saver compared to building this in-house, with minimal ongoing maintenance. For ~$0 upfront (MIT license), we get enterprise-grade analytics integration."
For Engineers:
*"Spatie’s package abstracts the Google Analytics Data API into Laravel-friendly methods (e.g., fetchMostVisitedPages() returns a Collection). Key benefits:
get() method with GA4’s API schema.Analytics::fake())..env) and never committed to Git.
Tradeoff: Limited to GA4; if you hit scale limits, we can extend it with custom logic."*For Data Teams: *"This gives product teams self-service access to GA4 data without relying on us. For example:
fetchTopReferrers) to optimize ad spend.eventName=‘checkout_start’).fetchMostVisitedPages.
We’ll document common queries in our internal wiki to standardize usage."How can I help you explore Laravel packages today?