PHP code example of darvis / livewire-google-analytics
1. Go to this page and download the library: Download darvis/livewire-google-analytics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
darvis / livewire-google-analytics example snippets
// Before: Complex and error-prone ❌
$this->js("gtag('event', 'generate_lead', {...})");
// After: Simple and safe ✅
$this->trackLead(['form_name' => 'contact_form']);
use Darvis\LivewireGoogleAnalytics\Traits\TracksAnalytics;
class ContactForm extends Component
{
use TracksAnalytics;
public function submit()
{
$this->validate();
Contact::create($this->all());
// Track the conversion
$this->trackLead([
'form_name' => 'contact_form',
'lead_type' => 'contact',
]);
$this->success = true;
}
}