Without the facade
The facade is the recommended default, not the only way in. It is sugar over RoundlyConsulting\Plausible\PlausibleManager — the facade root, bound as a container singleton. Inject the manager through the constructor for the same API as an explicit dependency with no static calls, or call the plausible() helper, which returns the same instance:
use RoundlyConsulting\Plausible\PlausibleManager;
final class DashboardController
{
public function __construct(private PlausibleManager $plausible) {}
public function __invoke()
{
return $this->plausible->stats()->for('my-site.com')->last30Days()->aggregate();
}
}
plausible()->sites()->list(); // the helper returns the same singletonResource clients instead of actions
Plausible is a remote API, so there are no action classes: each area is a resource client resolved from the container, which you can also inject or rebind directly:
| Facade method | Resource client | Covers |
|---|---|---|
stats() | Repositories\StatsRepository | Fluent builder, explicit requests, Stats v2 run(). |
events() | Repositories\EventsRepository | Pageviews, custom events, queued and batched capture. |
sites() | Repositories\SitesRepository | create, get, list, update, delete. |
goals() | Repositories\GoalsRepository | create, list, delete. |
sharedLinks() | Repositories\SharedLinksRepository | create, createFrom. |
Plausible::fake() replaces the manager behind the facade and in the container, so an injected PlausibleManager and plausible() are recorded too. Go through the manager when you want a call to show up in the fake’s assertions.
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.