【问题标题】:DFP refresh ad afer X seconds in viewDPF 刷新并在 X 秒后显示
【发布时间】:2018-06-04 09:24:13
【问题描述】:

我也想这样做,但使用 GPT APi(我对这种编码东西很陌生,所以不知道在做什么,所以寻求帮助)

我在 GPT ApI 文档中找到了这个:

  1. 展示可视化监听器,特定于广告位的逻辑。 当印象被视为可见时,将调用侦听器。 此事件也在服务级别运行,但如上所述,您可以过滤 使用此模式仅响应某个广告位

    googletag.pubads().addEventListener('impressionViewable', function(event) { if (event.slot == targetSlot) { //插槽特定逻辑。 } });

并且已经有了这个,它会在 X 秒后刷新广告

googletag.cmd.push(function() {
  var mappingleaderslot = googletag.sizeMapping().
  addSize([1024, 769], [[970,250],[970,90],[728,90],[468,60],[320,50],[234,60]]).
  addSize([768, 500], [[728,90],[468,60],[320,50],[234,60]]).
  addSize([1, 1], [[320,50],[234,60]]).
  build();
  var mappingbigboxslot = googletag.sizeMapping().
  addSize([1024, 769], [[300,600],[300,250],[160,600],[120,600],[250,250]]).
  addSize([768, 500], [[300,250],[250,250]]).
  addSize([1, 1], [[300,250],[250,250]]).
  build();
  topSlot = googletag.defineSlot('/1001824/prebid_test2', [[970, 250],[970, 90],[728, 90],[468, 60],[320, 50],[234, 60]], 'topSlot').defineSizeMapping(mappingleaderslot).setTargeting("test", "refresh").addService(googletag.pubads());
  middlerightSlot = googletag.defineSlot('/1001824/prebid_test3', [[300, 600],[300, 250],[160, 600],[120, 600],[250, 250]], 'middlerightSlot').defineSizeMapping(mappingbigboxslot).setTargeting("test", "refresh").addService(googletag.pubads());
  bottomrightSlot = googletag.defineSlot('/1001824/prebid_test1', [[300, 600],[300, 250],[160, 600],[120, 600],[250, 250]], 'bottomrightSlot').defineSizeMapping(mappingbigboxslot).setTargeting("test", "refresh").addService(googletag.pubads());
  bottomleftSlot = googletag.defineSlot('/1001824/prebid_test4', [[300, 600],[300, 250],[160, 600],[120, 600],[250,250]], 'bottomleftSlot').defineSizeMapping(mappingbigboxslot).setTargeting("test", "refresh").addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs(true, true);
googletag.pubads().setCentering(true);
googletag.enableServices();
googletag.display("topSlot");
googletag.display("middlerightSlot");
googletag.display("bottomrightSlot");
googletag.display("bottomleftSlot");
setInterval(function(){googletag.pubads().refresh([topSlot]);}, 120000);
setInterval(function(){googletag.pubads().refresh([middlerightSlot]);}, 120000);
setInterval(function(){googletag.pubads().refresh([bottomrightSlot]);}, 120000);
setInterval(function(){googletag.pubads().refresh([bottomleftSlot]);}, 120000);
});

function refreshSlot(slot) {
    pbjs.que.push(function() {
        pbjs.requestBids({
            timeout: PREBID_TIMEOUT,
            adUnitCodes: [slot.getSlotElementId()],
            bidsBackHandler: function() {
                pbjs.setTargetingForGPTAsync([slot.getSlotElementId()]);
                googletag.pubads().refresh([slot]);
            }
        });
    });
}
function refreshtopSlot() {
    refreshSlot(topSlot);
}
function refreshmiddlerightSlot() {
    refreshSlot(middlerightSlot);
}
function refreshbottomrightSlot() {
    refreshSlot(bottomrightSlot);
}  
function refreshbottomleftSlot() {
    refreshSlot(bottomleftSlot);
}

但我不知道如何将两者结合起来,因此当广告在“可见”X 秒后刷新时,任何指针/任何人都可以帮助我吗?

【问题讨论】:

    标签: google-dfp


    【解决方案1】:

    我认为我发现了另一个问题,如果预出价广告首先呈现,它不会将预出价 que/页面出价推送到“下一个”预出价,它会刷新相同的出价,因此没有后续的“rev”有。我尝试添加这个,但似乎不起作用

    googletag.pubads().addEventListener('impressionViewable', function 
    (event) {
              var elementId = event.slot.getSlotElementId();
              var slotConfig = slots[elementId];
              if (slotConfig) {
                var handle = setTimeout(function () {
                  googletag.cmd.push(function () {
                      function refreshBid() {
                          pbjs.que.push(function() {
                              pbjs.requestBids({
                                  timeout: PREBID_TIMEOUT,
                                  bidsBackHandler: function() {
                                      googletag.pubads().refresh([slot1]);
    

    【讨论】:

      【解决方案2】:

      你可以看看这个 Gist,它有一个完整的code example

      这里是 Javascript 示例

      var size = [
        //[300, 600],
        //[300, 250],
        //[160, 600],
        //[120, 600],
        [250, 250]
      ];
      var PREBID_TIMEOUT = 1000;
      
      googletag.cmd.push(function () {
        (function (googletag, pbjs, config) {
          var sizeMappings = {};
          var slots = {};
          function refreshSlot(slot) {
            pbjs.que.push(function() {
              pbjs.requestBids({
                timeout: PREBID_TIMEOUT,
                adUnitCodes: [slot.getSlotElementId()],
                bidsBackHandler: function() {
                  pbjs.setTargetingForGPTAsync([slot.getSlotElementId()]);
                  googletag.pubads().refresh([slot]);
                }
              });
            });
          }
          Object.keys(config.sizeMappings).forEach(function (key) {
            var sizeMappingBuilder = googletag.sizeMapping();
            config.sizeMappings[key].forEach(function (mapping) {
              sizeMappingBuilder.addSize(mapping[0], mapping[1]);
            });
            var sizeMapping = sizeMappingBuilder.build();
            sizeMappings[key] = sizeMapping;
            console.log('created sizemapping ', key, ' ', sizeMappings[key]);
          });
      
          //googletag.pubads().enableSingleRequest();
          googletag.pubads().collapseEmptyDivs(true, true);
          googletag.pubads().setCentering(true);
          googletag.pubads().disableInitialLoad();
          googletag.enableServices();
          googletag.pubads().addEventListener('impressionViewable', function (event) {
            var elementId = event.slot.getSlotElementId();
            var slotConfig = slots[elementId];
            if (slotConfig) {
              var handle = setTimeout(function () {
                googletag.cmd.push(function () {
                  refreshSlot(event.slot);
                });
              }, config.definitons[elementId].timeout);
              console.log('handle for time ', handle, ' elementId ', elementId, ' duration ', config.definitons[elementId].timeout);
            }
          });
          Object.keys(config.definitons).forEach(function (key) {
            var def = config.definitons[key];
            var slot = googletag.defineSlot(def.adUnitPath, def.size, key);
            slot.setTargeting('test', 'refresh');
            slot.defineSizeMapping(sizeMappings[def.sizeMapping]);
            slot.addService(googletag.pubads());
            googletag.display(key);
            slots[key] = { slot: slot };
          });
          googletag.pubads().refresh();
        })(window.googletag, window.pbjs, {
          definitons: {
            topSlot: {
              adUnitPath: '/1001824/prebid_test2',
              size: size,
              sizeMapping: 'mappingleaderslot',
              timeout: 5000,
            },
            middlerightSlot: {
              adUnitPath: '/1001824/prebid_test3',
              size: size,
              sizeMapping: 'mappingbigboxslot',
              timeout: 3000,
            },
            bottomrightSlot: {
              adUnitPath: '/1001824/prebid_test1',
              size: size,
              sizeMapping: 'mappingbigboxslot',
              timeout: 3000,
            },
            bottomleftSlot: {
              adUnitPath: '/1001824/prebid_test4',
              size: size,
              sizeMapping: 'mappingbigboxslot',
              timeout: 3000,
            },
          },
          sizeMappings: {
            mappingleaderslot: [
              [
                [1024, 769],
                [
                  [970, 250],
                  [970, 90],
                  [728, 90],
                  [468, 60],
                  [320, 50],
                  [234, 60]
                ]
              ],
              [
                [768, 500],
                [
                  [728, 90],
                  [468, 60],
                  [320, 50],
                  [234, 60]
                ]
              ],
              [
                [1, 1],
                [
                  [320, 50],
                  [234, 60]
                ]
              ],
            ],
            mappingbigboxslot: [
              [
                [1024, 769],
                [
                  [300, 600],
                  [300, 250],
                  [160, 600],
                  [120, 600],
                  [250, 250]
                ]
              ],
              [
                [768, 500],
                [
                  [300, 250],
                  [250, 250]
                ]
              ],
              [
                [1, 1],
                [
                  [300, 250],
                  [250, 250]
                ]
              ],
            ]
          }
        });
      });
      

      【讨论】:

      • 非常感谢 Bewarnd,似乎工作完美,我只需要将它添加到我所拥有的其余部分中。竖起大拇指
      • 实际上,尺寸映射似乎不起作用,复制ipad,iphone等时它没有改变尺寸?
      • 好的,谢谢,它现在可以设置不同的尺寸,但另一个问题出现了,似乎现在再次推动预投标 que/ 投标,如果它们的尺寸大于它们显示的尺寸映射9有时会得到 970x250 等,什么时候应该是 728x90 的最大尺寸)。即“打破尺寸映射”,errrr,任何线索?
      • Prebid 有自己的尺寸映射方案见prebid.org/dev-docs/examples/size-mapping.html
      • 好的,谢谢,您如何将“allSizes”放入您编写的脚本的其余部分? (没有它,我不知道该怎么做,似乎阻止了大量投标人)googletag.defineSlot('/19968336/header-bid-tag-0', allSizes, 'div-1')跨度>
      猜你喜欢
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 2013-06-23
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多