PHPackages                             freshbitsweb/laravel-google-analytics-4-measurement-protocol - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. freshbitsweb/laravel-google-analytics-4-measurement-protocol

ActiveLibrary[API Development](/categories/api)

freshbitsweb/laravel-google-analytics-4-measurement-protocol
============================================================

A Laravel package to use Measurement Protocol for Google Analytics 4

3.0.0(1mo ago)20111.0k—9.7%13[1 PRs](https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol/pulls)MITPHPPHP ^7.4|^8.0CI passing

Since Mar 18Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol)[ Packagist](https://packagist.org/packages/freshbitsweb/laravel-google-analytics-4-measurement-protocol)[ Docs](https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol)[ RSS](/packages/freshbitsweb-laravel-google-analytics-4-measurement-protocol/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (10)Versions (8)Used By (0)

[![Plant a Tree](https://camo.githubusercontent.com/8fc259310ca13ed7289b251e1fa09793040c80b15be39e4add104d1da2ce3f8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f636f6c6f723d627269676874677265656e266c6162656c3d506c616e7425323061253230547265652671756572793d2532342e746f74616c2675726c3d68747470732533412532462532467075626c69632e6f66667365742e6561727468253246757365727325324674726565776172652532467472656573)](https://plant.treeware.earth/freshbitsweb/laravel-google-analytics-4-measurement-protocol)

Laravel Google Analytics 4 Measurement Protocol
===============================================

[](#laravel-google-analytics-4-measurement-protocol)

A Laravel package to use [Measurement Protocol for Google Analytics 4](https://developers.google.com/analytics/devguides/collection/protocol/ga4).

Introduction
------------

[](#introduction)

This package allows you to post events to Google Analytics 4 from your Laravel backend.

Supported Laravel versions
--------------------------

[](#supported-laravel-versions)

- Laravel 7.x
- Laravel 8.x
- Laravel 9.x
- Laravel 10.x
- Laravel 11.x
- Laravel 12.x
- Laravel 13.x

Installation
------------

[](#installation)

1. Install the package by running this command in your terminal/cmd:

```
composer require freshbitsweb/laravel-google-analytics-4-measurement-protocol
```

2. Set `MEASUREMENT_ID` and `MEASUREMENT_PROTOCOL_API_SECRET` in your .env file. You can get them from: Google Analytics &gt; Admin &gt; Data Streams &gt; \[Select Site\] &gt; Measurement Protocol API secrets
3. Optional: You can publish the config file by running this command in your terminal/cmd:

```
php artisan vendor:publish --tag=google-analytics-4-measurement-protocol-config
```

4. `client_id` is required to post an event to Google Analytics. This package provides a Blade component which you can put in your layout file after the Google Analytics Code tracking code. It makes a POST request to the backend to store the client id in the session which is later used to post events to Google Analytics 4.

```

```

The other option is to call the `setClientId($clientId)` method on the `GA4` facade everytime before calling the `postEvent()` method.

Usage
-----

[](#usage)

You can simple call `GA4::postEvent($eventData)` from anywhere in your backend to post event to Google Analytics 4. `$eventData` contains the name and params of the event as per this [reference page](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#login). For example:

```
GA4::postEvent([
    'name' => 'login',
    'params' => [
        'method' => 'Google',
    ],
]);
```

`postEvent()` method will return an array with the status of the request.

### Debugging Mode

[](#debugging-mode)

You can also enable [debugging mode](https://developers.google.com/analytics/devguides/collection/protocol/ga4/validating-events) by calling `enableDebugging()` method before calling the `postEvent()` method. Like so - `GA4::enableDebugging()->postEvent($eventData)`. The `postEvent()` method will return the response (array) from Google Analytics request in that case.

Authors
-------

[](#authors)

- [**Gaurav Makhecha**](https://github.com/gauravmak) - *Initial work*

See also the list of [contributors](https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol/graphs/contributors) who participated in this project.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

Treeware
--------

[](#treeware)

You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to our forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees at for our forest here [offset.earth/treeware](https://plant.treeware.earth/freshbitsweb/laravel-google-analytics-4-measurement-protocol)

Read more about Treeware at [treeware.earth](http://treeware.earth)

Special Thanks to
-----------------

[](#special-thanks-to)

- [Laravel](https://laravel.com) Community

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance88

Actively maintained with recent releases

Popularity44

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~365 days

Recently: every ~348 days

Total

6

Last Release

59d ago

Major Versions

1.3.0 → 2.0.02025-02-26

2.0.0 → 3.0.02026-03-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/2628a8e3bd55b2ab1a2b4aaccb5a88d33854348c7a7d99e4f76f49c502692329?d=identicon)[gauravmak](/maintainers/gauravmak)

---

Top Contributors

[![gauravmak](https://avatars.githubusercontent.com/u/11887260?v=4)](https://github.com/gauravmak "gauravmak (18 commits)")[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![jaggy](https://avatars.githubusercontent.com/u/1993075?v=4)](https://github.com/jaggy "jaggy (1 commits)")

---

Tags

freshbitsweblaravel-google-analytics-4-measurement-protocol

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/freshbitsweb-laravel-google-analytics-4-measurement-protocol/health.svg)

```
[![Health](https://phpackages.com/badges/freshbitsweb-laravel-google-analytics-4-measurement-protocol/health.svg)](https://phpackages.com/packages/freshbitsweb-laravel-google-analytics-4-measurement-protocol)
```

###  Alternatives

[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[flat3/lodata

OData v4.01 Producer for Laravel

96320.9k](/packages/flat3-lodata)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[stechstudio/laravel-hubspot

A Laravel SDK for the HubSpot CRM Api

2971.0k](/packages/stechstudio-laravel-hubspot)[njoguamos/laravel-plausible

A laravel package for interacting with plausible analytics api.

208.8k](/packages/njoguamos-laravel-plausible)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
