Git Product home page Git Product logo

matomo-php-api's Introduction

Matomo PHP API

PHPUnit Packagist

A PHP wrapper class for the Matomo API.

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

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

$matomo->reset();

So you can execute multiple requests without specifying the parameters again.

siteId

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

period

The period you request the statistics for

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

$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:

$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

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

Or use the constants

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

Report for the last seven weeks including the current week

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

Report for the last 2 years without the current year

$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.

format

Specify a output format via

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

JSON is converted with json_decode before returning the request.

All available formats

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:

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();

matomo-php-api's People

Contributors

thelfensdrfer avatar hackolein avatar voku avatar teodortalov avatar simonschaufi avatar frofrik avatar bashilbers avatar stayallive avatar axelcho avatar jnngr avatar zhkarl avatar michael2h4ng avatar oparoz avatar webkluns avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.