fix: use beforeInteractive strategy for GTM and GA4

- Changed GTM script from afterInteractive to beforeInteractive
- Changed GA4 scripts to beforeInteractive for earlier loading
- Hardcoded IDs to avoid template literal issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-12-05 13:46:28 +01:00
parent 8fc3851cf7
commit 340aa93c4e

View File

@ -45,8 +45,8 @@ export default function RootLayout({ children }: { children: React.ReactNode })
return ( return (
<html lang="fr"> <html lang="fr">
<head> <head>
{/* Google Tag Manager */} {/* Google Tag Manager - must load first */}
<Script id="google-tag-manager" strategy="afterInteractive"> <Script id="google-tag-manager" strategy="beforeInteractive">
{` {`
(function(w,d,s,l,i){ (function(w,d,s,l,i){
w[l]=w[l]||[]; w[l]=w[l]||[];
@ -57,20 +57,20 @@ export default function RootLayout({ children }: { children: React.ReactNode })
j.async=true; j.async=true;
j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl; j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
f.parentNode.insertBefore(j,f); f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','${GTM_ID}'); })(window,document,'script','dataLayer','GTM-WN8H6RTC');
`} `}
</Script> </Script>
{/* Google Analytics 4 */} {/* Google Analytics 4 */}
<Script <Script
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`} src="https://www.googletagmanager.com/gtag/js?id=G-E272LVVQRD"
strategy="afterInteractive" strategy="beforeInteractive"
/> />
<Script id="google-analytics" strategy="afterInteractive"> <Script id="google-analytics" strategy="beforeInteractive">
{` {`
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);} function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}'); gtag('config', 'G-E272LVVQRD');
`} `}
</Script> </Script>
</head> </head>
@ -78,7 +78,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
{/* Google Tag Manager (noscript) */} {/* Google Tag Manager (noscript) */}
<noscript> <noscript>
<iframe <iframe
src={`https://www.googletagmanager.com/ns.html?id=${GTM_ID}`} src="https://www.googletagmanager.com/ns.html?id=GTM-WN8H6RTC"
height="0" height="0"
width="0" width="0"
style={{ display: 'none', visibility: 'hidden' }} style={{ display: 'none', visibility: 'hidden' }}