### Install laravel-gtm via Composer Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Install the package via Composer. Requires PHP 8.2+, Laravel 11.0+, and automatically installs spatie/laravel-settings ^3.0. ```bash composer require jeffersongoncalves/laravel-gtm ``` -------------------------------- ### Run migrations for GTM settings Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Run migrations to create the settings table and seed the GTM settings. ```bash php artisan migrate ``` -------------------------------- ### Publish and run GTM settings migration Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Publishes the settings migration and runs it. This creates the 'gtm.gtm_id' setting in the 'settings' database table. ```bash php artisan vendor:publish --tag=gtm-settings-migrations php artisan migrate ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Run the package's test suite. ```bash composer test ``` -------------------------------- ### Publish GTM settings migration Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Publish the settings migration if you need to customize it. This is optional. ```bash php artisan vendor:publish --tag=gtm-settings-migrations ``` -------------------------------- ### Access GTM settings via helper, facade, DI, and app container Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Shows four ways to retrieve the GTM ID: using the global helper gtm_settings(), the facade Gtm::gtm_id, dependency injection of GtmSettings, and the app container. ```php use JeffersonGoncalves\Gtm\Settings\GtmSettings; // Via global helper $settings = gtm_settings(); $gtmId = $settings->gtm_id; // Via facade $gtmId = \JeffersonGoncalves\Gtm\Facades\Gtm::gtm_id; // Via dependency injection public function show(GtmSettings $settings) { return $settings->gtm_id; } // Via app container $settings = app(GtmSettings::class); ``` -------------------------------- ### Run Pest tests for GTM package Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Execute the test suite using Pest with Orchestra Testbench. Run this command from the package root to verify the GTM head script rendering behavior. ```bash php vendor/bin/pest ``` -------------------------------- ### Define GtmSettings class extending Spatie Settings Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md The GtmSettings class extends Spatie\LaravelSettings\Settings and defines a public string property 'gtm_id' with a default empty string. The group() method returns 'gtm'. ```php namespace JeffersonGoncalves\Gtm\Settings; use Spatie\LaravelSettings\Settings; class GtmSettings extends Settings { public string $gtm_id = ''; public static function group(): string { return 'gtm'; } } ``` -------------------------------- ### Package structure of jeffersongoncalves/laravel-gtm Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Shows the directory layout of the package, including the facade, settings class, service provider, helper, Blade views, and migration. ```text src/ Facades/Gtm.php # Facade resolving to GtmSettings Settings/GtmSettings.php # Settings class with gtm_id property GtmServiceProvider.php # Service provider (auto-discovered) helpers.php # gtm_settings() global helper resources/views/ head.blade.php # GTM JavaScript snippet for
body.blade.php # GTM noscript iframe for database/settings/ 2026_02_20_000000_create_gtm_settings.php # Settings migration ``` -------------------------------- ### Create Filament settings page for GTM Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Use this Filament SettingsPage class to manage the GTM container ID in the admin panel. It binds to the GtmSettings class and provides a text input for the GTM ID with a placeholder and max length of 20 characters. ```php use Filament\Forms\Components\TextInput; use Filament\Pages\SettingsPage; use JeffersonGoncalves\Gtm\Settings\GtmSettings; class ManageGtmSettings extends SettingsPage { protected static string $settings = GtmSettings::class; protected static ?string $navigationIcon = 'heroicon-o-code-bracket'; public function form(Form $form): Form { return $form->schema([ TextInput::make('gtm_id') ->label('GTM Container ID') ->placeholder('GTM-XXXXXXX') ->maxLength(20), ]); } } ``` -------------------------------- ### Update GTM settings via app container Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Retrieves the settings instance from the app container, sets the gtm_id property to 'GTM-XXXXXXX', and saves it. ```php $settings = app(GtmSettings::class); $settings->gtm_id = 'GTM-XXXXXXX'; $settings->save(); ``` -------------------------------- ### Pest tests for GTM head script rendering Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md These Pest tests verify that the GTM head script renders when a GTM ID is set and does not render when the ID is empty. They use the GtmSettings class and assert on the view output. ```php use JeffersonGoncalves\Gtm\Settings\GtmSettings; it('renders gtm head script when id is set', function () { $settings = app(GtmSettings::class); $settings->gtm_id = 'GTM-TEST123'; $settings->save(); $view = $this->blade("@include('gtm::head')"); $view->assertSee('GTM-TEST123'); $view->assertSee('googletagmanager.com/gtm.js'); }); it('does not render when gtm_id is empty', function () { $settings = app(GtmSettings::class); $settings->gtm_id = ''; $settings->save(); $view = $this->blade("@include('gtm::head')"); $view->assertDontSee('googletagmanager'); }); ``` -------------------------------- ### Set GTM ID via helper function Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Set the GTM ID at runtime using the gtm_settings() helper function. ```php $settings = gtm_settings(); $settings->gtm_id = 'GTM-XXXXXX'; $settings->save(); ``` -------------------------------- ### Read current GTM ID Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Read the current GTM ID using three approaches: the gtm_settings() helper, the container, or the Gtm facade. ```php // 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; ``` -------------------------------- ### Update GTM ID at runtime Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Update the GTM ID at runtime using the gtm_settings() helper. ```php $settings = gtm_settings(); $settings->gtm_id = 'GTM-NEWID'; $settings->save(); ``` -------------------------------- ### Include GTM head script Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Add the GTM head script inside your tag, as high as possible. The script is only rendered when a valid GTM ID is configured (pattern GTM-XXXXXXX). ```blade @include('gtm::head') {{-- or use the Blade directive --}} @gtmHead ``` -------------------------------- ### Set GTM ID via dependency injection Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Set the GTM ID at runtime using dependency injection. The GTM ID is stored in the database via spatie/laravel-settings. ```php use JeffersonGoncalves\Gtm\Settings\GtmSettings; $settings = app(GtmSettings::class); $settings->gtm_id = 'GTM-XXXXXX'; $settings->save(); ``` -------------------------------- ### Include GTM body noscript Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/README.md Add the GTM body noscript immediately after the opening tag. The script is only rendered when a valid GTM ID is configured. ```blade @include('gtm::body') {{-- or use the Blade directive --}} @gtmBody ``` -------------------------------- ### Include gtm::head in Blade layout Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Include the GTM head view in your layout's section. The view renders the GTM JavaScript snippet only when the gtm_id setting is non-empty. ```blade @include('gtm::head') ``` ```html ``` -------------------------------- ### Include gtm::body in Blade layout Source: https://github.com/jeffersongoncalves/laravel-gtm/blob/master/resources/boost/skills/gtm-development/SKILL.md Include the gtm::body view immediately after the tag. It renders the noscript fallback iframe when gtm_id is populated. ```blade @include('gtm::body') ``` ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.