2017 © Pedro Peláez
 

library piwik-php-api

API wrapper for piwik

image

visualappeal/piwik-php-api

API wrapper for piwik

  • Wednesday, November 22, 2017
  • by thelfensdrfer
  • Repository
  • 8 Watchers
  • 43 Stars
  • 26,573 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 18 Forks
  • 1 Open issues
  • 12 Versions
  • 6 % Grown

The README.md

Matomo PHP API

PHPUnit Packagist, (*1)

A PHP wrapper class for the Matomo API., (*2)

Requirements

  • PHP >= 8.0 (for php 7.3/7.4 use version 1.6.1)
  • cUrl (php-curl)
  • JSON (php-json)

Install

This library can be installed via composer: composer require visualappeal/matomo-php-api, (*3)

Usage

Create an instance of matomo

require(__DIR__ . '/vendor/autoload.php');

use VisualAppeal\Matomo;

$matomo = new Matomo('http://stats.example.org', 'my_access_token', 'siteId');

There are some basic parameters (period, date, range) which you can define at the beginning. They do not change until you reset them with, (*4)

$matomo->reset();

So you can execute multiple requests without specifying the parameters again., (*5)

siteId

The ID of your website, single number, list separated through comma "1,4,7", or "all"., (*6)

period

The period you request the statistics for, (*7)

Matomo::PERIOD_DAY
Matomo::PERIOD_WEEK
Matomo::PERIOD_MONTH
Matomo::PERIOD_YEAR
Matomo::PERIOD_RANGE

If you set the period to Matomo::PERIOD_RANGE you can specify the range via, (*8)

$matomo->setRange('2012-01-14', '2012-04-30'); //All data from the first to the last date
$matomo->setRange('2012-01-14', Matomo::DATE_YESTERDAY); //All data from the first date until yesterday
$matomo->setRange('2012-01-14'); //All data from the first date until now

If you set it to something other than Matomo::PERIOD_RANGE you can specify the date via:, (*9)

$matomo->setPeriod(x);
$matomo->setDate('2012-03-03');

Case x of PERIOD_DAY the report is created for the third of march, 2012
Case x of PERIOD_WEEK the report is created for the first week of march, 2012
Case x of PERIOD_MONTH the report is created for march, 2012
Case x of PERIOD_YEAR the report is created for 2012

date

Set the date via, (*10)

$matomo->setDate('YYYY-mm-dd');

Or use the constants, (*11)

$matomo->setDate(Matomo::DATE_TODAY);
$matomo->setDate(Matomo::DATE_YESTERDAY);

Report for the last seven weeks including the current week, (*12)

$matomo->setPeriod(Matomo::PERIOD_WEEK);
$matomo->setDate('last7');

Report for the last 2 years without the current year, (*13)

$matomo->setPeriod(Matomo::PERIOD_YEAR);
$matomo->setDate('previous2');

segment, idSubtable, expanded

For some functions you can specify segment, idSubtable and expanded. Please refer to the matomo segment documentation and to the api reference for more information about these parameters., (*14)

format

Specify a output format via, (*15)

$matomo->setFormat(Matomo::FORMAT_JSON);

JSON is converted with json_decode before returning the request., (*16)

All available formats, (*17)

Matomo::FORMAT_XML
Matomo::FORMAT_JSON
Matomo::FORMAT_CSV
Matomo::FORMAT_TSV
Matomo::FORMAT_HTML
Matomo::FORMAT_RSS
Matomo::FORMAT_PHP

Example

Get all the unique visitors from yesterday:, (*18)

require(__DIR__ . '/vendor/autoload.php');

use VisualAppeal\Matomo;

$matomo = new Matomo('http://stats.example.org', 'my_access_token', 1, Matomo::FORMAT_JSON);

$matomo->setPeriod(Matomo::PERIOD_DAY);
$matomo->setDate(Matomo::DATE_YESTERDAY);

echo 'Unique visitors yesterday: ' . $matomo->getUniqueVisitors();

The Versions

22/11 2017

dev-master

9999999-dev

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

22/11 2017

1.3.0

1.3.0.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

17/08 2017

1.2.3

1.2.3.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

17/09 2016

1.2.2

1.2.2.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

17/09 2016

dev-develop

dev-develop

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

09/11 2015

1.2.1

1.2.1.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4.0
  • ext-curl *

 

The Development Requires

03/05 2015

1.2.0

1.2.0.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4.0

 

The Development Requires

22/03 2015

1.1.2

1.1.2.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

  • php >=5.4.0

 

The Development Requires

18/02 2015

1.1.1

1.1.1.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

13/02 2015

1.1.0

1.1.0.0

API wrapper for piwik

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

13/02 2015

1.0.1

1.0.1.0

  Sources   Download

The Requires

  • php >=5.3.0

 

24/07 2014

1.0.0

1.0.0.0

  Sources   Download

The Requires

  • php >=5.3.0