redaelfillali / google-analytics-events
There is no license information available for the latest version (1.0.3) of this package.
Send events to Google Analytics (GA4) via Measurement Protocol
1.0.3
2025-06-25 10:58 UTC
Requires
- php: ^8.1
- illuminate/support: ^9 || ^10 || ^11 || ^12
README
A lightweight Laravel package that sends events to Google Analytics 4 (GA4) using the Measurement Protocol.
Track frontend or backend interactions (form submissions, purchases, clicks, etc.) directly from your Laravel app.
๐ Features
- โ Simple API for sending custom GA4 events
- ๐ Uses secure Measurement Protocol (
measurement_id
&api_secret
) - ๐ช Automatically extracts
client_id
from_ga
cookie or generates fallback UUID - โ๏ธ Configurable via
.env
orconfig/google-analytics-events.php
๐ฆ Installation
1. Require the package
If installed locally (recommended for development):
composer require redaelfillali/google-analytics-events
Then install:
composer require redaelfillali/google-analytics-events
2. Publish the config
php artisan vendor:publish --tag=config
3. Add your credentials to .env
GA_MEASUREMENT_ID=G-XXXXXXXXXX GA_API_SECRET=your_secret_here
โ๏ธ Configuration
config/google-analytics-events.php
:
return [ 'measurement_id' => env('GA_MEASUREMENT_ID', 'your-id'), 'api_secret' => env('GA_API_SECRET', 'your-secret'), ];
๐ก Usage
Send an event manually
use Redaelfillali\GoogleAnalyticsEvents\GoogleAnalyticsService; app(GoogleAnalyticsService::class)->sendEvent('form_submission', [ 'form_id' => 'contact', 'submitted_at' => now()->toIso8601String(), ]);
Optional: Provide a custom client_id
app(GoogleAnalyticsService::class)->sendEvent('purchase', [ 'value' => 49.99, ], '123456789.987654321');
๐งช Debug
Once events are sent correctly, visit your GA4 property:
Google Analytics โ Admin โ DebugView
To see real-time incoming events.
๐ Package Structure
redaelfillali/google-analytics-events/
โโโ src/
โ โโโ GoogleAnalyticsService.php
โ โโโ GoogleAnalyticsEventsServiceProvider.php
โโโ config/
โ โโโ google-analytics-events.php
โโโ composer.json
โโโ README.md
โ Requirements
- PHP 8.1+
- Laravel 9, 10, or 11
- Google Analytics 4 property
- Measurement Protocol API secret
๐ License
MIT License
๐ค Credits
Developed by Reda El Fillali