google-dfp – Google DFP广告管理系统 – SafeFrame扩展广告

似乎这个问题之前已经被问到没有答案.我正在尝试使用Google Dfp和SafeFrame API实现重叠式广告.我有Google控制台报告广告是在SafeFrame中投放的,但是没有使用$sf.ext.register回调来检索状态.看起来$sf.ext.expand永远不会像$sf.ext.register那样触发.

我已将广告素材中的设置更改为iframe,我正在使用以下dfp标记.

var sticky_image = document.getElementById('sticky-footer__image');
var sticky_image_expanded = 'http://www.example.com/image.jpg'
var sticky_image_collapsed = sticky_image.src;
var sticky_container = document.getElementById('sticky-footer__container');

function adjustDivContainerSize() {
  var self = $sf.ext.geom().self;
  sticky_container.style.width = (self.r - self.l) + 'px';
  sticky_container.style.height = (self.b - self.t) + 'px';
}

function expandAd() {
  /**
   * Expand the ad by calling the SafeFrame API
   */
  var config = {
    push: false,
    t: 250,
    l: 0,
    r: 0,
    b: 0
  };
  $sf.ext.expand(config);
  adjustDivContainerSize();
}

function collapseAd() {
  $sf.ext.collapse();
  adjustDivContainerSize();
}

adjustDivContainerSize();

/**
 * Register the original ad size
 */
$sf.ext.register(300, 70, function(status, data) {
  if (status == "expanded") {
    //nothing fires
  } else if (status == "collapsed") {
    //nothing fires
  }

});

sticky_container.style.height = '100%';

sticky_container.addEventListener('mouseover', function() {
  sticky_image.src = sticky_image_expanded;
  expandAd();
})

sticky_container.addEventListener('mouseout', function() {
  sticky_image.src = sticky_image_collapsed;
  collapseAd();
});

具有讽刺意味的是,我的代码段在使用广告素材预览工http://publisherconsole.appspot.com/safeframe/creative-preview.html

最佳答案 您在expandAd()函数中缺少一个部分.您需要将配置变量设置为允许的扩展大小.复制相关部分并添加所需的代码.

    function expandAd() {
      /**
       * Expand the ad by calling the SafeFrame API
       */
      var allowedExp = $sf.ext.geom().exp;
      var config = {
        push: false,
        t: 250,
        l: 0,
        r: 0,
        b: 0
      };
      /*config.t = allowedExp.t; set in config initialisation*/
      config.l = allowedExp.l;
      config.r = allowedExp.r;
      config.b = allowedExp.b;
      $sf.ext.expand(config);
    }

希望这会有所帮助.

点赞