Google AdSense Script Issues in Remix Framework
Google Analytics and Google AdSense
Personally, I don't like ads because of user experience, but I decided to add Google AdSense to my blog for learning purposes. As soon as I integrated AdSense, I started encountering significant hydration errors.
` window.dataLayer = window.dataLayer || []; function gtag(){ dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', '${GA4_ID}'); `;
From what I found on Google, many users encounter errors because of new Date() in the script. I haven't had any errors related to that since I set it up so that the GA4 script only loads after cookie consent is given.
However, the problem lies with Google AdSense. When I inserted the Google AdSense script into my Remix framework-based site, various errors started popping up.
<script async // or async={true} src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_CLIENT}`} crossOrigin="anonymous" suppressHydrationWarning={true} // ✅> </script>
I added code to suppress hydration warnings, but that didn’t help much. The errors still appeared. The issue is clear, though: as soon as I remove that script, all the errors go away.
Link -> Related Stack Overflow post
I found a post in the link above that could have helped me, but I haven't tried it yet since my AdSense account isn't approved. The reason I haven't is that if I dynamically load the script only on the client side, the AdSense bot can't detect it, which would be problematic.
For now, I’ve decided to hold off on figuring out the solution until my AdSense approval comes through.
One thing I’ve learned during this process is that the information available for Remix framework is still relatively limited compared to other frameworks.
I hope this post helps other Remix users as I cover more topics on my blog. If anyone has a solution, feel free to contact me at