2

I'm working on a Docusaurus project hosted on GitHub at https://github.com/Ajay-Dhangar/CodeMastermindHQ. I want to integrate Google AdSense into my website to monetize it. However, I'm facing issues with the integration and need some help.

I have signed up for an AdSense account and received my ad code from Google. I have also reviewed the AdSense documentation, but I'm not sure where and how to add the AdSense code in my Docusaurus project to display ads on my website. I have tried a few approaches, but none of them seem to work as expected.

Here's what I have tried so far:

  • Adding the AdSense code directly in my Markdown files
  • Adding the AdSense code in the Docusaurus configuration file
  • Embedding the AdSense code in my custom theme

However, the ads are not showing up on my website as expected. I was expecting to see ads displayed on my website after integrating AdSense.

I would appreciate any guidance or sample code that can help me successfully integrate AdSense in my Docusaurus project. Thank you in advance for your assistance!

1 Answers1

1

You can use the scripts configuration in docusaurus.config.js. AdSense will give you an example of a script to include in the head of your HTML, such as this:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXX"
     crossorigin="anonymous"></script>

You can translate that into a Docusaurus script config like this:

  scripts: [
    {
      src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXX',
      async: true,
      crossorigin: 'anonymous',
    }
  ],

If you want to place ads ads specific locations rather than accept auto placement of ads, you can probably just add the HTML of the ad directly to the relevant pages.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Could you please clarify whether it would be more advisable to utilize the current host link, namely https://codemastermindhq.vercel.app/, for my content, or if the situation would warrant the acquisition of a private domain? – Ajay Dhangar Aug 07 '23 at 16:00