Matomo 400 Bad Request

(khushboo) #1


I have added below code for on play button click event for video.
onclick="_paq.push([‘trackEvent’, ‘Video Content’, ‘Play’, ‘Video Title’]);"

Now when I click on play button, it sends a request to piwik.php file with below url: url &_id=0fc5f88e80aad80f&_idts=1529302030&_idvc=1&_idn=0&_refts=0&_viewts=1529302030&cs=windows-1252&send_image=1&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=0&java=0&gears=0&ag=0&cookie=1&res=1280x720&gt_ms=127&pv_id=bC8UVL

But this url returns 400 Bad Request. Kindly suggest, what can be done to resolve the issue.
Thanks in advance.


Hi guys i have a question plzzzz help meee?
(Fabian Dellwing) #2

Any exceptions in the webserver errorlog?

(khushboo) #3

Thanks for reply. Below is error log lines
connect() to unix:/run/php/php7.1-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client.

Now I restarted fpm and I can access admin interface. Also regular matomo tracking code is working, please find the below url, it gives status 200 : &_id=ac6e36563743e258&_idts=1529054724&_idvc=2&_idn=0&_refts=0&_viewts=1529320383&cs=windows-1252&send_image=1&pdf=0&qt=0&realp=0&wma=0&dir=0&fla=1&java=0&gears=0&ag=0&cookie=1&res=1280x720&gt_ms=123&pv_id=5nhGLB

But when I click on play button with onclick="_paq.push([‘trackEvent’, ‘Video Content’, ‘Play’, ‘Video Title’]);" it again gives 400 Bad request.

My understanding is trackEvent is a matomo (in-built) function, I need not to define this function. Please suggest if there is another way to track click based events.


(Lukas Winkler) #4


php-fpm should never crash. Can you check the php error log if there is a reason why it isn’t working?

(khushboo) #5


Below is phpfpm error log:

[18-Jun-2018 11:16:08] WARNING: [pool www] server reached pm.max_children settin g (5), consider raising it

(Fabian Dellwing) #6

Did the fpm crashed again after clicking the button? Or do you have another message in the webserver errorlog?

(khushboo) #7

Now I’m getting 502 Bad Gateway error for all the requests. Even I cannot log into matomo interface. It display login screen and dashboard. But as soon as I click on any link it gives 502 Bad Gateway error and then I’m unable to access the page.

(Fabian Dellwing) #8

There has to be something really broken with your server that seems unrelated to Matomo.

(khushboo) #9

I have resolved 502 Bad Gateway error now.
Kindly suggest on onclick="_paq.push([‘trackEvent’, ‘Video Content’, ‘Play’, ‘Video Title’]);"
issue. Why this trackEvent is not working.

My understanding is trackEvent is a matomo (in-built) function, I need not to define this function. Please suggest if there is another way to track click based events.


(Roddy A. Stegemann) #10

Sometimes the obvious is overlooked for the simple reason that it is obvious. So, please allow me to ask whether the _paq array has been properly defined in your Matomo source code at the bottom of your webpage.


(Peterbo) #11

Is there something on your server that can block requests? e.g. mod_security

(khushboo) #12

Yes _paq is defined, I have added matomo code on top of page

(Roddy A. Stegemann) #13

A bad request is often caused by a faulty query string. I have checked your formatting and found nothing wrong with it except, of course, the value of the &url parameter.

    &url= 1 url 

This said, if formatting is not a problem, then it might be that you are sending a parameter or even several parameters that Matomo does not know who to handle for the type of request being sent. Your parameter list appears very long, and I cannot help, but think that you are sending parameters that are either unnecessary for your counting objective or even wrong.

Alternatively the value of a parameter or several parameters could be mis-specified.

Finally, could it be that you have not installed the plug-in necessary to handle the type of request being sent?

If I were in your position, I would strip the list to its bare minimum and determine whether it works. If the bare minimum works, then the problem is with your query string. If the bare minimum does not work, then the problem likely lies beyond Matomo.


p.s. Make sure that your HTTPRequest is not sent until the _paq variable is completely loaded. I place my Matomo script at the bottom of my page.

(khushboo) #14

Thanks for your reply.
In my opinion these query parameters are by default added by matomo script for when we use onclick="_paq.push([‘trackEvent’, ‘Video Content’, ‘Play’, ‘Video Title’]);"

url parameter, I have updated to hide page url.

Can you suggest what plugins need to be installed to use trackEvent in matomo.


(Peterbo) #16

What is the exact request that triggers the bad request response?

(Roddy A. Stegemann) #17

To the best of my knowledge no special plug-in is required for the trackEvent( ) method that is not included in the CORE Plugin folder.

If the parameters shown were generated entirely by Matomo, then I have nothing more to say about the query-string as a source your bad request.

Did you try placing your Matomo script at the bottom of your document? I place mine between the </body> and </html> tag.