Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track Custom Variables error: Warning - count(): Parameter must be an array or an object that implements Countable #16596

Closed
basos9 opened this issue Oct 20, 2020 · 11 comments · Fixed by matomo-org/developer-documentation#392
Labels
Bug For errors / faults / flaws / inconsistencies etc. wontfix If you can reproduce this issue, please reopen the issue or create a new one describing it.

Comments

@basos9
Copy link

basos9 commented Oct 20, 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(),#1/core/Tracker/Request.php(635),#2/core/Tracker/Action.php(191),#3/plugins/CustomVariables/Tracker/CustomVariablesRequestProcessor.php(76),#4/core/Tracker/Visit.php(174),#5/core/Tracker.php(155),#6/core/Tracker/Handler.php(57),#7/core/Tracker.php(135),#8/core/Tracker.php(112),#9/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 tsteur added Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. labels Oct 20, 2020
@tsteur
Copy link
Member

tsteur commented Oct 20, 2020

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

@basos9
Copy link
Author

basos9 commented Oct 21, 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
Copy link
Author

basos9 commented Oct 21, 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
Copy link
Member

tsteur commented Oct 21, 2020

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

@basos9
Copy link
Author

basos9 commented Oct 29, 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
Copy link
Member

tsteur commented Oct 29, 2020

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

@basos9
Copy link
Author

basos9 commented Oct 30, 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 Findus23 removed the Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. label Oct 30, 2020
@Findus23
Copy link
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
Copy link
Member

tsteur commented Nov 1, 2020

See eg #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
Copy link
Author

basos9 commented Nov 2, 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 tsteur added the wontfix If you can reproduce this issue, please reopen the issue or create a new one describing it. label Nov 2, 2020
tsteur added a commit to matomo-org/developer-documentation that referenced this issue Nov 2, 2020
@tsteur
Copy link
Member

tsteur commented Nov 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. wontfix If you can reproduce this issue, please reopen the issue or create a new one describing it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants