Giter Club home page Giter Club logo

matomo-reporting-api's Introduction

Matomo Reporting API

(former Piwik Reporting API)

This library allows to retrieve data from the Matomo open source web analytics platform using the Matomo Reporting API using PHP.

Usage

<?php

use Matomo\ReportingApi\QueryFactory;

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

// The URL of the Matomo server. *Always use HTTPS!*
$matomo_url = 'https://my.matomo.server';

// The user authentication token. You can get it in the web interface of the
// Matomo server at Administration > Platform > API.
$token = 'e0357ffdf830ca8be8af4151b564b53d';

// Instantiate the query factory. This class helps to quickly generate
// different query objects with reusable default parameters.
$query_factory = QueryFactory::create($matomo_url);

// Set some default parameters such as the site ID and user authentication
// token. 
$query_factory
    ->set('idSite', 1)
    ->set('token_auth', $token);

// Example: retrieve the version of the Matomo server.
$query = $query_factory->getQuery('API.getMatomoVersion');
$response = $query->execute()->getResponse();
$matomo_version = $response->value;

echo "Server is running Matomo $matomo_version.\n\n";

// Example: retrieve browser usage statistics for the past week.
$response = $query_factory->getQuery('DevicesDetection.getBrowsers')
  ->setParameter('date', 'today')
  ->setParameter('period', 'week')
  ->execute()
  ->getResponse();

foreach ($response as $browser) {
  echo "Browser: {$browser->label}\n";
  echo "Total visits: {$browser->nb_visits}\n";
  echo "Bounce count: {$browser->bounce_count}\n";
  echo "Daily unique visitors: {$browser->sum_daily_nb_uniq_visitors}\n\n";
}

For the full list of available methods, see the Matomo API reference.

Security

The Matomo Reporting API uses a user authentication token to access the API. The API is very powerful and allows to view, edit and delete most data, even add and remove users. This means that the user authentication token should be kept as secret as your username and password.

Since the token is sent over the network it is crucial that all network traffic to the Matomo API is encrypted. You can use an unencrypted HTTP URL during testing, but for a production server it is highly recommended to use HTTPS or it will be possible for an attacker to steal your credentials and lock you out of your Matomo server.

matomo-reporting-api's People

Contributors

claudiu-cristea avatar idimopoulos avatar pfrenssen 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.