I’m working on a nextjs project and I have to implement the google AdSense code that is for automatic ads.
So, my google ad code is just this:
<script
async
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${process.env.NEXT_PUBLIC_GOOGLE_ADSENSE}`}
crossOrigin="anonymous"
/>
There is no specific ad unit code. Based on this script load, Google will automatically add the ads.
In such a case, how will I implement this in my NextJS project ensuring that the ads will continue to work with the route change?
Currently, the problem I see is that if I just place this in the _document.js
head, the ads will load only on full reload. There are some tutorials describing how to implement google Adsense in NextJS, but they all describe the case when you have specific ad units created for Adsense, but not the case of automatic ads based on this script alone.
Will really appreciate any input on this.