Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Analytics Data

Analytics Data Laravel Package

google/analytics-data

Idiomatic PHP client for the Google Analytics Data API (GA4). Query reports, audience exports, and more via REST or gRPC. Install with Composer (google/analytics-data) and authenticate using Google Cloud credentials. Part of Google Cloud PHP (beta).

View on GitHub
Deep Wiki
Context7

google/analytics-data is the idiomatic PHP client for the Google Analytics Data API (GA4). It’s part of Google Cloud PHP and provides a streamlined way to query analytics reports and programmatically access GA4 data using familiar, strongly-typed request/response objects.

Use it to build reporting pipelines, dashboards, or backend integrations with secure Google authentication and flexible transport options.

  • Composer-first installation (composer require google/analytics-data)
  • Supports REST (HTTP/1.1) and gRPC transports (gRPC enables streaming)
  • Typed clients like BetaAnalyticsDataClient with request builders
  • Robust error handling via ApiException
  • Linked API docs, plus authentication and debugging guides
Frequently asked questions about Analytics Data
How do I install and authenticate the Google Analytics Data API client in Laravel?
Install via Composer with `composer require google/analytics-data`. Authenticate using service account credentials (JSON key file) or OAuth2 tokens, stored securely in Laravel’s `config/services.php` or environment variables. The client supports both REST and gRPC, with gRPC requiring additional PHP extensions like `grpc`.
Does this package support Laravel’s service container for dependency injection?
Yes. Bind the `BetaAnalyticsDataClient` as a singleton in `AppServiceProvider` with pre-configured credentials. Example: `$this->app->bind(BetaAnalyticsDataClient::class, fn() => new BetaAnalyticsDataClient(['credentials' => storage_path('app/google_credentials.json')]))`.
Can I use this for real-time analytics in Laravel livewire or dashboard widgets?
Absolutely. The REST endpoint supports low-latency queries, ideal for real-time dashboards. Cache responses with Laravel’s `Cache::remember` to reduce API calls. For high-frequency updates, consider gRPC’s streaming capabilities.
How do I handle large audience exports or batch processing in Laravel?
Use async tasks (e.g., `RunReportTask`) dispatched via Laravel Queues. For large exports, implement custom pagination or streaming handlers. Example: `RunReportTask::dispatch($request)->onQueue('analytics')`.
What Laravel versions and PHP requirements does this package support?
Requires PHP 8.1+ (for gRPC/protobuf support) and works with Laravel 9+. Tested with Laravel’s latest LTS. Check the [Google Cloud PHP docs](https://cloud.google.com/php/docs) for dependency updates.
How do I handle API errors or rate limits in production?
Catch `ApiException` and map it to Laravel’s error handler (e.g., `render()`). Check quotas with `GetPropertyQuotasSnapshot` before heavy operations. Log errors via `Log::error()` or integrate with Sentry for monitoring.
Is there a Laravel facade or helper to simplify API calls?
No built-in facade, but you can create one (e.g., `Analytics::runReport()`) in a service class. Example: `class Analytics { public static function runReport($request) { return app(BetaAnalyticsDataClient::class)->runReport($request); }}`.
Can I use this for user-specific analytics (OAuth2) instead of service accounts?
Yes. Configure OAuth2 credentials in `config/services.php` and use the client’s OAuth2 flow. Store tokens securely (e.g., encrypted in the database) and refresh them via Laravel’s caching layer.
What are the risks of using a beta API in production?
Beta APIs may have breaking changes, but Google provides clear deprecation policies. Monitor the [Google Analytics Data API release notes](https://developers.google.com/analytics/devguides/reporting/data/v1/release-notes) and use semantic versioning (e.g., `v1beta` → `v1`).
Are there alternatives to this package for Laravel analytics?
For GA4, this is the official Google client. Alternatives include third-party wrappers (e.g., `spatie/laravel-analytics`) or direct HTTP clients (e.g., Guzzle), but they lack gRPC support or official Google backing. This package offers the most features and stability.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport