How does Matomo Analytics work?

So as most of analytics tools Matomo works with:

  • JavaScript.
  • Cookies.

Note though that JavaScript is not the only technology which can be used and data can be sent without cookies too, but as JavaScript is offering more possibilities in terms of data collection than other programming languages and as cookies allow you to have more interesting data too, that's the reason why most analytics tools are using both of them.

About the Javascript

The JavaScript is here in order to send the data to the Matomo's database (so to say your MySQL database). In fact when you analyze the following tracking code:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//localhost/matomo/piwik/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '34']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

As you can see from the code above, there is a file named matomo.php, this file is here in order to send all the data that the matomo.js tracker collected about the internet user when this script has been loaded.

About the cookies

Cookies are here in order to store values for Matomo to be able to record data with more consistency.

By default, Matomo is storing 3 cookies on the browser of the internet user:

  • _pk_id: to store the visitor id of the internet user.
  • _pk_se: to store the visit/session of the internet user.
  • _pk_ref: to store the referrer of the internet, so by which communication channel she/he came.

Let's imagine a scenario in which the cookie _pk_se cannot be set (for example an internet user has a browser extension blocking this cookie), it would mean that every interaction recorded by this given internet user will be consider as a new visit. You could then imagine how fake your data are going to be.

If the _pk_id could not be set, it would mean that the count of visitors will be totally biased too, not though that Matomo has a mechanism named fingerprinting in order to identify the same internet user if they are blocking cookies. It is using a combination of all the attributes of the internet user in order to attribute her/him a given id.

You can easily check the different caracteristics of your cookies within your browser.

How to check that the Matomo tracking code is working and that cookies are well set?

As we just saw, Matomo is working thanks to a tracking code which is sending the data to the Matomo server + setting cookies on the internet user browser.

As a result we can check all that within our Firefox browser by looking at the HTTP requests sent + the cookies. You will find the details of HTTP requests within the network tab and the cookies within the cookies tab.

Last modified: Sunday, 8 September 2019, 5:29 PM