A Laravel package for retrieving Google Analytics data, including pageviews, visitors, and top pages, with a fluent API.
Spatie Laravel Analytics is a Laravel package that provides a fluent, expressive API for retrieving data from Google Analytics. It allows developers to fetch metrics like pageviews, visitors, top pages, and user demographics directly within their Laravel applications, eliminating the need to manually interact with the Google Analytics Data API.
Laravel developers who need to integrate Google Analytics data into their applications, such as for building admin dashboards, generating reports, or displaying analytics in user-facing features.
It simplifies Google Analytics integration by offering a clean, Laravel-style syntax, built-in caching, and comprehensive testing support, saving developers time and reducing complexity compared to direct API usage.
A Laravel package to retrieve pageviews and other data from Google Analytics
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Methods like fetchVisitorsAndPageViews() with Period classes offer a clean, Laravel-native syntax, eliminating the need for verbose raw API calls as shown in the README examples.
Includes pre-built methods for common data like visitors, page views, top pages, and demographics, covering most dashboard needs without custom queries.
Configurable cache lifetime reduces Google API calls and improves performance, with default settings for 24-hour caching as per the config file.
Provides a fake() method to mock analytics data in tests, enabling reliable testing without hitting live APIs, as detailed in the Testing section.
Explicitly designed for GA4 properties, so it won't work with older Universal Analytics (GA3) setups, forcing upgrades for legacy projects.
Requires manual steps like creating a Google service account, downloading JSON keys, and granting permissions, which adds overhead compared to simpler analytics tools.
The get() method for advanced queries still demands deep knowledge of Google Analytics metrics and dimensions, as evidenced by the verbose FilterExpression examples in the README.