PHP code example of visualappeal / piwik-php-api

1. Go to this page and download the library: Download visualappeal/piwik-php-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

visualappeal / piwik-php-api example snippets




use VisualAppeal\Matomo;

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

$matomo->reset();

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

$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

$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

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

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

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

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

Matomo::FORMAT_XML
Matomo::FORMAT_JSON
Matomo::FORMAT_CSV
Matomo::FORMAT_TSV
Matomo::FORMAT_HTML
Matomo::FORMAT_RSS
Matomo::FORMAT_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();