-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add custom header to all the http calls make by matomojs. #16076
Comments
@SARAVANA1501 you mean in the JS tracking request (going eg to matomo.php endpoint?) |
Yeah |
That's not possible just yet unless you manage to intercept these any XmlHttpRequest or maybe using service workers. Alternatively, you could create a PR that adds this feature. |
If provide a some technical detail to begin, I am glad to start. |
It's hard to give much technical detail there. Basically, you want to look at the Add some public method that can be called similar to how eg You'd store this in a say These custom headers you would need apply to the method in To have this working you would also need to force using POST requests by calling You would later configure the headers like @Findus23 @mattab do we see any issues with allowing people to send custom headers? I suppose if there's an XSS on the site or ad blockers they could configure any random custom headers but I suppose they could also just send the XmlHttpRequest to the Matomo directly if they wanted in that case. Wondering if this was maybe better done in a custom tracker plugin see https://developer.matomo.org/guides/enrich-js-tracker in which case I would give you different instructions @SARAVANA1501 |
@SARAVANA1501 sounds good, feel free to create a PR and we will review it eventually 👍 Also check to include automated tests in the file: https://github.com/matomo-org/matomo/blob/4.x-dev/tests/javascript/index.php. Thanks for your consideration! |
@tsteur What about |
@SARAVANA1501 that could work to have this in the JS tracker. Not sure though what you mean by "for scripts generated by tag manager"? |
@tsteur While creating container in tag-manager, it is generating tracker js file. we have to configure page with container similar to below snippet Is it possible to add similar "setCustomRequestHeader" function on these generated files? |
If it's added to the Matomo JS tracker in https://github.com/matomo-org/matomo/blob/4.x-dev/js/piwik.js then it will automatically also be included in the tag manager since the tag manager embeds the JS tracking code automatically. |
Hello, This is actually a critical one for us. We would really like to use |
@joelcoxokc This hasn't been implemented yet, and there are no current plans to do so. Also implementing this might need some additional effort. By default Matomo tries to send it's requests using |
@sgiehl I have been digging through the code to see if I could implement it for you. afaik and XMLHttpRequest do not support setting headers? I understand that you are requesting the matomo.js Is it possible to add custom headers to those individual tracking events? |
I see this line, and am wondering if it's possible to tap into this add add an additional header Line 2916 in cc2ff14
|
The header might need to be set at that place. But there need to be methods added to allow providing the headers to be set. In addition as soon as a custom header is set, the sendbeacon method needs to be disabled, as it doesn't support additional headers. |
Have same problem |
We are hosting Matomo behind gateway service, which is capable of exposing part of matomo endpoint to internet. We need to authenticate every request by certain custom header. The token is available in website cookie which we are trying to track. Is it possible to add that token or key in every request made by matomojs?
The text was updated successfully, but these errors were encountered: