Hi,
If I delay scripts 3 or seconds, can increase seo ranking and speed up to load website.
I have Google Adsense and Google Analytics.
Can i add below code in footer.php to delay scripts - (code by chatgpt)
<script>
window.addEventListener("load", function() {
setTimeout(function() {
// Google Analytics
var gaScript = document.createElement("script");
gaScript.src = "
https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX";
gaScript.async = true;
document.head.appendChild(gaScript);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
// Google AdSense
var adsScript = document.createElement("script");
adsScript.src = "
https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
adsScript.async = true;
adsScript.setAttribute("data-ad-client", "ca-pub-XXXXXXXXXXXX");
document.head.appendChild(adsScript);
}, 3000); // ⏱️ 3 seconds delay
});
</script>