Ensure creatives render within iframes
If you're using Google Publisher Tags (GPT) to serve expanding and floating ads, and the creative is larger than the ad slot, your creatives might be cut off. To make creatives compatible with iframes, the code for the creative needs conditional logic to detect and handle its environment.
Statically-sized creatives, such as a 728x90 banner, render correctly regardless of the existence of an iframe, because they do not require resizing of their container.
How a creative can detect its surroundings
Below is example creative code that detects if the creative is:
- Not served in an iframe
- Served in a friendly iframe and can escape
- Served in a cross-domain iframe and cannot escape
||1. Not served in an iframe
2. Served in a friendly iframe and can escape
If the code is able to successfully reference the top window, the containing iframe is not a cross-domain iframe and considered "friendly".
||3. Served in a cross-domain iframe and cannot escape
If there was an error referencing the top window, the creative detects that it's in a cross-domain iframe and cannot escape. Here you can provide an alternative behavior so that the creative still renders in an acceptable manner. For example, you might display a statically-sized backup image instead of an expandable ad.
By default, Google Publisher Tags (GPT) use cross-domain iframes called SafeFrames to serve creatives. Use SafeFrame function calls to communicate with the parent page and resize itself. Learn how to render creatives using SafeFrame.