PHPackages                             ronald2wing/laravel-ga4 - 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. [Templating &amp; Views](/categories/templating)
4. /
5. ronald2wing/laravel-ga4

ActiveLibrary[Templating &amp; Views](/categories/templating)

ronald2wing/laravel-ga4
=======================

Drop-in Google Analytics 4 (gtag) snippet for Laravel Blade.

1.0.0(2mo ago)0150MITPHPPHP ^8.3CI passing

Since Apr 27Pushed 2mo agoCompare

[ Source](https://github.com/ronald2wing/Laravel-GA4)[ Packagist](https://packagist.org/packages/ronald2wing/laravel-ga4)[ Docs](https://github.com/ronald2wing/laravel-ga4)[ GitHub Sponsors](https://github.com/sponsors/ronald2wing)[ Fund](https://www.buymeacoffee.com/ronald2wing)[ RSS](/packages/ronald2wing-laravel-ga4/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Laravel GA4
===========

[](#laravel-ga4)

[![Latest Version](https://camo.githubusercontent.com/891323ccd990cb25581692d3e8fe1233c8ad1636c37a69b2a30a910796e9464a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6e616c643277696e672f6c61726176656c2d6761342e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ronald2wing/laravel-ga4)[![License](https://camo.githubusercontent.com/fa6697c2138647f21c69511fada60ad295036b23d6023ce79b23d4a416b2c54e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726f6e616c643277696e672f6c61726176656c2d6761342e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHPStan](https://camo.githubusercontent.com/4470f8df20a6d13b9eac69d9a1f3abcd72eb30f8436f5355e69f06cb6bd970ab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/ronald2wing/laravel-ga4)[![CI](https://camo.githubusercontent.com/1db7f36f05fff697a515fc7b1232d9d8862dee38cff18c07515f64c0d4577aa2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f6e616c643277696e672f6c61726176656c2d6761342f7068702e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/ronald2wing/laravel-ga4/actions)

A small Laravel package that drops the Google Analytics 4 tracking snippet into your Blade layout. One directive, one env var, no ceremony.

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 10.x, 11.x, 12.x, or 13.x

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

[](#installation)

```
composer require ronald2wing/laravel-ga4
```

The service provider is auto-registered.

Configuration
-------------

[](#configuration)

Add your measurement ID to `.env`:

```
GA4_MEASUREMENT_ID=G-XXXXXXXXXX
```

Optionally publish the config:

```
php artisan vendor:publish --tag=ga4-config
```

### gtag parameters

[](#gtag-parameters)

Forwarded as the third argument to `gtag('config', id, parameters)`:

```
// config/ga4.php
'parameters' => [
    'send_page_view' => true,
    'anonymize_ip'   => true,
],
```

Usage
-----

[](#usage)

Place `@ga4` in your layout's ``:

```

    {{ config('app.name') }}
    @ga4

    @yield('content')

```

The directive renders the tracking snippet, or nothing at all if no measurement ID is configured — so it's safe to drop into any layout unconditionally.

### Conditional rendering

[](#conditional-rendering)

`Ga4Tag::isEnabled()` lets you guard analytics-aware UI:

```
@use(Ronald2Wing\LaravelGa4\Ga4Tag)

@if(app(Ga4Tag::class)->isEnabled())
    Sign Up
@endif
```

`Ga4Tag` implements `Htmlable` and `Stringable`, so `{{ $tag }}` and `{!! $tag !!}` both work if you'd rather inject the instance directly.

Composer scripts
----------------

[](#composer-scripts)

```
composer test          # run tests
composer check         # lint + test
composer lint          # Pint dry-run
composer pint          # Pint fix
composer analyse       # PHPStan
```

License
-------

[](#license)

MIT © [Ronald2Wing](https://github.com/ronald2wing)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance86

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~38 days

Total

2

Last Release

67d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/db229ddb4db3893dddd4793f880304c35a5e43c76e0b206acd546c07b51fc450?d=identicon)[ronald2wing](/maintainers/ronald2wing)

---

Top Contributors

[![ronald2wing](https://avatars.githubusercontent.com/u/16713673?v=4)](https://github.com/ronald2wing "ronald2wing (3 commits)")

---

Tags

analyticsga4google-analyticslaravellivewirephplaraveltrackingbladeanalyticsgoogle-analyticsga4gtag

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ronald2wing-laravel-ga4/health.svg)

```
[![Health](https://phpackages.com/badges/ronald2wing-laravel-ga4/health.svg)](https://phpackages.com/packages/ronald2wing-laravel-ga4)
```

###  Alternatives

[blade-ui-kit/blade-icons

A package to easily make use of icons in your Laravel Blade views.

2.5k42.5M404](/packages/blade-ui-kit-blade-icons)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[robsontenorio/mary

Gorgeous UI components for Livewire powered by daisyUI and Tailwind

1.5k570.6k23](/packages/robsontenorio-mary)[hasinhayder/tyro-dashboard

Tyro Dashboard - Beautiful admin dashboard for managing Tyro roles, privileges, users, and settings

5443.8k](/packages/hasinhayder-tyro-dashboard)[technikermathe/blade-lucide-icons

A package to easily make use of Lucide icons in your Laravel Blade views.

18421.4k11](/packages/technikermathe-blade-lucide-icons)[hasinhayder/tyro-login

Tyro Login - Beautiful, customizable authentication views for Laravel 12 &amp; 13

2464.9k6](/packages/hasinhayder-tyro-login)

PHPackages © 2026

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