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 Gtag Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • Ordering — a nonce set in a middleware that runs after the response body is composed will produce tags with an empty/absent attribute.
  • Per-request uniqueness — under Octane or any long-lived worker, a nonce held in a singleton or static must be reset per request; a leaked nonce across responses silently weakens the policy.
  • Page/CDN caching — cached HTML carrying a previously valid nonce will be blocked on replay. Any full-page cache in front of the app needs nonce-aware handling.
  • Mixed script sources — nonces only authorize inline/owned script tags; third-party scripts loaded by the package still require script-src host allowlisting. Teams expecting one attribute to solve CSP will be disappointed.

Key questions for the maintainer/vendor.

  1. Which script surfaces receive the nonce — only the primary render path, or also scripts injected into AJAX/partial responses and Blade components?
  2. Is the nonce read once at boot or per render? (Determines Octane safety and whether it must be re-read after useCspNonce().)
  3. Does the package expose a hook to verify nonce propagation in a test environment?
  4. Is style-src / inline-style nonce handling on the roadmap, or is this script-only?
  5. Minimum supported Laravel/PHP versions for 3.1.x, and whether the Vite nonce API is treated as a stable contract.

Integration Approach

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:

  1. Upgrade the package to ^3.1.0; confirm no output change in an app without a nonce.
  2. Stand up CSP in Content-Security-Policy-Report-Only with a nonce directive.
  3. Verify the emitted script tags carry the nonce and that violations drop to zero for the package's scripts.
  4. Remove '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.

Operational Impact

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.

  • No nonce set → unchanged behavior; no failure.
  • Nonce set but not propagated → script silently blocked; the package's feature degrades, the host app does not. This is the dangerous one because it's quiet.
  • Stale nonce from cache → intermittent, environment-specific breakage that is hard to reproduce.
  • Nonce leaked under Octane → no visible breakage, but the policy is weaker than assumed; a security regression with no runtime symptom.
  • Third-party scripts assumed covered → still blocked until host allowlisted.

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.

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