【问题标题】:Remove adsense on mobile移除手机上的adsense
【发布时间】:2014-04-20 01:28:15
【问题描述】:

我正在研究我的响应式设计,但在使用 Adsense 时遇到了问题。

我有一个广告应该显示在桌面设计上,而不是移动设计上。 因此,只有在桌面上查看网站时,广告代码才应放在 html 中。 使用 display: none 的 css 是可能的,但这违反了 adsense TOS,所以不是解决方案。

我认为像 http://mobiledetect.net 这样的 PHP 类是可能的,但我更喜欢检查浏览器宽度,然后决定做什么。

Adsense 有一个经过批准的示例,如下所示,但我可以将它用于我的目标吗?

<script type="text/javascript">
google_ad_client = "ca-publisher-id";
width = document.documentElement.clientWidth;
google_ad_slot = "1234567890";
google_ad_width = 320;
google_ad_height = 50;
if (width > 500) {
    google_ad_slot = "3456789012";
    google_ad_width = 468;
    google_ad_height = 60;
}
if (width > 800) {
    google_ad_slot = "2345678901";
    google_ad_width = 728;
    google_ad_height = 90;
}
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

我希望有人能指出我正确的方向。

【问题讨论】:

  • 如果您真的想区分台式机和移动设备,检查浏览器宽度不是办法。我的手机分辨率比我的显示器高。您是否更倾向于屏幕尺寸而不是设备类型?
  • 它用于响应式设计,因此网站的外观(以及要展示的广告)取决于浏览器的宽度,而不是移动设备与否。我可能解释得有点奇怪:)

标签: javascript jquery mobile responsive-design adsense


【解决方案1】:

我已经联系了荷兰 AdSense 支持团队,得到了令人惊讶的答案,但我还没有在互联网上找到。

显然允许在使用响应式 AdSense 代码时使用 display:none。 这是支持团队的某个人发给我的代码:

<style>
  .responsive-test { display: block;}
  @media(max-width: 480px) { .responsive-test { display: none; } }
</style>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Resposive_TEST -->
<ins class="adsbygoogle responsive-test"
  data-ad-client="ca-pub-3086914080036003"
  data-ad-slot="1408862175"
  data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

请注意,只有在使用响应式 AdSense 代码时才允许这样做!

我表达了我对他发送给我的方法的担忧,因为 ad implementation policies 明确指出必须避免 display:none。他认为这篇文章对于新的自适应广告来说已经过时了。

他问了他的一位同事,也确认上面的代码是允许的。虽然,我仍然希望社区或其他 AdSense 支持团队的人来确认,只是为了确保! :D

【讨论】:

  • 在 2016 年这仍然有效:Techniques to avoid: Hiding ad units at anytime (e.g., display:none), unless you're implementing a responsive ad unit 并由 Google 确认
【解决方案2】:

您可以尝试这样的方法来避免在移动设备上加载 JS,但您应该与您的 AdSense 经理确认是否允许或现在进行此更改。

if (width >= 480) {
  document.write('<script src="show_ads.js"><\/script>');
}

【讨论】:

  • 感谢您的评论,但我不确定我是否完全理解。你的意思是像jsfiddle.net/Kr4tZ 还是你在暗示什么? (PS:不在jsfiddle上工作,只是为了展示代码)
  • 在 JSFiddle 中不允许 document.write。
  • 是的,我知道,但我只是把它贴在那里给你看代码。这就是您在示例中的意思吗?
【解决方案3】:

您可以尝试 Labnol Google adsense responsive design 的方法,Google 批准

【讨论】:

  • 这个帖子我也看了几遍,但是看不出来怎么用?它总是在 html 中编写 adsense 代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多