Exceptions
Every exception the package throws extends RoundlyConsulting\Plausible\Exceptions\PlausibleException, so one catch handles anything from the client:
| Exception | Thrown when |
|---|---|
MissingConfiguration | url is missing on the first call, key is missing on the first Stats or Sites call (event capture works without one), or a call needs a site and none was passed nor configured. |
UniqueVisitorIdentifierRequired | An event is captured (sync, queued or batched) before setVisitor() or fromRequest(). |
InvalidRevenue | A revenue currency or amount is invalid — the money exception is chained as getPrevious(). |
RateLimitExceeded | A throttled request would wait longer than the surface’s max_wait. Carries key and retryAfterSeconds(). |
use Illuminate\Http\Client\RequestException;
use RoundlyConsulting\Plausible\Enums\Metric;
use RoundlyConsulting\Plausible\Exceptions\PlausibleException;
try {
$visitors = Plausible::stats()->query()->last7Days()->aggregate()->metric(Metric::Visitors);
} catch (PlausibleException $e) {
// configuration, visitor, revenue or rate-limit problem raised by the package
} catch (RequestException $e) {
// Plausible answered with a non-2xx status — $e->response holds it
}A malformed setting is the one exception from outside this hierarchy: it throws RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException from the package toolkit, naming the key — an env typo such as PLAUSIBLE_TIMEOUT=five or PLAUSIBLE_STATS_RATELIMIT_PER=hourly. See Configuration.
HTTP failures
HTTP errors are Laravel’s own: a non-2xx response from Plausible throws Illuminate\Http\Client\RequestException — after the rate limiter has recorded any 429 penalty — and a network failure throws Illuminate\Http\Client\ConnectionException. Enable retry.* for transient connection failures.
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.