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.
'unsafe-inline' from your CSP without breaking tag management. The 3.1.0 release forwards Laravel's CSP nonce (Vite::cspNonce(), e.g. set by laravel-security-headers 2.1) onto the scripts this package injects and onto the gtm.js tag it creates. That turns a hard security/compliance trade-off into a configuration detail: you can adopt a strict script-src 'nonce-{nonce}' policy while keeping GTM/analytics instrumentation working.'unsafe-inline' is flagged in audit.Consider it when:
laravel-security-headers 2.1 or Vite::cspNonce(). The 3.1.0 nonce forwarding, including to the derived gtm.js tag, is the specific reason to adopt or upgrade now.'unsafe-inline' from script-src.Look elsewhere or defer when:
Adoption criteria: confirm the nonce is available at render time, verify the emitted scripts and gtm.js tag carry the nonce in a staging CSP with 'unsafe-inline' removed, and check that response caching or full-page caching doesn't serve a stale nonce.
For executives: A small, low-risk upgrade that removes a common security exception. Our analytics/marketing tags can now run under a strict Content Security Policy instead of the weaker 'unsafe-inline' allowance — closing a recurring finding in security reviews and customer questionnaires, at no migration cost. Apps that don't use a nonce see no change at all.
For engineering: Version 3.1.0 propagates Laravel's CSP nonce (Vite::cspNonce(), as set by laravel-security-headers 2.1) onto the scripts this package injects, and forwards it to the gtm.js tag it creates. That lets a policy allow these scripts via 'nonce-{nonce}' rather than 'unsafe-inline'. Fully backward compatible — no config or code changes required. Upgrade risk is low; the only real validation is confirming the nonce is set before render and is not cached across requests.
Recommendation: Upgrade to 3.1.0. Treat it as an enabler for tightening script-src to nonce-based in a follow-up change, validated in staging with 'unsafe-inline' removed.
How can I help you explore Laravel packages today?