I am using google-dfp's lazyLoading. When this is enabled, all Ads are lazy loaded. Is there a way to enable it only for specific ads and not for all?
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,
});
There is a way of doing it by splitting your adrequests in 2 batchs :
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]]);
});
See here for details about SRA batching.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.