Maybe I'm missing something here, but in Google Analytics V3 (analytics.js or gtag.js) setting the transport
or transport_type
to beacon
would make the request to google-analytics.com/x/collect
be sent using POST, i.e. no GET-parameters would be shown in the request URL.
When using GA4 (and a G- measurement ID) setting this parameter does nothing. This is what my tracking code looks like:
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXX', {"transport_type":"beacon"});
Am I doing something wrong, or am I simply misinterpreting how the beacon
works in GA4? If the latter, is there any way to make GA4 function in a similar manner? What I'd like to achieve is send requests, that look like:
https://www.google-analytics.com/g/collect
As opposed to:
https://www.google-analytics.com/g/collect?param=1¶m_2=2&etc=etc
Hopefully someone'll be able to help me out, as the documentation is very limited ATM.
In Firefox in Network section of developer tools you can see the initiator of hit, and it say the way how hit was sent. If you see something like js.56 (beacon)
you can be sure that hit was sent via navigator.sendBeacon()
method of Beacon API
Setting parameter transport_type
to beacon
indeed do nothing, because ga4 hits are sent using this method by default.