Matomo 400 Bad Request

Hi,

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:
http://my.domain.com/piwik/piwik.php?e_c=Video%20Content&e_a=Play&e_n=Video%20Title&idsite=1&rec=1&r=567550&h=11&m=37&s=27&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.

Regards,
Khushboo

Any exceptions in the webserver errorlog?

1 Like

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 :

https://mydomain.com/piwik/piwik.php?action_name=Video.js%20Test&idsite=1&rec=1&r=587752&h=16&m=43&s=15&url=url &_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.

Regards,
Khushboo

1 Like

Hi,

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

1 Like

Hi,

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

1 Like

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

1 Like

Hi,
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.

1 Like

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

2 Likes

Hi
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.

Thanks.

1 Like

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.

Roddy

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

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

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.

http://my.domain.com/piwik/piwik.php?

    e_c=Video%20Content
    &e_a=Play
    &e_n=Video%20Title
    &idsite=1
    &rec=1
    &r=567550
    &h=11
    &m=37
    &s=27
    &url= 1 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

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.

Roddy

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.

Hi,
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.

Thanks.

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

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.

Roddy

Hi!
i am confront with same problem, but i used c# client for my app.
Did anybody resolve this issue?
I have almost equal request (but after both not view data on dasboard)
ok request:


What i am doing wrong?
matomo backend version: latest (3.8.1) enterprise
I use c# client https://github.com/matomo-org/piwik-dotnet-tracker
i don’t have acess on backend logs :frowning:
P.S.: sorry for my bad english, but i really need done this task

description of problem in post above
bad request:

Resolved in my case. I set token in piwikTracker and he works correctly. (why that error code?)
Hope, this help somebody :grinning:

Thank you so much… I searched for more than an hour. After reading your post I realized that I created a user, created a token and did not assign the right project to that user. :partying_face: