PHPackages                             jeffersongoncalves/laravel-gtag - 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. jeffersongoncalves/laravel-gtag

ActiveLibrary

jeffersongoncalves/laravel-gtag
===============================

This Laravel package provides a straightforward integration of Google Analytics using Gtag into your Blade templates. It enables you to easily track website visits and user engagement, offering valuable insights into your site's performance. With minimal setup, you can leverage Gtag's powerful analytics features to better understand your audience and improve your website's effectiveness.

v2.0.1(2mo ago)2143↑100%[1 PRs](https://github.com/jeffersongoncalves/laravel-gtag/pulls)1MITPHPPHP ^8.2|^8.3CI passing

Since May 2Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/jeffersongoncalves/laravel-gtag)[ Packagist](https://packagist.org/packages/jeffersongoncalves/laravel-gtag)[ Docs](https://github.com/jeffersongoncalves/laravel-gtag)[ RSS](/packages/jeffersongoncalves-laravel-gtag/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (5)Used By (1)

[![Laravel Gtag](https://raw.githubusercontent.com/jeffersongoncalves/laravel-gtag/master/art/jeffersongoncalves-laravel-gtag.png)](https://raw.githubusercontent.com/jeffersongoncalves/laravel-gtag/master/art/jeffersongoncalves-laravel-gtag.png)

Laravel Google Analytics
========================

[](#laravel-google-analytics)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae05040d7cacdc42505b4be60a790f2e26a840115dd552bb4181278086d9c53b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d677461672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-gtag)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/3c088649fed710fe1630a4abcf725b55cffd4fa047be2af785b1b1ca1bc70450/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d677461672f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jeffersongoncalves/laravel-gtag/actions?query=workflow%3A%22Fix+PHP+code+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/e8a41486ec42ca110004154fb0088cabca04565a955d1a985682c805add5479f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d677461672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-gtag)

This Laravel package provides a straightforward integration of Google Analytics using Gtag into your Blade templates. It enables you to easily track website visits and user engagement, offering valuable insights into your site's performance. With minimal setup, you can leverage Gtag's powerful analytics features to better understand your audience and improve your website's effectiveness.

Settings are stored in the database using [spatie/laravel-settings](https://github.com/spatie/laravel-settings), allowing dynamic management via admin panels or code.

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

[](#installation)

You can install the package via composer:

```
composer require jeffersongoncalves/laravel-gtag
```

Publish and run the settings migrations:

```
php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
php artisan vendor:publish --tag=gtag-settings-migrations
php artisan migrate
```

Usage
-----

[](#usage)

Add the script tag to your Blade layout (typically in the ``):

```
@include('gtag::script')
```

### Configuration via Code

[](#configuration-via-code)

You can update settings at any time using the `GtagSettings` class, the `gtag_settings()` helper, or the `Gtag` facade:

```
use JeffersonGoncalves\Gtag\Settings\GtagSettings;

// Via container
$settings = app(GtagSettings::class);
$settings->gtag_id = 'G-XXXXXXXXXX';
$settings->enabled = true;
$settings->save();

// Via helper
gtag_settings()->gtag_id = 'G-XXXXXXXXXX';
gtag_settings()->save();

// Via Facade
use JeffersonGoncalves\Gtag\Facades\Gtag;

$gtag = Gtag::getFacadeRoot();
$gtag->gtag_id = 'G-XXXXXXXXXX';
$gtag->save();
```

### Available Properties

[](#available-properties)

PropertyTypeDefaultDescription`gtag_id``?string``null`Google Tag ID (e.g., `G-XXXXXXXXXX`)`enabled``bool``true`Enable/disable script rendering`anonymize_ip``bool``false`Anonymize visitor IPs (GDPR compliance)`additional_config``array``[]`Extra parameters for `gtag('config', ...)`### Additional Config Example

[](#additional-config-example)

```
$settings = gtag_settings();
$settings->additional_config = [
    'send_page_view' => false,
    'cookie_domain' => 'example.com',
];
$settings->save();
```

Upgrading from v1
-----------------

[](#upgrading-from-v1)

Version 2 replaces the `config/gtag.php` configuration file with database settings via `spatie/laravel-settings`. This is a **breaking change**.

1. Remove the old config file: `config/gtag.php`
2. Remove the `GTAG_ID` environment variable (no longer used)
3. Publish and run the settings migration
4. Set your Google Tag ID via code (see Usage above)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jèfferson Gonçalves](https://github.com/jeffersongoncalves)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance85

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.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 ~149 days

Total

3

Last Release

77d ago

Major Versions

1.0.0 → v2.0.02026-02-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/411493?v=4)[Jefferson Gonçalves](/maintainers/jeffersongoncalves)[@jeffersongoncalves](https://github.com/jeffersongoncalves)

---

Top Contributors

[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (1 commits)")

---

Tags

analyticsgdprgoogle-analyticsgoogle-tag-managergtaglaravellaravel-gtaglaravel-packagespatie-laravel-settingslaraveljeffersongoncalveslaravel-gtag

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jeffersongoncalves-laravel-gtag/health.svg)

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

###  Alternatives

[jeffersongoncalves/filament-topbar

A simple yet effective Filament plugin that automatically adds a customized topbar to your Filament admin panel. This plugin enhances your Filament panel's user experience by replacing the default topbar component with an improved version that displays navigation and user interface elements in strategic locations.

171.2k](/packages/jeffersongoncalves-filament-topbar)

PHPackages © 2026

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