---
title: "Automatic pageviews — Plausible for Laravel | Roundly"
description: "The plausible.track middleware records server-side pageviews for successful HTML GET responses, after the response is sent."
url: https://roundly-consulting.com/open-source/docs/plausible-for-laravel/pageview-tracking
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Plausible for Laravel](https://roundly-consulting.com/open-source/docs/plausible-for-laravel.md)

# 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:

```php
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:

```php
// 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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/plausible-for-laravel.md)
