jeffersongoncalves/laravel-gtag
Laravel package for integrating Google tag (gtag.js) and Google Analytics 4 into your application, with simple configuration, Blade support, and helpers for tracking page views and custom events.
Architecture fit. The package follows standard Laravel package conventions — a service provider plus the Blade/response-layer hooks that emit its script tags — and v3.1.0 adds a read of Laravel's Vite nonce singleton (Vite::cspNonce()) at render time. That is the canonical, framework-blessed way to obtain a per-request nonce, so the package is aligning with core rather than inventing a parallel config surface. There is no new dependency, no new migration, and no new configuration key: the nonce is inherited from whatever sets it (e.g. laravel-security-headers 2.1, or an app middleware calling Vite::useCspNonce()). Architecturally this is a small, well-scoped change in the presentation layer.
Integration feasibility. Low effort. A composer update to ^3.1 plus confirmation that a nonce is actually populated before the package's scripts render. Two preconditions matter: (1) the app must emit a CSP header containing 'nonce-{nonce}', and (2) the nonce must be generated and bound before the package renders its tags — ordering is the only real integration hazard. Apps without a nonce see byte-identical output, so the blast radius of the upgrade itself is effectively zero.
Technical risk. Low to moderate, concentrated in nonce lifecycle rather than in the package code:
script-src host allowlisting. Teams expecting one attribute to solve CSP will be disappointed.Key questions for the maintainer/vendor.
useCspNonce().)style-src / inline-style nonce handling on the roadmap, or is this script-only?Stack fit. Laravel 9+ with the Vite integration available (Vite::useCspNonce() / cspNonce()), PHP 8.1+, and a CSP emitter — either laravel-security-headers 2.1+ or homegrown middleware. Teams not running CSP are unaffected and can adopt later with no code change.
Migration path. Treat this as an enabler rather than a migration in itself:
^3.1.0; confirm no output change in an app without a nonce.Content-Security-Policy-Report-Only with a nonce directive.'unsafe-inline' from script-src and flip to enforcing.Compatibility. Backwards compatible by construction — the release note explicitly scopes the change to apps that set a nonce. The one version coupling to watch is the CSP emitter: laravel-security-headers 2.1 is the reference implementation, and older versions or custom middleware must be confirmed to call Vite::useCspNonce() rather than rolling their own nonce variable.
Sequencing. Do the package bump first (inert), then the CSP reporting work (observable), then enforcement (the actual security win). Do not bundle enforcement into the same deploy as the upgrade — you lose the ability to attribute breakage. If the app sits behind a CDN or full-page cache, sequence cache-behavior changes before enforcement.
Maintenance. Near zero. No config, no migration, no data changes. The ongoing obligation is tracking the upstream Vite nonce API and the CSP emitter version — both stable, but this is now an implicit dependency the package doesn't declare.
Support. Net reduction in CSP-related support load once enforcement lands, since 'unsafe-inline' removal is usually the blocking item in security reviews and audit questionnaires. Expect a short spike in "widget stopped rendering" tickets during the report-only → enforce transition, almost always traceable to a missing or stale nonce.
Scaling. Negligible performance cost — one attribute per tag. The scaling concern is correctness at scale: nonce generation must be per-request and per-response, and any horizontal layer that reuses rendered HTML (CDN, reverse proxy cache, response cache) must not replay a nonce.
Failure modes.
Ramp-up. Effectively zero for existing users. For teams newly pursuing CSP, this release is the piece that lets them drop 'unsafe-inline' without rewriting their inline script handling — a meaningful unblock for security sign-off at low implementation cost. Recommendation: adopt on the next routine dependency bump, and pair it with a short spike to confirm nonce ordering and Octane/caching behavior before CSP enforcement.
How can I help you explore Laravel packages today?