nicdev / ga-reporter
A PHP client for the Google Analytics API
dev-main
2025-07-08 01:04 UTC
Requires
- php: ^7.4|^8.0
- google/apiclient: ^2.12
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- laravel/pint: ^1.23
- phpunit/phpunit: ^9.0
- spatie/ray: ^1.41
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2025-07-08 01:05:51 UTC
README
A modern PHP client for the Google Analytics API
Installation
composer require nicdev/ga-reporter
Setup
- Create a Google Cloud Project
- Enable the Google Analytics API
- Create credentials (OAuth 2.0 or Service Account)
- Download your credentials JSON file
Usage
// Initialize with credentials $client = new \Nicdev\GoogleAnalytics\Client([ 'credentials_path' => '/path/to/credentials.json' ]); // Create Reporter instance $reporter = new \Nicdev\GoogleAnalytics\Reporter($client); // Get page views for last 30 days $startDate = new DateTime('30 days ago'); $endDate = new DateTime(); $pageViews = $reporter->getPageViews('VIEW_ID', $startDate, $endDate); // Get real-time users $activeUsers = $reporter->getRealTimeUsers('VIEW_ID');
Features
- Universal Analytics (UA) and GA4 support
- Real-time reporting
- Audience metrics
- Event tracking
- Custom dimensions and metrics
- Automatic token refresh
- PSR-4 compliant
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.