PHPackages                             rs/matomo-google-charts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rs/matomo-google-charts

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rs/matomo-google-charts
=======================

A package for creating an analytics dashboard using Matomo data and Google Charts

1.0.0(1y ago)0132MITPHPPHP ^8.1

Since Nov 29Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/RedSnapper/matomo-google-charts)[ Packagist](https://packagist.org/packages/rs/matomo-google-charts)[ RSS](/packages/rs-matomo-google-charts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Matomo Google Charts
====================

[](#matomo-google-charts)

A Laravel package for building analytics dashboards using data from [Matomo](https://matomo.org/) and [Google Charts](https://developers.google.com/chart). It fetches analytics data from a Matomo instance, caches it, and transforms it into Google Charts-compatible data structures that can be served as JSON API resources.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10+

Installation
------------

[](#installation)

```
composer require rs/matomo-google-charts
```

The package uses Laravel's auto-discovery, so the service provider and facade are registered automatically.

### Publish the config

[](#publish-the-config)

```
php artisan vendor:publish --provider="RedSnapper\MatomoCharts\MatomoChartServiceProvider" --tag=config
```

This publishes `config/piwik.php`.

### Environment variables

[](#environment-variables)

Add the following to your `.env` file:

```
MATOMO_API_ENABLED=true
MATOMO_API_KEY=your-matomo-token
MATOMO_SITE_ID=1
```

When `MATOMO_API_ENABLED` is `false` (the default), the package uses a fake API implementation that returns empty data, allowing you to develop without a live Matomo connection.

### Configuration

[](#configuration)

The published `config/piwik.php` file contains all available options:

KeyDescriptionDefault`api_enabled`Enable live Matomo API calls`false``piwik_url`Matomo server URL`https://matomo.redsnapper.net``api_key`Matomo authentication token`null``format`API response format (`json`, `xml`, `php`, etc.)`json``period`Default period for API queries`last30``site_id`Default Matomo site ID`null``verify_peer`SSL certificate verification`true``http_timeout`HTTP request timeout (seconds)`500.0`Usage
-----

[](#usage)

### Creating chart types

[](#creating-chart-types)

Define your chart by extending `AnalyticsChart`. Set the chart metadata as properties and override `query()` to fetch data from the Matomo API:

```
use RedSnapper\MatomoCharts\Analytics\Models\AnalyticsChart;
use RedSnapper\MatomoCharts\Analytics\Enums\AnalyticsChartComponent;
use RedSnapper\MatomoCharts\Analytics\Enums\AnalyticsChartStyle;
use RedSnapper\MatomoCharts\Analytics\Enums\AnalyticsChartType;

class BrowserChart extends AnalyticsChart
{
    public string $title = 'Browsers';
    public array $columns = ['Browser', 'Visits'];
    public array $properties = ['label', 'nb_visits'];
    public AnalyticsChartComponent $component = AnalyticsChartComponent::GOOGLE_CHART;
    public AnalyticsChartType $type = AnalyticsChartType::PIE;
    public AnalyticsChartStyle $style = AnalyticsChartStyle::STANDARD;

    public function query(): void
    {
        $this->matomoAPI
            ->setSiteId($this->matomoSiteId)
            ->setDate($this->startDate, $this->endDate);

        $this->data = $this->matomoAPI->fetchBrowserData()->get();
    }

    public function getTextView(): ?View
    {
        return null;
    }
}
```

The `$properties` array maps Matomo response fields to chart columns. The `$columns` array provides the column headings. The base class automatically processes the raw Matomo data into a format compatible with Google Charts.

### Creating mini charts (with comparison)

[](#creating-mini-charts-with-comparison)

Mini charts show a metric with a comparison against a previous period. Extend `AnalyticsMiniChart`:

```
use RedSnapper\MatomoCharts\Analytics\Models\AnalyticsMiniChart;
use RedSnapper\MatomoCharts\Analytics\Enums\AnalyticsChartComponent;
use RedSnapper\MatomoCharts\Analytics\Enums\AnalyticsChartStyle;
use RedSnapper\MatomoCharts\Analytics\Enums\AnalyticsChartType;

class VisitorsMiniChart extends AnalyticsMiniChart
{
    public string $title = 'Total Visitors';
    public array $columns = ['Week', 'Visitors'];
    public array $properties = ['label', 'nb_uniq_visitors'];
    public AnalyticsChartComponent $component = AnalyticsChartComponent::GOOGLE_CHART;
    public AnalyticsChartType $type = AnalyticsChartType::LINE;
    public AnalyticsChartStyle $style = AnalyticsChartStyle::MINI;
    public bool $hasValueComparison = true;

    public function query(): void
    {
        $this->matomoAPI
            ->setSiteId($this->matomoSiteId)
            ->setDate($this->startDate, $this->endDate);

        $this->data = $this->matomoAPI->fetchWeeklyData()->get();

        // Fetch previous period data for comparison
        $this->matomoAPI->setDate($this->preStartDate, $this->preEndDate);
        $this->preData = $this->matomoAPI->fetchWeeklyData()->get();
    }

    public function getTextView(): ?View
    {
        return null;
    }

    public function getStatIcon(): ?string
    {
        return self::ICON_VISITORS;
    }

    public function getComparisonData(): array
    {
        return [
            'value' => $this->data->sum('nb_uniq_visitors'),
            'preValue' => $this->preData->sum('nb_uniq_visitors'),
            'label' => 'visitors',
        ];
    }
}
```

Available icons: `calendar`, `globe`, `monitor`, `views`, `visitors`.

### Using the facade

[](#using-the-facade)

Use the `MatomoChart` facade to create charts and JSON resources in your controllers:

```
use RedSnapper\MatomoCharts\Facades\MatomoChart;

// Get a chart model instance
$chart = MatomoChart::makeChart(BrowserChart::class, $matomoSiteId);

// Get a JSON resource (for API responses)
$resource = MatomoChart::makeChartResource(BrowserChart::class, $matomoSiteId);

// Mini charts
$miniChart = MatomoChart::makeMiniChart(VisitorsMiniChart::class, $matomoSiteId);
$miniResource = MatomoChart::makeMiniChartResource(VisitorsMiniChart::class, $matomoSiteId);
```

### Date filtering

[](#date-filtering)

Date ranges are automatically resolved from the HTTP request query parameters:

ParameterDescriptionDefault`dateFrom`Start date (any Carbon-parseable string)Start of previous month`dateTo`End date (any Carbon-parseable string)End of previous monthA comparison period of equal length is automatically computed from the primary date range.

### Chart resource JSON structure

[](#chart-resource-json-structure)

`AnalyticsChartResource` returns:

```
{
    "style": "standard",
    "title": "Browsers",
    "text": "",
    "component": "GoogleChart",
    "type": "PieChart",
    "data": [
        ["Browser", "Visits"],
        ["Chrome", 1200],
        ["Firefox", 800]
    ],
    "columns": ["Browser", "Visits"],
    "options": {},
    "pageBreakAfter": false
}
```

`AnalyticsMiniChartResource` additionally includes:

```
{
    "comparison": {
        "enabled": true,
        "value": "1,500",
        "preValue": "1,200",
        "difference": "300",
        "label": "visitors"
    },
    "icon": "..."
}
```

### Available chart types

[](#available-chart-types)

EnumGoogle Charts type`AnalyticsChartType::GEO`GeoChart`AnalyticsChartType::COLUMN`ColumnChart`AnalyticsChartType::LINE`LineChart`AnalyticsChartType::PIE`PieChart`AnalyticsChartType::STANDARD_TABLE`StandardTable### Available Matomo data fetchers

[](#available-matomo-data-fetchers)

The `MatomoAPIInterface` provides methods you can use in your chart's `query()` method:

- `fetchWeeklyData()` - Weekly aggregated metrics
- `fetchPageViewData()` - Page URL data
- `fetchCountryData()` - Visitor countries
- `fetchBrowserData()` - Browser breakdown
- `fetchDeviceTypes()` - Device type breakdown
- `fetchOSVersions()` - OS version breakdown
- `fetchDailyVisitorData(Carbon $startDate)` - Visits by day of week
- `fetchHourlyVisitorData(Carbon $startDate)` - Visits by hour
- `fetchWebsiteReferrerData()` - Referring websites
- `fetchSiteSearchKeywordData()` - Site search keywords
- `fetchCampaignData()` - Campaign referral data

All fetch methods are chainable and return a `MatomoCollection` (extended Laravel Collection) via `->get()`.

### Caching

[](#caching)

API responses are automatically cached until midnight using Laravel's cache system. Cache keys are scoped by site ID, segment, and date range to avoid collisions.

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance65

Regular maintenance activity

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

528d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6851104?v=4)[rstechnical](/maintainers/rstechnical)[@rstechnical](https://github.com/rstechnical)

---

Top Contributors

[![joeuk89](https://avatars.githubusercontent.com/u/6736852?v=4)](https://github.com/joeuk89 "joeuk89 (2 commits)")

---

Tags

matomors

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rs-matomo-google-charts/health.svg)

```
[![Health](https://phpackages.com/badges/rs-matomo-google-charts/health.svg)](https://phpackages.com/packages/rs-matomo-google-charts)
```

###  Alternatives

[fof/analytics

Tracks analytics using Google Analytics, Google Optimize/GTM and Matomo

3543.1k](/packages/fof-analytics)[mediawiki/matomo

The Matomo (ex-Piwik) extension inserts your Matomo tracking code to the bottom of every page.

174.5k](/packages/mediawiki-matomo)[moderntribe/tribe-libs

A library for use on Modern Tribe service projects.

1348.8k2](/packages/moderntribe-tribe-libs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
