matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.83k stars 2.64k forks source link

[Bug] Inconsistent datatypes from `Events.getAction` #21978

Open alexhebing opened 7 months ago

alexhebing commented 7 months ago

What happened?

We have a self-hosted Matomo that we try to keep up-to-date as much as possible. Our data is being imported into datawarehouse (and subsequently into PowerBI), and this includes event data, that are requested from the Event.getAction API endpoint. Our developer notices inconsistencies in the datatypes. Here is an example of what I mean:

[{
      "label": "xxx",
      "nb_uniq_visitors": 65, 
      "nb_visits": 65, 
      "nb_events": 86, 
      "nb_events_with_value": 0,
      "sum_event_value": 0, 
      "min_event_value": 0, 
      "max_event_value": 0, 
      "avg_event_value": 0, 
      "segment": "eventAction==xxx"
},
 {
      "label": "xxx", 
      "nb_uniq_visitors": 3,
      "nb_visits": "3",                          <- String instead of int
      "nb_events": "4",                       <- String instead of int                  
      "nb_events_with_value": "0",     <- String instead of int
      "sum_event_value": 0,
      "min_event_value": 0, 
      "max_event_value": 0,   
      "avg_event_value": 0, 
      "segment": "eventAction==xxx"
}]

Another example, with some more details. I suspected that this had to do with the major version update from Matomo 4 to 5 that we did at the beginning of the year. Here is a response from the API retrieved in september 2023:

[
    {
        "label": "xxx",
        "nb_uniq_visitors": 3,
        "nb_visits": 3,
        "nb_events": 9,
        "nb_events_with_value": 0,
        "sum_event_value": 0,
        "min_event_value": false,
        "max_event_value": 0,
        "avg_event_value": 0,
        "segment": "eventAction==xxx"
    },
    {
        "label": "xxx",
        "nb_uniq_visitors": 3,
        "nb_visits": 3,
        "nb_events": 7,
        "nb_events_with_value": 0,
        "sum_event_value": 0,
        "min_event_value": false,
        "max_event_value": 0,
        "avg_event_value": 0,
        "segment": "eventAction==xxx"
    }
]

As you can see, this has integer values. Same API, same website, but in february 2024:

[
    {
        "label": "methodStarted",
        "nb_uniq_visitors": 5,
        "nb_visits": "5",                       <!---
        "nb_events": "10",                   <!---
        "nb_events_with_value": "0",   <!---
        "sum_event_value": 0,
        "min_event_value": 0,
        "max_event_value": 0,
        "avg_event_value": 0,
        "segment": "eventAction==methodStarted"
    },
    {
        "label": "situationStarted",
        "nb_uniq_visitors": 5,
        "nb_visits": "5",
        "nb_events": "6",
        "nb_events_with_value": "0",
        "sum_event_value": 0,
        "min_event_value": 0,
        "max_event_value": 0,
        "avg_event_value": 0,
        "segment": "eventAction==situationStarted"
    }
]

Strings instead of integers.

Is this due to the new version? We were unable to find mention of this in the release notes. I also searched the issues here, and the forum, but found no mention of this issue. Any ideas?

Please note that we are always on a recent version of Matomo, i.e. at the moment that is 5.0.2. I don't know exactly which version it was in september 2023, but I suspect that it must have been 4.15.1.

What should happen?

One would expect the datatypes to be consistent, and most of all that nb_ values would actually contain an numeric value, instead of a string.

How can this be reproduced?

I am not sure exactly, but I would suspect requesting the mentioned data from the API in the versions mentioned would produce results like these.

Matomo version

5.0.2

PHP version

8.1.27

Server operating system

Debian 11

What browsers are you seeing the problem on?

Not applicable (e.g. an API call etc.)

Computer operating system

No response

Relevant log output

No response

Validations

mneudert commented 7 months ago

Hi @alexhebing,

sorry this type confusion is causing you trouble. This was not a deliberate change, but probably gone wrong along the way to the new major release.

We will check what happened here and how to fix it.

mikedaul commented 4 months ago

At my job we just noticed this as well having recently upgraded our Matomo instance from 4 to 5.

I can see even in the sample JSON output from the docs that several "nb_vists" and "nb_events" are returned as strings: https://demo.matomo.cloud/?module=API&method=Events.getName&idSite=1&period=day&date=yesterday&format=JSON&token_auth=anonymous