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.66k stars 2.62k forks source link

Wrong content-type in multi-event matomo-call #20791

Open dahiro opened 1 year ago

dahiro commented 1 year ago

Context

I postet this question already in the forum, but with no feedback so far

We try to use matomo for video/multimedia analytics. Unfortunately not all events are reported to our backend. We found out that there are two types of calls to our tracking backend:

  1. POST request with get query parameters => works OK
  2. POST request with request body (I assume this is multi-event tracking, right?) is answered with a 400 return code in our reverse-proxy

Current Behavior

The issue with 2. ist, that the content-type-header of the request (application/x-www-form-urlencoded) does not correspond to the actual content (application/json or plain/text).

Did anybody else experience this issue and/or has a solution?

Expected Behavior

The POST requests with a request body should have a parsable content-type, like plain/text or application/json

Possible Solution

We tried to set the following, but with no success: _paq.push([‘setRequestContentType’, ‘plain/text; charset=utf-8’]);

Steps to Reproduce (for Bugs)

I don't know exactly when a multi-event-call (is this even the right term?) is triggered.

Your Environment

MatomoForumNotifications commented 1 year ago

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/wrong-content-type-in-multi-event-matomo-call/51381/2

romanimm commented 1 year ago

Having the same issue.

Looks like this can be fixed relatively easy. sendBulkRequest produces a json, and sendXmlHttpRequest / sendPostRequestViaSendBeacon does not accept a way to set the content type header. So the content type header is wrong for all sendBulkRequet. The other way I see, to fix this issue, would be to send application/x-www-form-urlencoded data for sendBulkRequest.

https://github.com/matomo-org/matomo/blob/d13d4c4db7be2625e2aedf415f58de9bcb70a81b/js/piwik.js#L3216C47-L3216C47

sgiehl commented 1 year ago

Sending the correct content-type is indeed something we should do for bulk requests.

inbasekarandev commented 9 months ago

hey try this

_paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); _paq.push(['setRequestContentType', 'text/plain; charset=utf-8']);

you have to use 'text/plain; charset=utf-8'