9

我使用 DFP 广告管理系统 (DFP) 提供的广告。这是页面: http ://www.ifly.com

在页面加载事件之后,我通过 jQuery AJAX 加载 DFP 广告,以使我的各种搜索小部件尽可能快地用于用户交互。这个过程看起来像这样。

将初始 DFP 标题调用放在文档标题中。

<head>
...
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') + 
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/9358962/HP-300x250', [300, 250], 'div-gpt-ad-1353002461867-0').addService(googletag.pubads());
googletag.defineSlot('/9358962/HP-460x60', [468, 60], 'div-gpt-ad-1353002461867-1').addService(googletag.pubads());
googletag.defineSlot('/9358962/HP-728x90', [728, 90], 'div-gpt-ad-1353002461867-2').addService(googletag.pubads());
googletag.defineSlot('/9358962/HP-LAF-160x600', [160, 600], 'div-gpt-ad-1353002461867-3').addService(googletag.pubads());
googletag.defineSlot('/9358962/HP-RAF-160x600', [160, 600], 'div-gpt-ad-1353002461867-4').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
....
</head>

创建一个空 div 作为占位符。

<div id='horizontalTANBanner'></div>  

页面加载后,使用 jQuery AJAX 插入代码以获取广告。

<div id='horizontalTANBanner'>  
  <!-- HP-728x90 -->
  <div id='div-gpt-ad-1353002461867-2' style='width:728px; height:90px;'>
  <script type='text/javascript'>
  googletag.cmd.push(function() { googletag.display('div-gpt-ad-1353002461867-2'); });
  </script>
  </div>
</div>

Google 会加载更多 JavaScript 来实际调用广告。我看到它已使用 Firebug 插入。

<div id="horizontalTANBanner">
<div id="div-gpt-ad-1353002461867-2" style="width:728px; height:90px;">
<iframe id="google_ads_iframe_/9358962/HP-728x90_0" width="728" scrolling="no" height="90" frameborder="0" name="google_ads_iframe_/9358962/HP-728x90_0" marginwidth="0" marginheight="0" style="border: 0px none;">
<html>
</iframe>
<iframe id="google_ads_iframe_/9358962/HP-728x90_0__hidden__" width="0" scrolling="no" height="0" frameborder="0" name="google_ads_iframe_/9358962/HP-728x90_0__hidden__" marginwidth="0" marginheight="0" style="border: 0px none; visibility: hidden; display: none;">
</div>
</div>

我看到广告显示在除 Firefox(IE、Chrome、Opera、Safari)之外的所有浏览器中。我已与其他用户确认他们无法在 Firefox 中看到广告。如何让广告在 Firefox 中显示?

我在 DFP 论坛上问过这个问题,但不是技术性的,他们的最佳答案是“停止使用 AJAX”,但访问者体验要好得多,我希望谷歌会更好地对我的网页进行排名,因为加载速度不那么慢,所以我讨厌停止使用它。

4

1 回答 1

8

我认为您可能过于复杂 dfp 插槽的加载。

这个代码块是我认为不起作用的部分。

  /*** Populate DFP ads ***/
  var _pageID=$("body").find_class("pageID-");
  $.get('/common/modules/ajax-get-list.php',{pageID:_pageID},function(_data){
    //alert('data='+_data);
    if(_data!=''){
      var _arrDFPList=_data.split(',');
      for(var i=0;i<_arrDFPList.length;i++){
        //alert('DFP id = '+_arrDFPList[i]);
        $.get('/common/modules/ajax-get-one.php',{id:_arrDFPList[i]},function(_oneData){
          var _arrDFPOne=_oneData.split('<<<>>>');
          //alert('id = '+_arrDFPOne[0]+' and content = '+_arrDFPOne[1]);
          $("#"+_arrDFPOne[0]).append(_arrDFPOne[1]);
          //$("#"+_arrDFPOne[0]).html(_arrDFPOne[1]);
        });
      }
    }

    /*
    if(_data!=''){
      var arrDFPList=_data.split(',');
      $.get('/common/modules/def-get-one.php',{},function(_oneData){
      });
    }*/
  });
  /*** END Populate DFP ads ***/

我认为 Firefox 可能只是附加了广告位显示代码,但未能对其进行评估。

几个月前我遇到了一个类似的问题,我们想在加载后引入广告,并且让一切都非常快速而简单......我想出的解决方案是创建jquery.dfp.js。此插件允许您完全推迟 DFP 的加载,直到您想要加载它,您也不需要像当前正在做的那样预先定义所有插槽...

例如,这是您当前的主页,其中包含使用我的插件展示广告所需的基本要素:

<html>
<head>
    <title>DFP TEST</title>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="https://raw.github.com/coop182/jquery.dfp.js/master/jquery.dfp.min.js"></script>

</head>
<body>

<div class="adunit" id="HP-300x250" data-dimensions="300x250"></div>
<div class="adunit" id="HP-460x60" data-dimensions="460x60"></div>
<div class="adunit" id="HP-728x90" data-dimensions="728x90"></div>
<div class="adunit" id="HP-LAF-160x600" data-dimensions="160x600"></div>
<div class="adunit" id="HP-RAF-160x600" data-dimensions="160x600"></div>

<script>
$(function () {
    $.dfp('9358962');
});
</script>

</body>
</html>

我认为这是一种更好的做事方式。如果您有任何问题,请告诉我。

于 2013-01-09T13:40:55.050 回答