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

Explicit request objects

The request objects remain available for power users. The repository methods return the raw Illuminate\Http\Client\Response, and the *Result variants — aggregateResult(), timeseriesResult(), breakdownResult() — return the typed object:

use RoundlyConsulting\Plausible\Enums\Interval;
use RoundlyConsulting\Plausible\Enums\Metric;
use RoundlyConsulting\Plausible\Enums\Period;
use RoundlyConsulting\Plausible\Enums\Property;
use RoundlyConsulting\Plausible\Requests\Stats\AggregateRequest;
use RoundlyConsulting\Plausible\Requests\Stats\BreakdownRequest;
use RoundlyConsulting\Plausible\Requests\Stats\TimeseriesRequest;

$response = Plausible::stats()->aggregate(AggregateRequest::make(
    site: 'my-site.com',
    metrics: ['visitors', 'pageviews', 'bounce_rate'],
    compare: true,
));                                                  // Illuminate\Http\Client\Response

$result = Plausible::stats()->aggregateResult(AggregateRequest::make(
    site: 'my-site.com',
    metrics: [Metric::Visitors],
));                                                  // -> AggregateResult

$trend = Plausible::stats()->timeseriesResult(TimeseriesRequest::make(
    site: 'my-site.com',
    metrics: [Metric::Visitors],
    interval: Interval::Week,
    period: Period::SixMonths,
));                                                  // -> TimeseriesResult

$pages = Plausible::stats()->breakdownResult(BreakdownRequest::make(
    site: 'my-site.com',
    property: Property::EventPage,
    filters: ['visit:country==FR'],
    perPage: 50,
));                                                  // -> BreakdownResult

$live = Plausible::stats()->realtime('my-site.com'); // int

Request parameters

Every request has a static make() with named arguments; metrics, periods, intervals and properties accept enums or strings:

Requestmake() parameters and defaults
AggregateRequestsite, metrics = ['visitors'], filters = [], period = '30d', start = null, end = null, compare = false
TimeseriesRequestsite, metrics = ['visitors'], filters = [], interval = 'date', period = '30d', start = null, end = null
BreakdownRequestsite, property, metrics = ['visitors'], filters = [], interval = 'date', period = '30d', start = null, end = null, page = 1, perPage = 100
QueryRequestsite, metrics, dateRange = '30d', dimensions = [], filters = [], orderBy = [], include = [], limit = null, offset = null

With explicit requests, pass period: Period::Custom yourself — only the fluent between() and since() switch the period for you. A custom period with only a start is closed at today (date=start,today); with any other period a lone start is the anchor date (period: 'month', start: 2024-01-01 is January 2024). v1 filters are strings in the legacy syntax, joined with a semicolon.

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.