From 8041b19bb04c64de7783aec47126446119a944e6 Mon Sep 17 00:00:00 2001 From: Mostafa Khater Date: Wed, 25 Sep 2024 13:04:39 -0400 Subject: [PATCH] add(3rdparty/js): only load ads and Google Analytics after first app rendering with a 2 seconds delay (#510) --- app/root.tsx | 58 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/app/root.tsx b/app/root.tsx index ab5fb924..da635fb1 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -244,35 +244,49 @@ function App() { // eslint-disable-next-line react-hooks/exhaustive-deps }, []) + useEffect(() => { + const timer = setTimeout(() => { + // Load Google Tag Manager + ;(function (w, d, s, l, i) { + w[l] = w[l] || [] + w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }) + var f = d.getElementsByTagName(s)[0], + j = d.createElement(s), + dl = l != 'dataLayer' ? '&l=' + l : '' + j.async = true + j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl + f.parentNode.insertBefore(j, f) + })(window, document, 'script', 'dataLayer', 'GTM-WH4KFG5') + + // Load Ezoic script + const script = document.createElement('script') + script.src = '//www.ezojs.com/ezoic/sa.min.js' + script.async = true + document.body.appendChild(script) + + script.onload = function () { + window.ezstandalone = window.ezstandalone || {} + ezstandalone.cmd = ezstandalone.cmd || [] + ezstandalone.cmd.push(function () { + ezstandalone.define(118, 116) + ezstandalone.refresh() + ezstandalone.enable() + ezstandalone.display() + }) + } + }, 2000) // Delay of 1000ms (1 second) + + // Cleanup function to clear the timeout if the component unmounts + return () => clearTimeout(timer) + }, []) // Empty dependency array means this effect runs once after initial render + return ( - -