【问题标题】:How to detect if AdSense has loaded an ad in JavaScript?如何检测 AdSense 是否在 JavaScript 中加载了广告?
【发布时间】:2021-10-02 04:55:12
【问题描述】:

我正在尝试使用来自docs 的代码 sn-ps 将 AdSense 集成到我们的 Svelte/Sapper 项目中:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
</script>

<ins class="adsbygoogle"
  style="display: inline-block;"
  data-ad-client="ca-pub-**************"
  data-ad-slot="**********"
  data-ad-format="horizontal"
>
</ins>

<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

广告确实会显示有时,但有时我的页面上只剩下一个很大的空白位置。

我认为我可以通过使用 JavaScript 以编程方式在 AdSense 的 iframe 中查找广告来检查广告是否正在展示;但是,我不能这样做,因为 iframe 有一个 src 指向 Google 的域而不是我们的域,因此会引发 DOM 异常。

有谁知道我如何检查 AdSense 是否成功加载了广告,以便我可以决定是否在应该被广告占用的空白处显示其他内容?

【问题讨论】:

    标签: javascript adsense svelte sapper


    【解决方案1】:

    您可以使用 javascript 检查 data-ad-status=“filled” 以了解广告是否已呈现 更多信息: https://support.google.com/adsense/answer/10762946?hl=en

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-01
      • 2019-04-20
      • 2010-11-20
      • 2012-12-18
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多