Skip to content

Analytics

The kit ships a Plausible tag and ships it switched off. With no domain configured, resources/views/app.blade.php draws nothing: no script, no empty tag, no request to anybody. That is the default because it is the only default that is honest, and because analytics is a disclosure your installation makes and not one the kit can make on your behalf.

Turning it on is two environment variables, read by config/analytics.php.

Plausible Cloud

If you signed up at plausible.io, the domain is the site as you registered it there and the script URL is already right:

bash
PLAUSIBLE_DOMAIN=example.com

That is the whole setup. Reload a page and the dashboard has a visitor.

Self-hosted Plausible

A self-hosted instance serves the same script from your own hostname, so point the second variable at it:

bash
PLAUSIBLE_DOMAIN=example.com
PLAUSIBLE_SCRIPT_URL=https://analytics.example.com/js/script.js

The filename is also where Plausible's optional extensions live. Outbound link clicks, file downloads, hashed routes and tagged events each add a segment:

https://analytics.example.com/js/script.outbound-links.tagged-events.js

Copy that URL from Plausible's own installation page rather than assembling it by hand. A filename your instance does not serve is a 404 and then silence, and nothing in the page will tell you.

One site, several hostnames

A product usually lives at more than one hostname: example.com for the marketing site, docs.example.com, app.example.com for the application itself, maybe demo.example.com.

Register one site in Plausible, under the bare name, and give every one of them the same PLAUSIBLE_DOMAIN. Plausible records the real hostname with each pageview, so the dashboard tells them apart on demand while the funnel from the landing page to the signup stays in one place. Three separate properties would split that funnel in three and leave you reconciling them by hand.

Tracking your own events

The blade also draws Plausible's queue stub, so frontend code can send a custom event before the deferred script has finished loading and have the call replayed rather than dropped:

ts
window.plausible?.('Signed Up', { props: { plan: 'pro' } });

Without touching JavaScript at all, you can tag an element by class name. The goal name and its properties travel as classes, with + standing in for a space:

html
<a class="plausible-event-name=Upgrade+Click plausible-event-plan=pro" href="/billing">

Class-based tagging needs the tagged-events extension in your script URL.

A note on privacy

Plausible sets no cookies and stores no personal data, which is why most installations of it need no consent banner. That is a statement about the tool, not legal advice about your installation: which rules apply to you depends on where you and your customers are and on what else the page loads. Review your own obligations, and say what you actually run in the privacy policy the kit gives you at /privacy.

Using something else

config/analytics.php is one file with one if behind it in app.blade.php. Another vendor is a second key in that config and a second block in that view, and the property to keep is the one this file starts with: unconfigured has to mean absent, so that an installation that wants no analytics ships none.

Laraspring is a commercial starter kit. Buying it gets you the source.