PHPackages                             jeffersongoncalves/laravel-gtm - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jeffersongoncalves/laravel-gtm

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jeffersongoncalves/laravel-gtm
==============================

This plugin seamlessly integrates Google Tag Manager (GTM) into your website, enabling streamlined management and deployment of marketing tags, analytics, and tracking pixels. With easy-to-implement script inclusion and customizable options, it simplifies the process of monitoring user interactions and gathering valuable insights without altering your site's core code. Perfect for marketers and developers looking to enhance their tracking capabilities with minimal effort.

2.0.1(2mo ago)24211MITPHPPHP ^8.2|^8.3CI passing

Since May 2Pushed 1mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (8)Versions (6)Used By (1)

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

Laravel Google Tag Manager
==========================

[](#laravel-google-tag-manager)

[![Latest Version on Packagist](https://camo.githubusercontent.com/610c3572e2929ed629a95e024cb1e2530781067603acebe5a4f50e94910987bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d67746d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-gtm)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a960e99017669c8b860608129a25e9eb139b4e94ba282fb1d0d8233b9e0daa66/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d67746d2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jeffersongoncalves/laravel-gtm/actions?query=workflow%3A%22Fix+PHP+code+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/34a9e76489903996d8cb183e156e54badf89e1a08080dd10524829129f90f6d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6566666572736f6e676f6e63616c7665732f6c61726176656c2d67746d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jeffersongoncalves/laravel-gtm)

This plugin seamlessly integrates Google Tag Manager (GTM) into your website, enabling streamlined management and deployment of marketing tags, analytics, and tracking pixels. With easy-to-implement script inclusion and customizable options, it simplifies the process of monitoring user interactions and gathering valuable insights without altering your site's core code. Perfect for marketers and developers looking to enhance their tracking capabilities with minimal effort.

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

[](#requirements)

- PHP 8.2+
- Laravel 11.0+
- `spatie/laravel-settings` ^3.0 (installed automatically)

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

[](#installation)

You can install the package via composer:

```
composer require jeffersongoncalves/laravel-gtm
```

Run the migrations to create the settings table and seed the GTM settings:

```
php artisan migrate
```

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

[](#configuration)

### Setting your GTM ID

[](#setting-your-gtm-id)

The GTM ID is stored in the database via `spatie/laravel-settings`. Configure it at runtime using any of the following approaches:

#### Via dependency injection

[](#via-dependency-injection)

```
use JeffersonGoncalves\Gtm\Settings\GtmSettings;

$settings = app(GtmSettings::class);
$settings->gtm_id = 'GTM-XXXXXX';
$settings->save();
```

#### Via helper function

[](#via-helper-function)

```
$settings = gtm_settings();
$settings->gtm_id = 'GTM-XXXXXX';
$settings->save();
```

### Publishing the settings migration (optional)

[](#publishing-the-settings-migration-optional)

If you need to customize the settings migration:

```
php artisan vendor:publish --tag=gtm-settings-migrations
```

Usage
-----

[](#usage)

Add the GTM head script inside your `` tag, as high as possible:

```
@include('gtm::head')
```

Add the GTM body noscript immediately after the opening `` tag:

```
@include('gtm::body')
```

### Reading the current GTM ID

[](#reading-the-current-gtm-id)

```
// Via helper
$gtmId = gtm_settings()->gtm_id;

// Via container
$gtmId = app(\JeffersonGoncalves\Gtm\Settings\GtmSettings::class)->gtm_id;

// Via Facade
$gtmId = \JeffersonGoncalves\Gtm\Facades\Gtm::gtm_id;
```

### Updating the GTM ID at runtime

[](#updating-the-gtm-id-at-runtime)

```
$settings = gtm_settings();
$settings->gtm_id = 'GTM-NEWID';
$settings->save();
```

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

47

—

FairBetter than 94% of packages

Maintenance87

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.6% 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 ~99 days

Total

4

Last Release

77d ago

Major Versions

1.1.0 → 2.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 (25 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 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

google-analyticsgoogle-tag-managergtmlaravellaravel-gtmlaravel-packagephpspatie-laravel-settingstrackinglaraveljeffersongoncalveslaravel-gtm

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

PHPackages © 2026

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