Next.js Discord

Discord Forum

we found some policy violations | google adsense (Next v14)

Unanswered
Naeemgg posted this in #help-forum
Open in Discord
Hello there! is there anything extra we need to do for connecting google adsense to nextjs??
import Script from "next/script";

type Props = {
  pId: string;
};

const GoogleAdsense: React.FC<Props> = ({ pId }) => {
  if (process.env.NODE_ENV !== "production") {
    return null;
  }
  return (
    <Script
      async
      src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-${pId}`}
      crossOrigin="anonymous"
      strategy="afterInteractive"
    />
  );
};

export default GoogleAdsense;

I have injected this component into my root layout
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import GoogleAdsense from "../components/GoogleAdsense";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Create Next App",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    <GoogleAdsense pId="(AdsenseのID)" />
    </html>
  );
}

0 Replies