resizeRemoteCreative resizes DFP iframe but doesn't resize the div
Type of issue
Bug
Description
We have two different sizes on the same unit: 728x90 and 970x250. When 970x250 wins, it's not properly centered. It happens because pebid's code resizes the frame created by DFP but doesn't resize the div also created by DFP. We're using Safe Frames, so resizing is done in resizeRemoteCreative in secureCreatives.js
function resizeRemoteCreative({ adUnitCode, width, height }) {
const iframe = document.getElementById(
find(window.googletag.pubads().getSlots().filter(isSlotMatchingAdUnitCode(adUnitCode)), slot => slot)
.getSlotElementId()).querySelector('iframe');
iframe.width = '' + width;
iframe.height = '' + height;
}
As you can see, the code locates the div, yet ignores it and resizes the frame only. But the div also has it's size explicitly specified by DFP.
Steps to reproduce
- Create unit with two sizes
- Wait till the bid for larger size wins
- Examine the div properties
Expected results
Div has it's size adjusted to the size of winning bid
Actual results
Div's size is the same as it was set by DFP
Platform details
Prebid 1.15
I've had this hack in there for a long time (since v0.19.0), works well for us
function resizeRemoteCreative({ adUnitCode, width, height }) {
const iframe = document.getElementById(
find(window.googletag.pubads().getSlots().filter(isSlotMatchingAdUnitCode(adUnitCode)), slot => slot)
.getSlotElementId()).querySelector('iframe[id]');
iframe.width = '' + width;
iframe.height = '' + height;
/* @andyblackwell: make multi-size work correctly */
iframe.style.width = iframe.width + 'px';
iframe.style.height = iframe.height + 'px';
if (iframe.parentElement.style.width) {
iframe.parentElement.style.width = iframe.style.width;
}
if (iframe.parentElement.style.height) {
iframe.parentElement.style.height = iframe.style.height;
}
}
I use other hack on GPT event and works fine.
googletag.pubads().addEventListener('slotRenderEnded', function (event) {
if (!event.isEmpty) {
var width = parseInt(event.size[0]);
var height = parseInt(event.size[1]);
var div = document.getElementById(event.slot.getSlotElementId());
/* resize if creative is 1x1 */
if (width === 1 && height === 1) {
var size = event.slot.getTargeting('hb_size');
if (size && size.length > 0) {
try {
var parts = size[0].split("x");
width = parseInt(parts[0]);
height = parseInt(parts[1]);
var child = div.querySelector("div[id^='google_ads_iframe_']");
if (child) {
if (width > 0 && height > 0) {
child.style.width = width + "px";
child.style.height = height + "px";
} else {
child.style.width = "auto";
child.style.height = "auto";
}
}
} catch (ex) {
console.log(ex);
}
}
}
}
});
All these hacks are not required, if you don't explicitly set width and height on the div itself, and set iframe style to display: block...
In fact, DFP has stopped adding "width" and "height" properties for 1x1 and out-of-page ad units long time ago.
@YOzaz I knew that there should be some reason for this prebid's behavior. It seems that despite what's written here http://prebid.org/adops/step-by-step.html I created creatives with the actual size instead of using 1x1. I guess I'll try to switch to 1x1 creatives and see if it fixes my problem. Thanks!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.