Display Matomo Data in Google Data Studio

  • by
Matomo in DataStudio

In an older report I wrote about the possibility to connect Matomo with Google Data Studio via MySQL Connector. But not everyone can or wants to access the database directly. Therefore, here is a description of how to create a nice report from the data from Matomo with an automated API call in Google Data Studio.

Written by Sebastian Schaubs

To generate a report on the data collected by Matomo and Google Data Studio, the following requirements must be met.

  • A Matomo account and a connection to a Goggle account for Google Data Studio and Google Sheets.

After the accesses are set up, you still have to create the segments in Matomo for the corresponding data. These simply ensure that Matomo receives the data from the correct site. However, in order to be able to insert the first data into a report, you should only start creating the reports the next day.
However, since Google Data Studio cannot work directly with the data from Matomo, the first thing to do is to insert the data into Google Sheets in table form. This is done via CSV files.

Now insert the URL of the CSV file in the script editor of Google Sheets into the following function. However, some changes need to be made to the function in the script editor. These are:

  • Append &convertToUnicode=0 to the CSV URL.
  • Insert the token provided by Matomo (instead of Enter YOUR Token here)
  • Replace the date with date= previous90&period=day
  • and add var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(“browser”); to hand over the correct Sheet name
  • The result will look like this:


function browser() {
  var csvUrl = "https://MATOMO-URL/index.php?date=previous90&period=day&expanded=1&filter_limit=10&format=CSV&idSite=2&language=de&method=DevicesDetection.getBrowsers&module=API&period=day&segment=pageUrl%3D@https%25253A%25252F%25252Fwww.meine-seite.de&token_auth= ENTER YOUR TOKEN HERE&translateColumnNames=1&convertToUnicode=0";
  var csvContent = UrlFetchApp.fetch(csvUrl).getContentText();
  var csvData = Utilities.parseCsv(csvContent);
  var sheet =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("browser");
  sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
  sheet.activate;
}
Apps Script in Google Sheets

After that, the trigger for the automatic update must be added to the clock symbol (within the script editor). To do this, simply create a trigger for each sheet and set the desired parameters (update period, etc.).

The last step is to create the reports in Google Data Studio. The easiest way to do this is to click on New in Google Data Studio and then add a data source. Then simply select Google Sheets, the desired sheet and the desired spreadsheet.
In order to make the data visible graphically, you simply have to add a chart.

Leave a Reply

Your email address will not be published. Required fields are marked *