To integrate Google Adsense in Docusaurus, I have followed the below-mentioned steps
Adsense code will be provided by Google one your blog/website is monetized. It will look similar to the HTML code mentioned below.
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXX" crossorigin="anonymous"></script>
Once you have the code then you can go to the step 2
docusaurus.config.js
Modify your docusaurus.config.js
file. Add the AdSense script to the scripts
section. The configuration should look like this:
module.exports = {
// Other configurations...
scripts: [
{
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXX',
async: true,
crossorigin: 'anonymous',
}
],
};
If you still confuse check the my github source code
The next question in mind would be how can I add the adsense to the specific page lets find that
For that you can create similar script on that page.
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-XXXXXXXX"
data-ad-slot="XXXXXXX"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
In both the cases
Don't forget to replace ca-pub-XXXXXXXX with your actual Adsense ID