首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google-dfp仅在某些广告上启用延迟加载

google-dfp仅在某些广告上启用延迟加载
EN

Stack Overflow用户
提问于 2021-07-06 21:48:27
回答 1查看 71关注 0票数 2

我使用的是google-dfp的lazyLoading。启用此选项后,所有广告都会延迟加载。有没有办法只对特定的广告而不是所有的广告启用它?

代码语言:javascript
复制
googletag.pubads().enableLazyLoad({
    // Fetch slots within 6 viewports.
    fetchMarginPercent: 500,
    // Render slots within 1.04 viewports.
    renderMarginPercent: 4,
    // Double the above values on mobile, where viewports are smaller
    // and users tend to scroll faster.
    mobileScaling: 10,
});
EN

回答 1

Stack Overflow用户

发布于 2021-11-04 09:48:39

有一种方法可以将你的adrequest分成两批:

代码语言:javascript
复制
googletag.cmd.push(function() {
  // Define ad slots.
  var slots = [
    googletag.defineSlot('/6355419/Travel/Europe', [728, 90], 'slot-1')
             .addService(googletag.pubads()),
    googletag.defineSlot('/6355419/Travel/Europe', [728, 90], 'slot-2')
             .addService(googletag.pubads()),
    googletag.defineSlot('/6355419/Travel/Europe', [300, 250], 'slot-3')
             .addService(googletag.pubads()),
    googletag.defineSlot('/6355419/Travel/Europe', [300, 250], 'slot-4')
             .addService(googletag.pubads()),
    googletag.defineSlot('/6355419/Travel/Europe', [300, 250], 'slot-5')
             .addService(googletag.pubads())
  ];

  // Disable initial load to precisely control when ads are requested.
  googletag.pubads().disableInitialLoad();

  // Enable SRA and services.
  googletag.pubads().enableSingleRequest();
  googletag.enableServices();

  // Issue first SRA request (slots 1 and 2) immediately.
  googletag.pubads().refresh([slots[0], slots[1]]);

  // Enable lazyLoading after 1st SRA batch
  googletag.pubads().enableLazyLoad({
      // Fetch slots within 6 viewports.
      fetchMarginPercent: 500,
      // Render slots within 1.04 viewports.
      renderMarginPercent: 4,
      // Double the above values on mobile, where viewports are smaller
      // and users tend to scroll faster.
      mobileScaling: 10,
  });

  // Issue second SRA request (slots 3, 4 and 5) once lazyLoading has been enabled
  googletag.pubads().refresh([slots[2], slots[3], slots[4]]);

});

有关SRA批处理的详细信息,请参阅here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68271783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档