Convert custom templates to work with friendly iframes

If you're using asynchronous Google Publisher Tags (GPT) to serve expanding and floating ads, and the creative is larger than the ad slot, your creatives might get cut off. This is because asynchronous GPT tags use friendly iframes to serve creatives. (Standard creative banners (e.g., 728x90, 300x250) will not have an issue with friendly iframes.)

To make creatives compatible with friendly iframes, the code for the creative should detect and handle the following three scenarios:

The creative is not served in an iframe

The creative checks and sees that it is not served in a frame or iframe. The creative can be directly written to the page.

The creative is in an iframe and can escape the iframe

The creative detects that it is in a frame or iframe. The creative code will need to access the correct frame or window when adding the ad's HTML and Javascript code to the page. In most cases, that window will be the top window.

The creative is in an iframe and can't escape the iframe

An alternative should be provided in case the ad can't escape the iframe. For example, for an expandable ad, if the ad can't escape the iframe, show a backup image that does not expand, or for a floating ad, do not show anything and do not count an impression.

Example

Below is some sample code to detect each of the different scenarios. Replace each comment with the appropriate creative code.

<script type="text/javascript">
if(top==self){
/* The creative is not in an iframe. Display the ad. It might be possible to use document.write to display the creative. */
}else{
     try{
/* Use appropriate code to have the creative escape the iframe and show the ad. Most likely the code will need to use DOM functions and reference the top window. */
     }catch(e){
/* The creative cannot escape the iframe. Show an appropriate alternative. The alternative will remain inside of the iframe. */
}
}
</script>