reactjsadsadsensereact-ssr

How to make Google Auto Ads work with react SSR application


I want to use the Google Adsense Auto-Ads with my react application. The react application uses SSR and I have added the code that Google provided me to the head section of the template as shown below.

export default ({ markup, css }) => {
  return `<!doctype html>
      <html lang="en">
        <head>
          <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9999999999999999" crossorigin="anonymous"></script>
          <meta charset="utf-8">
          <meta
            name="viewport"
            content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"
          >
          <title>Teach Learn Game</title>
          <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400">
          <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
          <style>
              a{
                text-decoration: none;
                color: #bb4d00
              }
          </style>
        </head>
        <body style="margin:0">
          <div id="root">${markup}</div>
          <style id="jss-server-side">${css}</style>
          <script type="text/javascript" src="/dist/bundle.js"></script>          
        </body>
      </html>`;
};

When at the site, I have checked the html code using Chrome tools. I can see the line in the code but unfortunately I have been declined by the Google Adsense review saying I need to Fix some things.

The message from Google specifying the issue is: We couldn’t find the code on your site. This is because the code is either missing or incomplete, or because the URL of your site is incorrect. Learn more.

I have removed the requirement to login which was an earlier problem and I have a proper google account.

I did see another Stack Overflow issue where it was stated that window.adsbygoogle is to be used with React but it seemed that the problem was dealing more with specifying ad units and the implementation of the window.adsbygoogle was in a component class. As I am using Auto Ads I would not expect that would apply but maybe I am mistaken. If so, how would I change the code?

In any case, appreciate if anyone with experience with getting initial acceptance for Google Auto Ads can assist. If you provide code appreciate if you could use functional components as I am not very up on class components and the use of componentDidMount as most of the examples seem to be using.

Link to my site: https://tlgamer.herokuapp.com/


Solution

  • Adsense will look for Adcode in herokuapp.com instead of tlgamer.herokuapp.com that is why message from Google was "We couldn’t find the code on your site.", You can not monetize a subdomain if you do not own the main domain. Switch your SSR app to a top-level domain and re-apply for Adsense.