Data Whimsy
  • Home
  • What is Matomo
  • Contact
  • Custom Reports
  • Connect Matomo to other software
  • CLI API etc
  • Matomo Tag Manager Simple Guide
  • Lyn Only
  • Troubleshooting + Deploying Matomo
  • Weird Data
  • Why is data in Matomo giving different numbers than Google Analytics
  • The Dashboard
  • Moving the Data
  • Book Club Forum

Without the dashboard

The top slot of your browser can send requests to Tracking API & Reporting API
The command line of your browser can accept direct Matomo input (e.g. the PHP ./console command).
On this page are a variety of things you can do without ever touching the visual dashboard (Matomo GUI)

A manual call to the Reporting API can imitate your dashboard

8/9/2023

0 Comments

 
When you look at the Matomo dashboard, every white square is a widget .  The data that fills that widget is called a report.

Under the hood, every widget is a Vue.js display built from an API call to the Matomo backend (which in turn is building the API return from the MySQL database? 

We will explain below how you can make an API call.
There is a 1:1 correspondance of widgets to API calls you can make. That means any table you see in your dashboard can be run as an API call. And there's a shortcut for building the API call.


Quick review: the main two API's in Matomo are the Tracking API and the Reporting API. Everything we do on this page will be with the Reporting API. 

The simplest method for building any report call to the Reports API is the following:
1. Load the widget (or even load a segment) in the UI
2. Copy the segment definition from the URL, for example:
https://demo.matomo.cloud/index.php?module=CoreHome&action=index&idSite=1&period=day&date=yesterday#?period=day&date=yesterday&category=Dashboard_Dashboard&subcategory=1&segment=countryCode%3D%3Dnz
The segment definition is:
countryCode%3D%3Dnz

3. Add the segment definition to your API query, for example if we look at the Visits Summary API call:
https://demo.matomo.cloud/index.php?module=API&method=VisitsSummary.get&idSite=1&period=day&date=yesterday&format=JSON&token_auth=anonymous
We add: &segment=countryCode%3D%3Dnz
eg:

https://demo.matomo.cloud/index.php?module=API&method=VisitsSummary.get&idSite=1&period=day&date=yesterday&segment=countryCode%3D%3Dnz&format=JSON&token_auth=anonymous



Here is a slower way to do what we just did.
Again, the question is How can I retrieve data for a summary report under a specific "pre-defined segment ID" using the Matomo Reporting HTTP API?
General procedure:
Find the Segment ID.
Find the API call syntax for a report you want. Dashboard >> ⚙️ >> Platform >> API
Build the API, using the syntax guide
Make the call

Specific example, for a segment of "users from Taiwan":
First:
Check your Segment name in the user interface. If you know the segment name, you can get the segment number with this command:
https://example.com/index.php?module=API&method=SegmentEditor.getAll&idSite=1&format=JSON&token_auth=e1240d3392d2c3e6584cf0db64391d62&force_api_session=1
Then:
Find an API request you like, in Dashboard >> ⚙️ >> Platform >> API

Picture

Then:
Build a definition of your segment using this guide: https://developer.matomo.org/api-reference/reporting-api-segmentation
Further syntax advice is here: https://developer.matomo.org/api-reference/reporting-api

Finally:
Make the call to your API. In my case the call is
https://tatll.matomo.cloud/index.php?module=API&method=VisitsSummary.get&idSite=1&period=day&date=yesterday&format=JSON&token_auth=e1240d3392d2c3e6584cf0db64391d62&force_api_session=1&segment=browserCode==CR;countryCode==TW
or in more readable form
https://tatll.matomo.cloud/index.php?module=API&
method=VisitsSummary.get&
idSite=1&
period=day&
date=yesterday&
format=JSON&
token_auth=e1240d3392d2c3e6584cf0db64391d62&
force_api_session=1&
segment=browserCode==CR;countryCode==TW < - - - this is the segment

That last line is the hardest part to build.
0 Comments



Leave a Reply.

    Author

    Evan Genest

    Archives

    November 2024
    August 2024
    May 2024
    March 2024
    February 2024
    November 2023
    October 2023
    September 2023
    August 2023

    Categories

    All

Powered by Create your own unique website with customizable templates.
  • Home
  • What is Matomo
  • Contact
  • Custom Reports
  • Connect Matomo to other software
  • CLI API etc
  • Matomo Tag Manager Simple Guide
  • Lyn Only
  • Troubleshooting + Deploying Matomo
  • Weird Data
  • Why is data in Matomo giving different numbers than Google Analytics
  • The Dashboard
  • Moving the Data
  • Book Club Forum