darvis/livewire-google-analytics
Easily add Google Analytics to your Livewire apps with a simple component. Track page views, events, and user interactions without writing JavaScript, keeping analytics setup clean and configurable in Laravel.
composer require arviddejong/livewire-google-analytics, then follow the quickstart — it is the fastest path because it ships one complete, copyable contact form: layout, Livewire component, Blade view, and route, each with its file name and imports.livewire-google-analytics::script) to your layout once. The package does not load gtag.js for you, so you also need your own Google tag snippet (or GTM) with your measurement ID in place before any event will land.$this->track...() after save()/mail send), so the event reflects a real outcome rather than a click.…AfterRedirect() variants stash the event so it is sent on the next page load. Use the plain form for in-place interactions (modals, filters, live search) and the …AfterRedirect() form for the redirect-after-submit pattern where the component is destroyed.'debug_mode' => true in the params while developing — that is the reliable way to get the event into DebugView, either on the tag or on a single event.window.gtag does not exist yet (script still loading, tag manager delayed), events wait until it does. Pass ['queue' => false] when you would rather drop the event than have it fire late.wire:navigate works, with a nuance. The listener does not attach a second time on navigation, but it does flush events carried over from the previous page — so …AfterRedirect() events survive SPA-style navigation.No hint path defined for [livewire-google-analytics]. means the service provider is not loaded (package not discovered / provider removed from bootstrap/providers.php). View [script] not found. means the provider is fine but the view name you referenced is wrong. Check which one you have before touching config.window.gtag. Ad blockers, JS disabled, or a missing tag snippet means zero data — no server-side fallback exists, so do not use this for business-critical auditing.gtag.js load behind your own consent layer; the queue only controls when a waiting event is sent once window.gtag exists.…AfterRedirect() writes into the next page's listener script. Since 1.3.0, the event is serialised as JSON with tags and quotes escaped. Keep those payloads small and free of user-entered text — the old "form values are never written into a script" guarantee no longer holds for these methods, and escaping is not a licence to put PII in params.debug_mode parameter, and find DebugView under Admin → "Data display".debug_mode defaults) belongs in your own layout/partial that includes the package's script view.How can I help you explore Laravel packages today?