The Plausible facade
Use the Plausible facade — it is registered automatically and is the recommended entry point:
use RoundlyConsulting\Plausible\Facades\Plausible;
Plausible::stats()->for('my-site.com')->last7Days()->aggregate();
Plausible::stats()->query()->last7Days()->aggregate(); // query() = the PLAUSIBLE_SITE default
Plausible::events()->fromRequest(request())->event('Signup', url: url('/register'));
Plausible::script(); // the <script> tag, for any viewThe whole surface
The facade exposes one resource client per API area, plus the tracking-script tag and two health helpers:
use RoundlyConsulting\Plausible\Facades\Plausible;
// One resource client per API area
Plausible::stats(); // StatsRepository — the query API
Plausible::events(); // EventsRepository — event ingestion
Plausible::sites(); // SitesRepository — site provisioning
Plausible::goals(); // GoalsRepository — goal provisioning
Plausible::sharedLinks(); // SharedLinksRepository — shared dashboard links
// Plus three helpers
Plausible::script('my-site.com'); // HtmlString — the tracking-script tag
Plausible::ping(); // bool — reachable AND the key is accepted
Plausible::health('my-site.com'); // HealthResult — configuration and connectivity, never throws| Method | Returns | Purpose |
|---|---|---|
stats() | StatsRepository | Realtime, aggregate, timeseries and breakdown reads, plus the Stats v2 query endpoint. |
events() | EventsRepository | Pageviews and custom events, sent synchronously, on the queue or as a batch. |
sites() | SitesRepository | Create, get, list, update and delete sites. |
goals() | GoalsRepository | Create, list and delete conversion goals. |
sharedLinks() | SharedLinksRepository | Find or create shareable dashboard links. |
script(?$domain) | HtmlString | The hosted tracking-script tag — see Tracking script. |
ping(?$site) | bool | Whether Plausible is reachable and accepts the key — optionally verified against a site. |
health(?$site) | HealthResult | Configuration, connectivity and key acceptance, without throwing — see Health check. |
fake() | PlausibleFake | Swap in the recording fake — see Testing. |
Stats and Sites requests go to your configured url with the API key as a Bearer token; event captures go to the unauthenticated Events API and never carry the key. Every request uses the configured timeout and the optional retry.* retries, and passes through the rate limiter of its surface.
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 cryptoBy 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.