NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

Open source

Plausible for Laravel

Install
composer require roundly-consulting/plausible-for-laravel
Requires: PHP ^8.4 · Laravel ^12.0|^13.0

Overview

A clean, expressive client for the Plausible Analytics API — Cloud or self-hosted. Read your stats through a fluent, strongly-typed builder, capture server-side events and exact revenue, track pageviews and model events without writing tracking code, and provision sites, goals and shared links from your Laravel app. MIT-licensed and built only on official Laravel components plus four small Roundly companion packages — no third-party analytics SDK.

What you get

Fluent, typed stats

Realtime, aggregate, timeseries and breakdown reads through one fluent builder that returns typed result objects.

Stats v2 queries

Dimensions, type-safe where()/orWhere() filters, ordering and pagination against the /api/v2/query endpoint.

Server-side events

Capture pageviews and custom events from the backend — synchronously, on the queue, or as a single job batch.

Exact revenue

Revenue is a money-for-laravel Money, sent as an exact decimal string. Currencies Plausible can’t convert are refused up front.

Tracking without tracking code

A pageview middleware, a Trackable model trait, and the hosted script via @plausibleScript or Plausible::script().

Site provisioning

Create, update and delete sites, goals and shared dashboard links from code — built for multi-tenant products.

Rate limits & a test fake

Per-surface client-side rate limiting with adaptive 429 backoff, plus a recording Plausible::fake() for your tests.

Documentation

Installation

Install via Composer, set three env variables and verify the connection with one Artisan command.

Configuration

Every config key, its default and its env variable — instance, default site, HTTP, rate limits, tracking and script.

The Plausible facade

The Plausible facade: one resource client per API area — stats, events, sites, goals, shared links — plus script, ping and health.

Without the facade

Skip the facade: inject PlausibleManager or call the plausible() helper — and why there are resource clients instead of actions.

Querying stats

Read realtime visitors, aggregates, timeseries and breakdowns through the fluent builder, with typed results and period shortcuts.

Filters

Type-safe where()/orWhere() filters for Stats v2, custom-property filters, and the raw v1 string and v2 array forms.

Stats v2 queries

Drive the /api/v2/query endpoint with dimensions, ordering, includes and pagination, and read positional QueryResult rows.

Caching, collections & pagination

Cache any stats read by query signature, turn results into Collections, and walk every breakdown page with cursor() or each().

Explicit request objects

Build AggregateRequest, TimeseriesRequest and BreakdownRequest yourself and get the raw Response or a typed result.

Capturing events

Send pageviews and custom events server-side — synchronously, on the queue, or as a batch — with the visitor Plausible needs.

Revenue

Attach exact revenue to events as a money-for-laravel Money — decimal strings, no floats, invalid currencies refused up front.

Automatic pageviews

The plausible.track middleware records server-side pageviews for successful HTML GET responses, after the response is sent.

Model events (Trackable)

Emit Plausible events on Eloquent lifecycle hooks with the Trackable trait — custom props, URL and site per model.

Tracking script

Render the official hosted Plausible script with @plausibleScript or <x-plausible-script>, configured from one place.

Sites, goals & shared links

Provision Plausible sites, conversion goals and shareable dashboard links from code — typed results, one rate-limit bucket.

Enums

Type-safe metrics, periods, intervals, properties, dimensions, operators and goal types, with enums-for-laravel helpers.

Rate limiting

Per-surface client-side rate limits for stats, events and sites, with adaptive 429 backoff, fail-fast and shared budgets.

Health check

Check configuration and API connectivity without throwing — ping(), health() and the plausible:health Artisan command.

Exceptions

The PlausibleException hierarchy — configuration, visitor, revenue and rate-limit errors — and how HTTP failures surface.

Testing

Swap the client for a recording Plausible::fake() — no real HTTP — and assert on captured events, stats queries and provisioning.

Requirements

PHP 8.4+ with ext-bcmath, Laravel 12 or 13, and a Plausible account — a Stats or Sites API key, or no key just to capture events.

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 crypto

By 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.