Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Gtm Laravel Package

jeffersongoncalves/laravel-gtm

Laravel GTM is a lightweight package for adding Google Tag Manager to Laravel apps. Set your container ID in config, and the package injects the GTM script and noscript fallback into your layouts, so you can manage analytics and marketing tags from the GTM dashboard without editing Blade templates.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. This package sits in the server-render path — it emits inline <script> blocks (the GTM snippet plus whatever other tags it manages) directly into Blade output. That placement is precisely what CSP breaks, so the 3.1.0 change is an architectural alignment rather than a new capability: it lets the package participate in Laravel's existing nonce mechanism (Vite::cspNonce()) instead of forcing teams to keep 'unsafe-inline' in script-src. Because it reads the same nonce source Vite already uses, inline scripts emitted by the package and the Vite-generated bundles share one consistent value — no second nonce authority, no divergence. It also pairs with laravel-security-headers 2.1, which is the component actually emitting the policy header, so the two are designed to be adopted together.

Integration feasibility. Low. The release note is explicit that behaviour is unchanged when no nonce is set, which makes this an additive, opt-in change with no config migration and no call-site changes. Realistically the work is: (a) bump the Composer constraint, (b) confirm a nonce is being generated and registered before views render, (c) flip the policy from 'unsafe-inline' to 'nonce-{nonce}'. The one ordering constraint to verify is that the nonce must be set (typically in middleware or a service provider) before the Blade template executes — any code path that renders tags before the nonce is established will silently emit a nonce-less script.

Technical risk. Moderate but well-bounded, and concentrated in CSP semantics rather than in the package.

  • Fail-closed behaviour. Once 'unsafe-inline' is removed, a missing or empty nonce means scripts are blocked with no server-side error — the site renders but analytics/GTM silently stop. This is the highest-impact failure mode and it is introduced by the adoption, not the upgrade.
  • GTM's transitive tags. Forwarding the nonce to the gtm.js tag covers the container script, but tags that GTM itself injects at runtime are outside the package's control. Those require 'strict-dynamic' or container-side configuration. This is the single most likely source of "it worked in staging, half our pixels died in prod" incidents.
  • Caching. Nonces are per-response by design; any full-page HTML cache (CDN, response cache, Octane-level caching of rendered output) will serve a stale nonce and break scripts. This is a pre-existing constraint of Vite's nonce support, but adopting this package makes it load-bearing for marketing tags too.
  • Blast radius if reverted. Rolling back the package version alone will not restore service if the CSP header has already been tightened — the header change and the package version must be reverted together.

Key questions.

  1. Does the package apply the nonce to all script tags it emits across its config surface, or only the GTM snippet called out in the notes?
  2. What is the behaviour when Vite::cspNonce() returns null/empty — render without the attribute, or skip the tag?
  3. Minimum Laravel and PHP versions for 3.1.0, and is laravel-security-headers 2.1 a hard requirement or an optional companion?
  4. Is there documented guidance for 'strict-dynamic' and for GTM-injected tags?
  5. Does it handle Livewire/Inertia partial reloads, where script emission may bypass the normal render cycle?
  6. Any guidance on interaction with page caching / CDN?

Integration Approach

Stack fit. A native Laravel package reading Laravel's native nonce API, complementary to a Laravel-native security-headers package. No bespoke middleware, no custom nonce store, no proxy-layer changes. It fits the standard Blade + Vite rendering model; anything outside that model (SPA front ends, separate marketing sites) is unaffected and out of scope.

Migration path. Treat as a minor, backward-compatible upgrade with an opt-in behavioural change. Two distinct steps that should be scheduled separately: the version bump (zero-risk, no config change, can ship on the normal release cadence) and the CSP tightening (behavioural, needs verification, should be a deliberate change with its own ticket and rollback plan). Do not bundle them into one deploy.

Compatibility. Backward compatible within 3.x for apps without a nonce — verify the constraint allows a clean composer update from the currently pinned version. Confirm the Laravel/PHP support matrix against our runtime before scheduling. The pairing with laravel-security-headers 2.1 should be treated as a tested combination, not an assumption.

Sequencing.

  1. Inventory every inline script and the current policy header; identify what depends on 'unsafe-inline'.
  2. Upgrade the package to ^3.1; confirm no behaviour change in staging (no nonce present yet).
  3. Introduce nonce generation for every HTML response and register it before view rendering.
  4. Add the nonce to the CSP header while keeping 'unsafe-inline' as a temporary fallback; verify scripts carry the attribute in page source.
  5. Remove 'unsafe-inline' on a non-production environment first; run full tag-firing validation (browser console, CSP report endpoint, tag manager preview/debug).
  6. Confirm cache behaviour — purge HTML caches, verify no stale nonce is served.
  7. Roll out to production behind the standard release gate with a documented joint rollback (package version + header).

Operational Impact

Maintenance. Small, single-purpose surface with low ongoing cost. The recurring obligation is governance rather than code: any future inline script added by any team must carry the nonce, so a lightweight review check ("no new inline scripts without nonce") is worth institutionalising. Nonce plumbing code should be owned centrally, not per-feature.

Support. Expect a shift in the shape of incidents rather than an increase in volume: CSP violations are silent to the server and loud only in the browser console. Without a report-to/report-uri endpoint, first-line support will get vague "analytics is broken" tickets with no server-side signal. Standing up CSP reporting before removal of 'unsafe-inline' is the single highest-value operational investment here. Runbooks should map "tags not firing" to "check nonce in page source" as step one.

Scaling. No runtime performance cost. The scaling consideration is infrastructural: per-response nonces are fundamentally incompatible with shared HTML caching, so any CDN or response-cache tier in front of these pages needs to be understood and reconfigured or excluded. This should be surfaced to whoever owns caching before rollout, not discovered during a traffic spike.

Failure modes.

  • Nonce not set before render → scripts emitted without the attribute → blocked, no server error.
  • HTML cached with a stale nonce → blocked for all subsequent users until cache invalidation.
  • GTM-injected third-party tags blocked because 'strict-dynamic' is absent → partial analytics loss, easy to miss.
  • Partial rollback (revert package, keep tightened header) → prolonged outage of tags.
  • Nonce leaked into logs or error pages → weakens the control and is an audit finding.

Ramp-up. Low for anyone who has worked with CSP; genuinely confusing for anyone who has not. The concepts to land with the team are the nonce lifecycle (generate per response, register before render, reference in both markup and header) and 'strict-dynamic'. Budget roughly half a day of engineering for the change itself and a comparable amount of QA to validate tag firing across the tag estate, plus a short written explainer so on-call can diagnose violations without escalation.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums