spatie/laravel-analytics
Laravel package to retrieve Google Analytics data with a simple API. Fetch most visited pages, visitors and page views for a given period, returning Laravel Collections. Quick to install, configurable, and works nicely in dashboards and reports.
fetchMostVisitedPages for content performance).fetchVisitorsAndPageViewsByDate) for stakeholders.Adopt if:
fetchTotalVisitorsAndPageViews).Look Elsewhere if:
"This package lets us tap into Google Analytics data directly within our Laravel backend—no more manual exports or third-party tools. For example, we can automatically track feature adoption (e.g., ‘How many users visited the new checkout flow?’) or identify traffic spikes from marketing campaigns. It’s secure (MIT-licensed, service-account based), scalable (handles large datasets via caching), and integrates seamlessly with our existing stack. The cost? Zero—just a one-time setup for Google API credentials. ROI? Faster, data-driven decisions without engineering overhead."
"Spatie’s laravel-analytics abstracts the complexity of Google’s Data API v1. We get a clean facade (Analytics::fetchVisitorsAndPageViews()) with built-in caching, testing support (Analytics::fake()), and Laravel’s Collections for easy manipulation. It’s lightweight (~50KB), well-documented, and actively maintained. For custom queries, the get() method lets us leverage GA4’s full API schema—no need to rewrite the wheel. Setup is straightforward: drop in a JSON credential file and configure the property ID."
"This gives us programmatic access to GA4 metrics without API rate limits or UI constraints. Need to compare user behavior across regions? fetchTopCountries(). Want to filter events (e.g., ‘Show me all sessions with >3 pageviews’)?
The FilterExpression system handles it. Plus, the package’s caching (configurable) reduces API calls, cutting costs. We can even mock responses in tests—great for CI/CD pipelines."
How can I help you explore Laravel packages today?