Creating a plugin to import external and independant data, a social media example

There is not yet any core feature which allow you to import independant and external data within Matomo Analytics. So far, what you can do is to import visits from the outside within Matomo which can be problematic in the case of social media when someone is visiting your social media account though is not redirected on your website.

You may be interested to view the data directly within the social media account, but you may also be interested in concatenating all those data within Matomo in order to have Matomo acting as a data visualization software.

In this tutorial we are going to see how to proceed, this action is currently a bit complex but we will do our best to make it as less complicated as possible.

Here is what we would like to get:

A report showing the evolution of impressions overtime from a Linkedin page. Linkedin provides those data like this:


date impressions
2020-01-01 528
2020-01-02 824

The idea is then to understand how to create a table within Matomo in order to import the data within it and how we can create the report within the UI in order to browse it and change the dates accordingly.

Getting started

Matomo provides you with a great documentation in order to get started at https://developer.matomo.org/guides/getting-started-part-1.

The first part is to create the plugin (every new feature is a plugin in Matomo), so let's perform:

sudo ./console generate:plugin --name="LinkedinImport"

It will ask you for a description, I entered:

"Allows you to use Linkedin data such as date and impressions within Matomo Analytics."

It will ask you for a version, I leave it empty. The plugin is now created.

Then you activate the plugin with:

sudo ./console plugin:activate LinkedinImport

at this stage, the plugin is created. Let's see how to create the report to see it within the UI of Matomo.

It refers to the following documentation: https://developer.matomo.org/guides/custom-reports.

So first execute:

sudo ./console generate:report

Then to the question, name of your plugin answer:

LinkedinImport

Then enter the name of your plugin, in my case:

Linkedin impressions

In which category, you would like to appear, in my case it is Acquisition as it somehow belong to potential traffic:

Referrers_Referrers (at the time of this writing this value is not available within the drop-down menu).

Regarding the documentation part I mentioned:

A report showing the evolution of impressions over dates.

Enter the report dimension, in my case I don't have any as it is based on metrics only, so I leave it empty.

Congratulations your report is now created.

In order to add this new report to a category we need to make it visible within the menu, to do so you need to access to the following file:

sudo nano /matomo/plugins/LinkedinImport/Reports/GetLinkedinimpressions.php

and uncomment and edit this line accordingly:

$this->subcategoryId = $this->name;

Ok here is what we have so far:

Making it as a widget

There is nothing to do here. Wigdet is getting automatically created for the dashboard:

Filling in Matomo's database with some data

Ok, so here what I did is that I went on Linkedin and I exported the performances of my account. It is giving me data in a CSV format which definitely fit my needs. Then I just reprocessed the file in order to just have the dates and the number of impressions per day.

Then, I went on the Matomo's database and I created a table with the following columns:

  • date as a date
  • impressions as varchar with a lenght of 255.

I orginally named the table matomo_linkedin.

Then I filled the data like this on a CSV file:

then I am using the phpMyadmin feature to import a CSV within my matomo_linkedin table:

ended results is:

About methods

Within Matomo the result of your report is what we call a method, simply said it corresponds to the list of features you can find here: https://developer.matomo.org/api-reference/reporting-api#api-method-list so to say the reporting API or any other method you would like to develop.


Last modified: Saturday, 23 May 2020, 9:28 AM