【问题标题】:Problem to put google adsense ads on site in next js在下一个 js 中将 google adsense 广告放在网站上的问题
【发布时间】:2022-06-24 22:31:49
【问题描述】:

我在下一个 js 中在网站上放置 google adsense 广告时遇到问题

我在互联网上找到了这些代码,但它不起作用。我不知道还能做什么

第一个代码是一个组件,它被放置在任何有广告的地方

import React, { useEffect } from "react";

export default function Adsense() {
  const loadAds = () => {
    try {
      if (typeof window !== "undefined") {
        (window.adsbygoogle = window.adsbygoogle || []).push({});
      }
    } catch (error) {
      console.log("adsense error", error.message);
    }
  };

  useEffect(() => {
    loadAds();
  }, []);

  return (
    <ins
      className="adsbygoogle"
      style={{ display: "block" }}
      data-ad-client="ca-pub-xxxxxxxxx"
      data-ad-slot="xxxxxxxxxx"
      data-ad-format="auto"
      data-full-width-responsive="true"
    ></ins>
  );
}

第二个是放入_document.js

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" />
        <script dangerouslySetInnerHTML={{
        __html: `
        (adsbygoogle = window.adsbygoogle || []).push({
            google_ad_client: "xxxxxxxxxx",
            enable_page_level_ads: true
            });
            `,
            }} />

【问题讨论】:

  • 这里一样,你能解决吗?
  • react_devtools_backend.js:4026 AdSense 头部标签不支持 data-nscript 属性。

标签: reactjs next.js adsense


【解决方案1】:

嘿,我可以在这个包的帮助下解决它,强烈推荐: React Adsense。需要折衷把script标签放在head标签里面加上nextjs/script。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    相关资源
    最近更新 更多