https://github.com/akki-io/laravel-google-analytics
A Laravel package to retrieve data from Google Analytics 4 using the GA4 Query Explorer
https://github.com/akki-io/laravel-google-analytics
google-analytics google-analytics-4 google-analytics-query-explorer laravel php
Last synced: 3 months ago
JSON representation
A Laravel package to retrieve data from Google Analytics 4 using the GA4 Query Explorer
- Host: GitHub
- URL: https://github.com/akki-io/laravel-google-analytics
- Owner: akki-io
- License: mit
- Created: 2022-02-13T04:35:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-29T15:37:32.000Z (about 1 year ago)
- Last Synced: 2025-04-02T20:05:47.743Z (3 months ago)
- Topics: google-analytics, google-analytics-4, google-analytics-query-explorer, laravel, php
- Language: PHP
- Homepage: https://github.com/akki-io/laravel-google-analytics/wiki
- Size: 11.9 MB
- Stars: 46
- Watchers: 4
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
![]()
# Laravel Google Analytics
[](https://github.com/akki-io/laravel-google-analytics/releases)

[](https://styleci.io/repos/441735142)
[](LICENSE.md)
[](https://packagist.org/packages/akki-io/laravel-google-analytics)A Laravel package to retrieve data from Google Analytics 4 using the GA4 Query Explorer
## TL;DR
Using this package you can easily retrieve data from Google Analytics 4.
Below are some examples.
```php
use AkkiIo\LaravelGoogleAnalytics\Facades\LaravelGoogleAnalytics;
use AkkiIo\LaravelGoogleAnalytics\Period;
use Google\Analytics\Data\V1beta\Filter\StringFilter\MatchType;
use Google\Analytics\Data\V1beta\MetricAggregation;
use Google\Analytics\Data\V1beta\Filter\NumericFilter\Operation;// get the top 20 most viewed pages for last 30 days
LaravelGoogleAnalytics::getMostViewsByPage(Period::days(30), $count = 20);// get the top 20 dates with most users for last 12 months
LaravelGoogleAnalytics::getMostUsersByDate(Period::months(12), $count = 20);// build a query using the `get()` method
LaravelGoogleAnalytics::dateRanges(Period::days(30), Period::days(60))
->metrics('active1DayUsers', 'active7DayUsers')
->dimensions('browser', 'language')
->metricAggregations(MetricAggregation::TOTAL, MetricAggregation::MINIMUM)
->whereDimension('browser', MatchType::CONTAINS, 'firefox')
->whereMetric('active7DayUsers', Operation::GREATER_THAN, 50)
->orderByDimensionDesc('language')
->get();
```Please refer to the [wiki](https://github.com/akki-io/laravel-google-analytics/wiki) for more details.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Akki Khare](https://github.com/akki-io)
- [All Contributors](../../contributors)
- [spatie/laravel-analytics](https://github.com/spatie/laravel-analytics)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.