79535335

Date: 2025-03-26 03:34:53
Score: 0.5
Natty:
Report link

Google AdSense Integration in Docusaurus Project

To integrate Google Adsense in Docusaurus, I have followed the below-mentioned steps

1. Get The Code From the Google Adsense

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

2. Modify 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

3. Keeping Ads on Specific Page

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

Reasons:
  • Blacklisted phrase (0.5): how can I
  • Long answer (-1):
  • Has code block (-0.5):
  • Filler text (0.5): XXXXXXXX
  • Low reputation (1):
Posted by: abhinav tiwari