Download the PHP package darvis/livewire-google-analytics without Composer
On this page you can find all versions of the php package darvis/livewire-google-analytics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download darvis/livewire-google-analytics
More information about darvis/livewire-google-analytics
Files in darvis/livewire-google-analytics
Package livewire-google-analytics
Short Description Google Analytics 4 event tracking for Laravel Livewire: a trait that dispatches a browser event and a small listener that forwards it to gtag().
License MIT
Homepage https://arviddejong.github.io/livewire-google-analytics/
Informations about the package livewire-google-analytics
Livewire Google Analytics
Send Google Analytics 4 events from Laravel Livewire components. You call a PHP method such as $this->trackLead() in a component, and a listener script in your layout passes the event to gtag(). The package does not load Google Analytics, has no measurement id setting and does no consent handling: your own Google tag stays where it is.
Features
- One line per event -
trackLead(),trackNewsletterSignup(),trackCustomEvent(), andtrackEvent()for everything else - Parameters as data - the event name and parameters reach the browser as JSON, never as JavaScript source, so form input cannot break out of a script
- Waits for the Google tag - an event tracked before
window.gtagexists waits (at most 50 events, at most 30 minutes) and is sent in order once it does; opt out with['queue' => false] - Survives a redirect -
trackEventAfterRedirect()carries the event to the next page through the session, and it is sent once - Fails quietly - without
gtagfor the whole visit nothing is sent, nothing throws and the Livewire action carries on - No double events - the listener registers once per window, also with
wire:navigate - Nothing to configure - no config file, no environment variable, no migration
Requirements
- PHP 8.2+
- Laravel 11, 12 or 13
- Livewire 3 or 4
- A Google tag (
gtag.js) on the page; the package does not load it
Installation
Include the listener once in your layout, before </body>:
Quick start
app/Livewire/ContactForm.php:
After a valid submit the browser calls gtag('event', 'generate_lead', {form_name: 'contact_form'}). Track in an action, after the work succeeded, and not in render(), which runs on every request.
In an action that ends in a redirect, use the …AfterRedirect() variant; the page after the redirect has to include the Blade view:
Documentation
The full documentation lives on the documentation site:
- Installation: your Google tag, the listener, and a check that an event arrives
- Quick start: one complete contact form with every file
- Tracking events: every method and where to call it
- How it works: the browser event, the queue, the redirect
- Examples: newsletter, purchase, download
- Testing:
assertDispatched('ga:event', ...)in your own test suite - Troubleshooting: no event, double events, error messages
- FAQ
Laravel Boost
The package ships a guideline and a skill for Laravel Boost, so an AI assistant in your app knows the API and the pitfalls. Run php artisan boost:install, or php artisan boost:update --discover in a project that already uses Boost.
Testing
Changelog
See CHANGELOG.
Support the package
If darvis/livewire-google-analytics saves you time, a star on GitHub or a favourite on Packagist helps other developers find it.
Contributing
See CONTRIBUTING.
Security
Please report a vulnerability privately, as described in SECURITY, not in the issue tracker.
License
The MIT License (MIT). See LICENSE.
All versions of livewire-google-analytics with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
livewire/livewire Version ^3.0|^4.0