Yes, there is a package available for this called "matomo-tracker". You can use this package to track events in your Laravel application using Matomo. Here's how you can use it:
- Install the package using composer:
composer require matomo/matomo-tracker
- In your controller, you can create a new Matomo tracker object and track the event like this:
use Matomo\Tracker;
$tracker = new Tracker($idSite = 1, $apiUrl = 'http://your-matomo-url.com/matomo.php');
$tracker->doTrackEvent('Contact', 'Email Link Click', '[email protected]');
- You can then pass this data to your view using the
viewmethod in your controller:
return view('your-view')->with('tracker', $tracker);
- In your blade layout, you can then use the
@pushdirective to push the tracking code to the page:
@push('scripts')
<script type="text/javascript">
_paq.push(['trackEvent', '{{ $tracker->getEventCategory() }}', '{{ $tracker->getEventAction() }}', '{{ $tracker->getEventName() }}']);
</script>
@endpush
This will push the tracking code to the page, using the data that you tracked in your controller.