refactor: update Google Analytics component to use window.gtag for event tracking

This commit is contained in:
CodingOnStar 2025-10-17 17:22:49 +08:00
parent 70600ea861
commit 3d7c7acba6
1 changed files with 4 additions and 5 deletions

View File

@ -34,10 +34,10 @@ const GA: FC<IGAProps> = ({
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaIdMaps[gaType]}');
window.dataLayer = window.dataLayer || [];
window.gtag = function gtag(){window.dataLayer.push(arguments);};
window.gtag('js', new Date());
window.gtag('config', '${gaIdMaps[gaType]}');
`,
}}
nonce={nonce ?? undefined}
@ -56,7 +56,6 @@ gtag('config', '${gaIdMaps[gaType]}');
nonce={nonce ?? undefined}
/>
</>
)
}
export default React.memo(GA)