Laravel analytics: three ways to measure
Compare the three ways to add analytics to a Laravel app, then install a server-side package that counts pageviews and events in a few minutes.
Short answer: for Laravel analytics, you can load a browser tag, log requests into your own database with a self-hosted package, or send each pageview from your server to a hosted service. A middleware sees every page Laravel renders, ad blockers included; a script sees what happens inside the page. Many apps end up using both.
What this page says about SimpleStats and Google Analytics was checked on their own pages in December 2026.
Three ways to measure a Laravel app
A browser tag. Google Analytics is the best-known example, added to your Blade layout by hand or through a package. The measurement runs in the visitor's browser, so it depends on the script loading and running. Our Google Analytics alternative page covers that family in detail.
A self-hosted package that logs requests. A middleware writes each request into a table of your own database, and a dashboard reads it back. Nothing leaves your infrastructure. In exchange, you own the storage, the retention, the bot filtering and the queries that turn raw rows into a report.
A hosted service fed from your server. A middleware still sees each request, but it sends a small payload to a service that stores and aggregates it. SimpleStats works this way, and so does Quiet Metrics with its quiet-metrics/laravel-metrics package. You install a Composer package and get a dashboard without running one.
Middleware or script: what each one sees
The choice is less about the vendor than about where the measurement starts.
| Server middleware | Browser script | |
|---|---|---|
| Blocked by ad blockers | No, there is nothing in the page to block | A variable share |
| Needs JavaScript | No | Yes |
| Sees scroll, clicks, SPA navigation | No | Yes |
| Sees pages served from a cache in front of PHP | No | Yes |
| Weight added to the page | None | One script |
Neither column settles the consent question. Moving the request from the browser to the server changes who sends it, not what you do with the data. Whether you need consent depends on your purposes and settings, and the site publisher makes that call. Our page on server-side tracking goes through what it changes and what it does not.
Install the Laravel package in a few minutes
The package works with Laravel 12 and 13 on PHP 8.3 or later. The service provider and the facade register themselves through package discovery.
composer require quiet-metrics/laravel-metrics
Add your site keys to .env:
QUIET_METRICS_PUBLIC_KEY=qm_pub_XXXXXXXXXXXXXXXXX
QUIET_METRICS_SECRET_KEY=qm_sec_XXXXXXXXXXXXXXXX
Then attach the middleware, per route or per group:
Route::middleware('quiet-metrics')->group(function () {
Route::get('/', HomeController::class);
// …
});
Or measure all your web traffic at once:
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->appendToGroup('web', \QuietMetrics\Laravel\Middleware\TrackPageview::class);
})
That is the whole Laravel page view tracking setup. The middleware sends the pageview in terminate(), after the response has gone out, so the visitor does not wait for it. It counts HTML documents served in response to a GET, including 404 and 500 pages raised by your routes. Redirects, JSON, PDFs, attachments, AJAX calls and announced prefetches are left out.
One detail catches people out: with the web group, URLs that match no route are not measured, because Laravel runs no group middleware there. To count them, register the middleware in the global stack instead of the web group, never in both, or every page is counted twice. The Laravel documentation has the snippet.
Why the secret key matters
With the secret key set, every send is signed (HMAC-SHA256 with a timestamp). Only a signed request lets the service take into account the visitor's IP and browser passed in the payload; without it, your server would look like the only visitor. The signature is refused beyond five minutes of clock drift, so keep the server on NTP, and never expose the secret key in the browser or in a public repository.
Before sending, the package reduces the page address to its origin, path and campaign parameters, and the referrer to its origin. A token or an email address in a query string stays on your server.
Track events with the facade
use QuietMetrics\Laravel\Facades\QuietMetrics;
QuietMetrics::event('signup', ['plan' => 'pro']);
From a job, a command or a listener there is no current request, so pass the URL yourself. Without it, nothing is sent:
QuietMetrics::event('import-finished', ['rows' => 1200], [
'url' => 'https://mysite.com/imports',
]);
Sends never throw: a failure is silent by design, so analytics cannot break a page. In your test suite, QuietMetrics::fake() records instead of sending, and you can assert on what was recorded:
QuietMetrics::fake();
$this->post('/register', [...])->assertRedirect();
QuietMetrics::assertEventSent('signup', ['plan' => 'pro']);
QuietMetrics::assertPageviewSent();
Exclude your own visits
Open any page of your site with ?qm_ignore=1. The package sets a first-party qm_ignore cookie, and the server-side SDK stops counting that browser; the script reads the same marker. ?qm_ignore=0 puts you back. The marker holds no identifier and is never sent to us, so only you can remove it, from the same browser.
For staging, the simplest option is to leave the public key empty: without it, nothing is sent.
Run the middleware alongside the script
You can add the qm.js script on top of the middleware, for example on pages a full-page cache serves without running PHP, or to capture SPA navigation and outbound clicks. The service drops a pageview of the same page by the same visitor received less than two seconds after another one, so a page measured by both is counted once.
<script defer src="/qm.js" data-site="qm_pub_XXXXXXXXXXXXXXXXX"></script>
The installation guide explains how to serve the script from your own domain.
When another option fits better
You need revenue attribution. SimpleStats is a Laravel analytics package and service built to follow a visitor through to a signup and a payment, with MRR and churn attributed to the channel that brought each customer. It measures server-side, and its home page also lists a free plan. That is a different job from audience measurement, and they do it well. Our SimpleStats alternative page compares the two.
You want to self-host. SimpleStats publishes its application under the AGPL-3.0 licence and can run on your servers. A package that logs into your own database also keeps everything in-house. We do not offer self-hosting.
You measure behaviour inside the page. Scroll depth, clicks on a component, a form abandoned halfway: a server never sees those. A browser script is the requirement there, not a compromise.
You want visitors counted without storing them. That is what Quiet Metrics is for: a daily salt destroyed every night, an IP address never stored, data hosted in France. The method is published on how we count.
Get started
Create a site, copy the two keys into .env, add the middleware, and the installation screen confirms the first visit it receives. There is a free plan; the pricing page lists what each plan includes and the conditions of the trial.