xynnn/google-tag-manager-bundle
A Symfony bundle that integrates Google Tag Manager with configurable container IDs, Twig helpers, and environment-aware tracking. It simplifies adding GTM snippets, managing data layer variables, and keeping analytics setup clean across Symfony applications.
composer require it into a Laravel app and expect auto-discovery, Blade helpers, or a service provider. Treat it as a reference implementation for GTM container injection, not a day-to-day Laravel dependency.README.md, DependencyInjection/Configuration.php, Resources/config/services.xml, and the Twig extension class. Those tell you the config key, the Twig function names, and whether the bundle only renders snippets or also injects into responses.AppKernel, configure the container ID under the bundle’s config key (typically xynnn_google_tag_manager: container_id: GTM-XXXXXX), clear the cache, and call the bundle’s Twig helper in your base layout.<script> snippet in <head> and the <noscript> iframe immediately after <body>. Verify with GTM Preview mode that the container loads exactly once.GTM-XXXXXX in config/services.php or .env, create a Blade partial for the head and noscript snippets, include it in layouts/app.blade.php, and push events to dataLayer from a small PHP service or Blade component.config('services.google_tag_manager.container_id') and never hardcode IDs in templates.<head> and the noscript snippet immediately after <body>. For Inertia, Livewire, or Turbolinks-style navigation, load GTM once and push virtual page views to dataLayer on route changes.view_item, add_to_cart, purchase) and render them through a Blade component such as <x-gtm-event :payload="$payload" />. This avoids ad hoc dataLayer.push calls scattered across views..env and a null container ID.assertSee('GTM-...') plus a small data-layer assertion in a feature test is usually enough.composer.json constraints before trusting it in a current project.<noscript> iframe belongs immediately after <body>. Moving it to the footer breaks the intended fallback behavior.window.dataLayer = window.dataLayer || [] before GTM loads, then push events after. Ordering bugs are common when snippets are moved around or loaded asynchronously.dataLayer.window.dataLayer in the console. In Symfony, use debug:container and debug:twig to confirm service and function names, then clear cache. In Laravel, use php artisan config:clear and view:clear.Configuration.php and the extension class; old blog posts and READMEs drift. Also confirm the ID starts with GTM-; UA- and G- IDs are not GTM containers.script-src and connect-src, consider nonces, and do not render GTM in emails or non-HTML contexts.How can I help you explore Laravel packages today?