Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using transport_type "beacon" does not hide parameters in Google Analytics 4

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&param_2=2&etc=etc

Hopefully someone'll be able to help me out, as the documentation is very limited ATM.

like image 812
Daan van den Bergh Avatar asked Oct 19 '25 02:10

Daan van den Bergh


1 Answers

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

enter image description here

Setting parameter transport_type to beacon indeed do nothing, because ga4 hits are sent using this method by default.

like image 108
adamjuraczarnecki Avatar answered Oct 22 '25 05:10

adamjuraczarnecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!