roundly-consulting / plausible-for-laravel
Plausible Analytics API client for Laravel
Package info
github.com/roundly-consulting/plausible-for-laravel
pkg:composer/roundly-consulting/plausible-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- ext-bcmath: *
- illuminate/contracts: ^12.0|^13.0
- illuminate/http: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/http-client-rate-limits-for-laravel: ^1.0
- roundly-consulting/money-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.8|^9.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Plausible for Laravel
A clean, expressive client for the Plausible Analytics API. Query your stats, capture custom events server-side, and manage sites from your Laravel application through a fluent, strongly-typed API — no manual HTTP plumbing required.
Installation
Requires PHP 8.4 (ext-bcmath), Laravel 12 or 13, and a Plausible account (Cloud or self-hosted).
composer require roundly-consulting/plausible-for-laravel
Set PLAUSIBLE_URL (your Plausible instance, e.g. https://plausible.io), PLAUSIBLE_API_KEY
(a Stats API key — event capture needs none) and PLAUSIBLE_SITE (the default site) in .env.
Usage
Read typed stats with the fluent builder:
use RoundlyConsulting\Plausible\Enums\Metric; use RoundlyConsulting\Plausible\Enums\Property; use RoundlyConsulting\Plausible\Facades\Plausible; $result = Plausible::stats() ->for('my-site.com') ->metrics(Metric::Visitors, Metric::Pageviews) ->last30Days() ->compare() ->aggregate(); // -> AggregateResult $result->metric(Metric::Visitors); // 2001 $result->change(Metric::Visitors); // 30 — the change vs the previous 30 days $sources = Plausible::stats()->for('my-site.com')->last7Days() ->breakdown(Property::VisitSource) ->rows(); // list<BreakdownRow>
Capture a conversion server-side — the visitor comes from the request, the site from
PLAUSIBLE_SITE:
use RoundlyConsulting\Plausible\DataTransferObjects\Revenue; Plausible::events()->fromRequest(request())->event( 'Signup', url: url('/register'), props: ['plan' => 'pro'], revenue: Revenue::of('49.00', 'EUR'), );
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/plausible-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). Please see License File for more information.