@basos9 opened this Issue on October 20th 2020

Hello,

It seems that custom variables tracking is not working properly.
The variables are not stored in the databases.
Also with Tracker debug enabled we can see the following error on a tracking request with custom variables

WARNING CustomVariables[2020-10-19 11:52:37 UTC] [e201d] /var/www/matomo/core/Tracker/Request.php(635): Warning - count(): Parameter must be an array or an object that implements Countable - Matomo 3.14.1 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) [internal function]: Piwik\ErrorHandler::errorHandler(),<a href='/1'>#1</a>/core/Tracker/Request.php(635),<a href='/2'>#2</a>/core/Tracker/Action.php(191),<a href='/3'>#3</a>/plugins/CustomVariables/Tracker/CustomVariablesRequestProcessor.php(76),<a href='/4'>#4</a>/core/Tracker/Visit.php(174),<a href='/5'>#5</a>/core/Tracker.php(155),<a href='/6'>#6</a>/core/Tracker/Handler.php(57),<a href='/7'>#7</a>/core/Tracker.php(135),<a href='/8'>#8</a>/core/Tracker.php(112),<a href='/9'>#9</a>/piwik.php(76)

The affected code seems to be

/core/Tracker/Request.php(635)

            if ($id < 1
                || $id > $maxCustomVars
                || count($keyValue) != 2

URL decoded url part for tracking request

&_cvar={"1":"[\"ENV\", \"DEV\"]"}&

ENV

OS debian 10.6
SETUP: NGINX + PHP-FPM
PHP 7.3.19-1~deb10u1 (fpm-fcgi) (built: Jul  5 2020 06:46:45)
Matomo version 3.14.1
Tracking via Javascript Client
@tsteur commented on October 20th 2020 Member

@basos9 thanks for creating this issue. Are you using the Matomo JavaScript tracker? Or how do you track the data?

@basos9 commented on October 21st 2020

Hello,
Yes we are using the Javascript tracking client. The url part mentioned in my comment above, is extracted via the Network tab of the browser's (Chrome) inspect tools (F12)

@basos9 commented on October 21st 2020

And I think I have found a clue.
By looking at the url we can see that the cvar url parameter when url decoded is

`cvar={"5":"[\"PAGEVAR\", \"http://test.com/test.html\"]"}`

and this leads to error in tracking

Now if we change by removing the quotes and make the lvalue of the hash a list (instead of a string), like this

`cvar={"5":["PAGEVAR", "http://test.com/test.html"]}`

And url encode and hit, no error is logged and data starts to appear in the database

               custom_var_k5: PAGEVAR
               custom_var_v5: http://test.com/test.html

So i can assume that it might be a javascript client json encoding issue.

@tsteur commented on October 21st 2020 Member

Thanks for this @basos9 . Do you know in what browser this happens and whether that site maybe overwrites JSON or JSON.stringify?

@basos9 commented on October 29th 2020

Hello,
It happens on major browsers (Chrome, Firefox).
It seems to be related with something in the web page (maybe some JS library), since I was able to successfully track variables by creating a simple html web page with only the tracking code. We are investigating the issue.

@tsteur commented on October 29th 2020 Member

Thanks for investigating. Be great to let us know what you find out.

@basos9 commented on October 30th 2020

For this webpage we tracked to the inclusion of prototype.js library which was included in our web application.

The affected file has a header

Prototype JavaScript framework, version 1.6.0.3

The problem is fixed when we removed this library.

More specifically this library modified (monkey patches) Builtin in Objects like String and Array, defining among others a .toJSON() method.

Another example using the Chrome's browser console on our site

"test".toJSON()
""test""

JSON.stringify(["king","kong"]);
""[\"king\", \"kong\"]""

and on youtube

"test".toJSON()
VM529:1 Uncaught TypeError: "test".toJSON is not a function
    at <anonymous>:1:8

JSON.stringify(["king","kong"]);
"["king","kong"]"
@Findus23 commented on October 30th 2020 Member

That version was released in 2008 meaning it is older than the first release of Internet Explorer 8.

So I guess there is not really much to do as one would need to specifically check for this case which would be weird considering we just dropped support for IE<8.

@tsteur commented on November 1st 2020 Member

See eg https://github.com/matomo-org/matomo/issues/2165 prototype is kind of known actually to have caused issues with JSON and there isn't anything we can do unfortunately. Ideally the project would look at removing this dependency but I understand this is a big ask and not easily done. AFAIK the only other way would be that you overwrite again some of these changes that prototype does. Not sure if we can maybe close this issue but document somewhere this incompatibility or so?

@basos9 commented on November 2nd 2020

It seems that this is a library incompatibility issue and the best would be the things mentioned

  • either remove the library altogether
  • or unpatch the patched buildin objects.

Thank you for helping sort this out.

@tsteur commented on November 2nd 2020 Member

Noticed we haven't actually documented the requirements / supported browsers anywhere for the JS tracker (at least I couldn't find it) so created https://github.com/matomo-org/developer-documentation/pull/392

This Issue was closed on November 3rd 2020
Powered by GitHub Issue Mirror