amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

A4A FastFetch adsense-impl not generating ad format properly in responsive case

Open tdrl opened this issue 9 years ago • 5 comments

The amp-ad-network-adsense-impl is generating ad slot size via getIntersectionElementLayoutBox. In responsive cases, this can yield invalid ad formats, leading to 400 responses from the ad server. We need to make it smarter about how to generate slot sizes, possibly including centering when the generated format is smaller than the responsively sized slot.

tdrl avatar Mar 02 '17 20:03 tdrl

cc @ampproject/a4a

tdrl avatar Mar 02 '17 20:03 tdrl

Could you define what you mean by "responsively sized slot"? When and by whom is this calculated?

glevitzky avatar Mar 03 '17 20:03 glevitzky

This is related to slots using layout=responsive but the general issue is that amp-ad-network-adsense-impl.js derives format from the slotRect height/width (https://github.com/ampproject/amphtml/blob/master/extensions/amp-ad-network-adsense-impl/0.1/amp-ad-network-adsense-impl.js#L123) when this does not appear to be what Delayed Fetch is doing (it uses the iframe height/width attributes). Change is to ensure parity and have the creative centered should the slot be larger than than height/width given.

keithwrightbos avatar Mar 04 '17 21:03 keithwrightbos

My question was more about whether I'll need to wait for the creative to return, and then make some slot augmentations based on its rendered size. From what you're saying, it sounds like that's what I should be doing. What's the most sensible way of getting the creative size for AdSense in Fast Fetch? getIntersectionElementLayoutBox? Presumably any resizing logic can go into onCreativeRender().

glevitzky avatar Mar 06 '17 20:03 glevitzky

Actually no, that's not what I'm saying. The change required is as follows:

  • Modify AdSense format calculation to use height/width attributes instead of slotRect as follows (see https://github.com/ampproject/amphtml/blob/master/extensions/amp-ad-network-adsense-impl/0.1/amp-ad-network-adsense-impl.js#L123): const slotRect = this.getIntersectionElementLayoutBox(); let format; if (parseInt(this.element.getAttribute('height')) && parseInt(this.element.getAttribute('width')) { format =${this.element.getAttribute('width')x${this.element.getAttribute('height')}; } else { format =${slotRect.width}x${slotRect.height}; } Note that w/h parameters should continue to use slotRect height/width

  • It is now likely that responsive layout slots will return a creative smaller than the slot so we need to ensure they are properly centered vertically & horizontally to get parity with Delayed Fetch. Later we can revisit if we want to shrink the size of the slot but let's assume this will be addressed as the greater effort to fix responsive.

/cc @tlong2

keithwrightbos avatar Mar 06 '17 21:03 keithwrightbos