Is it possible to send data to the matomo server with a specific header

Dear matomo team and community
We want matomo.js in the browser to send data to the matomo server with a specific header. Is that possible? If so, how? Is there any documentation to refer to?

More background
We want to only collect data from users who are already logged in, putting matomo behind the protection of a gateway
We expect that when matomo sends the collected data, it will take the user’s token from the cookie and put it in the header to pass the gateway validation
Prevent the matomo server from being attacked by logged-in users

I’m currently using this approach for embedding scripts. My project is vue, but I can switch to vue way for embedding scripts if I need to

<! -- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
</script>
<! -- End Matomo Code -->