### Install filament-gtm via Composer Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/README.md Install the package via Composer. Requires PHP 8.2 or higher, Filament 5.0, and Laravel 11.0 or higher. ```bash composer require jeffersongoncalves/filament-gtm:"^3.0" ``` -------------------------------- ### GtmPlugin class implementing Filament Plugin Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/resources/boost/skills/filament-gtm-development/SKILL.md The GtmPlugin class implements Filament's Plugin contract. It provides make() and get() factory methods, returns the plugin ID 'filament-gtm', and registers the settings page when hasSettingsPage is true. The settingsPage() method toggles that flag and returns the instance for chaining. ```php namespace JeffersonGoncalves\Filament\Gtm; use Filament\Contracts\Plugin; use Filament\Panel; use JeffersonGoncalves\Filament\Gtm\Pages\ManageGtmSettings; class GtmPlugin implements Plugin { protected bool $hasSettingsPage = true; public static function make(): static { return app(static::class); } public static function get(): static { $plugin = filament(app(static::class)->getId()); return $plugin; } public function getId(): string { return 'filament-gtm'; } public function register(Panel $panel): void { if ($this->hasSettingsPage) { $panel->pages([ ManageGtmSettings::class, ]); } } public function boot(Panel $panel): void {} public function settingsPage(bool $condition = true): static { $this->hasSettingsPage = $condition; return $this; } } ``` -------------------------------- ### Publish and run GTM settings migrations Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/README.md Publish the settings migrations and run them to set up the database tables for the plugin's settings page. ```bash php artisan vendor:publish --tag=gtm-settings-migrations php artisan migrate ``` -------------------------------- ### Run tests with Composer Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/README.md Run the package's test suite. ```bash composer test ``` -------------------------------- ### GtmServiceProvider registering GTM render hooks Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/resources/boost/skills/filament-gtm-development/SKILL.md The GtmServiceProvider extends Spatie's PackageServiceProvider. It configures the package name and translations, and registers two render hooks: HEAD_START and BODY_START, both required by Google Tag Manager. The hooks render the 'gtm::head' and 'gtm::body' views respectively. ```php namespace JeffersonGoncalves\Filament\Gtm; use Filament\Support\Facades\FilamentView; use Filament\View\PanelsRenderHook; use Illuminate\Contracts\View\View; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; class GtmServiceProvider extends PackageServiceProvider { public function configurePackage(Package $package): void { $package->name('filament-gtm') ->hasTranslations(); } public function packageRegistered(): void { FilamentView::registerRenderHook(PanelsRenderHook::HEAD_START, fn (): View => view('gtm::head')); FilamentView::registerRenderHook(PanelsRenderHook::BODY_START, fn (): View => view('gtm::body')); } } ``` -------------------------------- ### Register GtmPlugin in Filament panel provider Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/README.md Register the plugin in your Filament panel provider. This adds a settings page for managing the GTM container ID and automatically injects GTM scripts into the and sections of your Filament panels. ```php use JeffersonGoncalves\Filament\Gtm\GtmPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ GtmPlugin::make(), ]); } ``` -------------------------------- ### ManageGtmSettings settings page with GTM ID field Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/resources/boost/skills/filament-gtm-development/SKILL.md The ManageGtmSettings page extends Filament's SettingsPage and binds to the GtmSettings class. Its form contains a single section with a TextInput for the GTM container ID, using the placeholder 'GTM-XXXXXXX' and localized labels. The navigation icon is set to 'heroicon-o-code-bracket'. ```php namespace JeffersonGoncalves\Filament\Gtm\Pages; use Filament\Forms\Components\TextInput; use Filament\Pages\SettingsPage; use Filament\Schemas\Components\Section; use Filament\Schemas\Schema; use JeffersonGoncalves\Gtm\Settings\GtmSettings; class ManageGtmSettings extends SettingsPage { protected static string $settings = GtmSettings::class; protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-code-bracket'; public function form(Schema $schema): Schema { return $schema ->columns(null) ->schema([ Section::make(__('filament-gtm::pages.sections.gtm.heading')) ->description(__('filament-gtm::pages.sections.gtm.description')) ->schema([ TextInput::make('gtm_id') ->label(__('filament-gtm::pages.fields.gtm_id.label')) ->placeholder('GTM-XXXXXXX') ->helperText(__('filament-gtm::pages.fields.gtm_id.helper')), ]), ]); } } ``` -------------------------------- ### Disable GTM settings page Source: https://github.com/jeffersongoncalves/filament-gtm/blob/3.x/README.md Disable the settings page if you only want automatic GTM injection without managing the container ID from the admin panel. ```php GtmPlugin::make() ->settingsPage(false), ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.