Later, I found out that the interception was caused by different sources caused by iframe. I used the default introduction method of GA to solve it. I needed to configure cookie_flags: 'SameSite=None;Secure'
useEffect(() => {
if (!gaId) return;
const script1 = document.createElement("script");
script1.async = true;
script1.src = `https://www.googletagmanager.com/gtag/js?id=${gaId}`;
document.head.appendChild(script1);
const script2 = document.createElement("script");
script2.innerHTML = `
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', '${gaId}', {
cookie_flags: 'SameSite=None;Secure'
});
`;
document.head.appendChild(script2);
return () => {
document.head.removeChild(script1);
document.head.removeChild(script2);
};
}, [gaId]);