PHPackages                             levelweb/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. levelweb/laravel-google-analytics-4-measurement-protocol

ActiveLibrary[API Development](/categories/api)

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

A Laravel package to use Measurement Protocol for Google Analytics 4

1.1.0(5y ago)063MITPHPPHP ^7.4|^8.0

Since Jul 3Pushed 5y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (5)Versions (2)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.

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

[](#installation)

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

```
composer require levelweb/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.

5. You can set `user_id` by call `setUserId($userId)` 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

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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

Unknown

Total

1

Last Release

1826d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3645147?v=4)[Artem Kovalev](/maintainers/levelweb)[@levelweb](https://github.com/levelweb)

---

Top Contributors

[![gauravmak](https://avatars.githubusercontent.com/u/11887260?v=4)](https://github.com/gauravmak "gauravmak (8 commits)")[![levelweb](https://avatars.githubusercontent.com/u/3645147?v=4)](https://github.com/levelweb "levelweb (1 commits)")

---

Tags

laravel-google-analytics-4-measurement-protocollevelweb

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M130](/packages/roots-acorn)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

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

OData v4.01 Producer for Laravel

99351.7k](/packages/flat3-lodata)

PHPackages © 2026

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