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.3(1mo ago)32.2k1MITPHPPHP ^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)[ GitHub Sponsors](https://github.com/jeffersongoncalves)[ RSS](/packages/jeffersongoncalves-laravel-gtm/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (24)Versions (9)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')
{{-- or use the Blade directive --}}
@gtmHead
```

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

```
@include('gtm::body')
{{-- or use the Blade directive --}}
@gtmBody
```

> The scripts are only rendered when a valid GTM ID is configured. A valid ID matches the pattern `GTM-XXXXXXX` (uppercase letters and digits).

### 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 (resolve the underlying settings instance first)
$gtmId = \JeffersonGoncalves\Gtm\Facades\Gtm::getFacadeRoot()->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

50

—

FairBetter than 95% of packages

Maintenance91

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.7% 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 ~77 days

Recently: every ~23 days

Total

6

Last Release

43d 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 (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 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

composergoogle-analyticsgoogle-tag-managergtmjeffersongoncalveslaravellaravel-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)
```

###  Alternatives

[finity-labs/fin-mail

A powerful email template manager and composer for Filament with dynamic token replacement, template versioning, and inline email sending.

284.5k1](/packages/finity-labs-fin-mail)

PHPackages © 2026

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