I'm currently working on a NextJS project and I need to integrate the Google AdSense code for automatic ads.
The Google ad code I have is:
<script
async
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${process.env.NEXT_PUBLIC_GOOGLE_ADSENSE}`}
crossOrigin="anonymous"
/>
There isn't a specific ad unit code provided. The ads will be automatically generated by Google based on this script.
My concern is how to implement this in my NextJS project so that the ads continue to function even when the route changes.
Currently, I've noticed that if I include this in the _document.js
head, the ads only load on full reload. Most tutorials cover implementing Google AdSense in NextJS with specific ad units, not with automatic ads like in this case.
I would greatly appreciate any guidance on this matter.