NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Plausible for Laravel

Automatic pageviews

Apply the plausible.track middleware to track server-side pageviews automatically. It uses the configured default site — override it per route with plausible.track:your-site:

use Illuminate\Support\Facades\Route;

Route::middleware('plausible.track')->group(function () {
    Route::get('/', HomeController::class);
    Route::get('/pricing', PricingController::class);
});

// Track a route against a different site than the default
Route::get('/docs', DocsController::class)->middleware('plausible.track:docs.my-site.com');

The middleware does its work in terminate(), after the response has been sent, and only records:

  • GET requests;
  • requests that are not AJAX and don’t expect JSON;
  • successful responses (status below 300);
  • responses with a text/html Content-Type.

Each pageview carries the full URL, the Referer header as its referrer, and the visitor lifted from the request. When no site is configured or passed, the middleware silently skips — so it is safe to apply broadly.

Every web route

Append the middleware class to the web group to track the whole site:

// bootstrap/app.php — track every route in the web group
use Illuminate\Foundation\Configuration\Middleware;
use RoundlyConsulting\Plausible\Http\Middleware\TrackPageview;

->withMiddleware(function (Middleware $middleware): void {
    $middleware->web(append: [TrackPageview::class]);
})

Captures are queued by default (plausible.tracking.queue). Set PLAUSIBLE_TRACKING_QUEUE=false (or off, no, 0) to send them synchronously in terminate() instead.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.