OiO.lk Blog PHP Why are Google AdSense auto display ads and site preview not working after switching from PHP to Next.js?
PHP

Why are Google AdSense auto display ads and site preview not working after switching from PHP to Next.js?


Background:

I recently migrated my website from a PHP-based setup to a React.js based setup to improve performance and work speed. However, I faced some issues with React js because of its CSR. Finally, I moved to Next.js with server-side rendering (SSR) to address issues with Google AdSense like auto-display ads and website preview in Adsense, and improve SEO. My website is hosted on a VPS and connected to my domain.

Problem:

Since switching from PHP to React (CSR) and later to Next.js (SSR), I’ve noticed the following issues with Google AdSense:

Auto display ads stopped displaying: Other ad formats (like vignette, anchor, and manual ads) still appear, but auto display ads that show randomly anywhere on pages are not appearing, they worked previously on the PHP website without any issues.

AdSense preview also isn’t working: My site no longer appears correctly in the AdSense site preview, which previously worked well with PHP.

What I’ve Tried:

Ensured SSR in Next.js: The Next.js app uses the App Router, and all pages are server-rendered (SSR), allowing the site to function without JavaScript.

Implemented AdSense scripts properly: Added the AdSense scripts in layout.js to ensure they load once on initial page load and do not reload on client-side navigations.

Re-requested indexing: Submitted my site for re-indexing in Google Search Console to help Google recognize the SSR setup and update its cache.

Question:

Given these steps, will AdSense auto display ads and the preview in Google’s AdSense dashboard eventually start working again, similar to how they did on the PHP site? Does Google require a certain amount of time to adjust to this new setup, or is there something specific in Next.js I need to address to make my site as compatible as it was in PHP?

I would greatly appreciate any insights from others who have migrated to Next.js and faced similar AdSense issues. Thanks in advance!

layout.js file code to load Adsense auto ads

<head>
    <script
      defer
      src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxxxx"
      crossOrigin="anonymous"
    ></script>
    <script
      defer
      dangerouslySetInnerHTML={{
        __html: `
          
        `,
      }}
    ></script>
  </head>



You need to sign in to view this answers

Exit mobile version