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

This package is auto-updated.

Last update: 2025-06-25 11:03:42 UTC


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 or config/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