This package provides a blade view with the script tag for plausible and a wrapper to easily send custom events to Plausible.
You can install the package via composer:
composer require vincentbean/laravel-plausible
You can publish the config file with:
php artisan vendor:publish --provider="VincentBean\Plausible\LaravelPlausibleServiceProvider" --tag="config"
Add the following to your env:
PLAUSIBLE_TRACKING_DOMAIN=DOMAIN_YOU_WANT_TO_TRACK
PLAUSIBLE_DOMAIN=OPTIONAL_IF_SELF_HOSTING
This package supports both client side and server side tracking.
Include the component in your layout to add the plausible script, with optional tracking extensions.
<x-plausible::tracking />
or
<x-plausible::tracking extensions="hash, outbound-links, etc.." />
Plausible will be available on the window object for sending custom events via Javascript:
plausible('event')
Track pageviews server side using middleware.
// app/Http/Kernel.php
'web' => [
// Add this middleware to the web group to track globally
\VincentBean\Plausible\Middleware\TrackPlausiblePageviews::class,
],
You can trigger custom events on the server.
\VincentBean\Plausible\Events\PlausibleEvent::fire('custom event', ['country' => 'netherlands']);
If firing your event from a queued job or event listener, it might be necessary to pass on the user's ip
and user-agent
string which are used by Plausible to generate user session ID's.
\VincentBean\Plausible\Events\PlausibleEvent::fire('custom event', ['country' => 'netherlands'], headers: [
'X-Forwarded-For' => $event->userIp,
'user-agent' => $event->userAgent
]);
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.