devarts/plausible-php

A PHP wrapper for using Plausible API

v4.0.1 2024-07-21 21:22 UTC

This package is auto-updated.

Last update: 2024-10-22 19:39:03 UTC


README

Build Status Latest Stable Version PHP Version Require License

The library provides access to the Plausible API from applications written in the PHP language. It includes a pre-defined set of classes for API resources that initialize themselves from API responses.

Install

Via Composer

$ composer require devarts/plausible-php

Usage

Simple usage looks like:

use Devarts\PlausiblePHP\Configuration;
use Devarts\PlausiblePHP\PlausibleApi;
use Devarts\PlausiblePHP\Support\Metric;
use Devarts\PlausiblePHP\Support\Filter;

$plausible = new PlausibleApi(Configuration::create('plausible_api_token'));

$metrics = Metric::create()
    ->addBounceRate()
    ->addVisitors();

$filters = Filter::create()
    ->addVisitBrowser('Chrome', Filter::NOT_EQUAL);

$result = $plausible->stats()->getAggregate('example.com', [
    'metrics' => $metrics,
    'filters' => $filters,
]);

echo $result->bounce_rate->value;

Credits

License

The MIT License (MIT). Please see License File for more information.