ads/inabox/inabox-host.md
One goal of AMPHTML ads is for advertisers to create ad once and use everywhere. This guide provides details about how an ad network can join us to serve and render AMPHTML ads in various environments, for example regular web & native mobile apps.
Ad creatives that are written following the AMPHTML ads spec.
A term describes the situation that an AMPHTML ad is being served on a non-AMP environment, e.g a regular web page inside an iframe embed or a native mobile app inside a WebView. This is very different from how AMPHTML ad gets rendered on an AMP page, where the page and ad shares the same JS runtime.
The web page or native mobile app that the ad is being served on.
An iframe with the same origin as the host page, so that it has full access to the host page content.
An iframe on the host page that has different origin, so it can only communicate to the host page via postMessage API.
This is the case when AMPHTML ad is being served and rendered on a regular web page (non-AMP) inside an iframe. The iframe can be either a friendly iframe, or a cross-domain iframe.
Using friendly iframe requires zero to little investment to get it work, but it can be more involved if you want to get the full benefit from AMPHTML ads, which will be discussed in the optimization session. Because AMPHTML is trustful & secure, it can be put inside a friendly iframe without worrying it hijacking the page and ruining the end user experience. Meantime, friendly iframe rendering in general requires less browser resources than cross-domain iframe rendering, which not only brings performance benefit but also revenue gain. One thing to keep in mind though is that the ad network should have their own mechanism to prevent pub modifying the ad content or faking clicks. Google Ad Manager uses this approach to integrate with AMPHTML ads.
Main workflow:
srcdoc.In case that the AMPHTML ad is generated by a 3rd party, to ensure it's secure to put it in a friendly iframe, the following 2 protections should be considered:
<meta http-equiv="Content-Security-Policy" content="script-src https://cdn.ampproject.org/;object-src 'none';child-src blob:;frame-src 'none'">Ideally, both should be implemented for defense-in-depth.
It is a good idea to consider server side rendering for further performance optimization. For example, rewrite all script links with version number to get the browser cache benefit. For more details about server side rendering, please reach out to the @ampproject/wg-monetization.
If the ad has to be put into a cross-domain iframe, the ads tag is responsible to set up the communication channel for the ad to complete various tasks such as ad expansion or viewability tracking. A so-called host script is to be loaded in that case to fulfill the requirements.
Main workflow:
src set to the ad request URL.https://cdn.ampproject.org/rtv/{version}/amp4ads-host-v0.jsA sample implementation of the above process can be found here.
(Working in progress, stay tuned)