All Projects → VisualAppeal → Matomo-PHP-API

VisualAppeal / Matomo-PHP-API

Licence: MIT License
PHP wrapper for the Matomo API.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Matomo-PHP-API

matomo-for-wordpress
Get a fully functioning Matomo Analytics for your WordPress. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Privacy is built-in. 100% data ownership, no one else can see your data. We love Pull Requests!
Stars: ✭ 90 (+15.38%)
Mutual labels:  matomo
nodejs-piwik
Access a Matomo (Piwik) API from node.js
Stars: ✭ 37 (-52.56%)
Mutual labels:  matomo
ngx-matomo
Matomo (aka. Piwik) web analytics for Angular applications
Stars: ✭ 83 (+6.41%)
Mutual labels:  matomo
matomo-tracker
Stand alone library for using matamo tracking in frontend projects
Stars: ✭ 138 (+76.92%)
Mutual labels:  matomo
matomo-next
Matomo for Next.js applications
Stars: ✭ 87 (+11.54%)
Mutual labels:  matomo
ip2location-piwik
Use IP2Location geolocation database to lookup for accurate visitor location in Matomo (Piwik) 3.x. It enables the user to find the country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation, usage type, address type and IAB category that any IP address o…
Stars: ✭ 26 (-66.67%)
Mutual labels:  matomo
matomo-mediawiki-extension
www.mediawiki.org/wiki/Extension:Piwik_Integration
Stars: ✭ 18 (-76.92%)
Mutual labels:  matomo
hugo-component-matomo
Matomo user tracking and optout scripts for Hugo
Stars: ✭ 38 (-51.28%)
Mutual labels:  matomo
gatsby-plugin-matomo
🥂 Gatsby plugin to add Matomo (formerly Piwik) onto a site.
Stars: ✭ 56 (-28.21%)
Mutual labels:  matomo
Matomo
Liberating Web Analytics. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. We love Pull Requests!
Stars: ✭ 15,711 (+20042.31%)
Mutual labels:  matomo

Matomo PHP API

Build Status Packagist

A PHP wrapper class for the Matomo API.

Requirements

  • PHP >= 7.3 (for php 7.2 use version 1.5)
  • 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

When you use the period range you do not need to specify a date!

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();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].