Render creatives using SafeFrame
SafeFrame is an API-enabled iframe that provides a single, unified mechanism for communication between advertiser and publisher content. SafeFrame technology in Ad Manager enables transparent and rich interactions between page content and ads, while preventing external access to sensitive data and providing more granular control over which creatives are rendered using the SafeFrame container with GPT.
IAB standards require publishers to update their websites in order to render ads inside SafeFrame containers. However, SafeFrame is supported in Ad Manager and enabled by default when using GPT tags.
To minimize the chances of malicious creatives serving, we recommend enabling SafeFrame whenever possible, in conjunction with the HTML5
sandbox attribute to prevent top-level navigation. Learn more about the
For detailed information, including the full SafeFrame specification, see the IAB documentation.
Configure creatives to use SafeFrame in GPT
In Ad Manager, you can explicitly control if a creative is rendered using a SafeFrame for four types of creatives: custom, third-party, system-defined templates, and user-defined templates. Select the Serve into a SafeFrame checkbox when creating a new creative or template for these creative types.
Before turning on SafeFrame, work with the advertisers or vendors who provide your creatives to determine if those creatives are SafeFrame-compatible. If you're using the
sandbox attribute, work with the agency or advertiser to ensure that clicks open the landing page in a new tab rather than navigating from the current page.
Custom and third-party creative types
For these creative types, Serve into a SafeFrame is turned ON by default. Uncheck the box to prevent a creative of this type from being served into a SafeFrame. Learn how to traffic third-party creatives and custom creatives.
User and system-defined creative templates
For these creative templates, Serve into a SafeFrame is turned OFF by default.
However, creating a user-defined template from an existing system-defined template turns this option ON. You must uncheck the box if you do not want creatives rendered inside a SafeFrame container. Learn more about creative templates.
Use the GPT API
You can also use the GPT API to force any particular ad slot or all slots on a page to render using a SafeFrame container. Learn about the setForceSafeFrame parameter
SafeFrame with AMP pages
The maximum expansion size of the SafeFrame container is limited to that of the viewport. SafeFrame doesn't allow ad slots within the viewport to resize for AMP pages, so a creative's request to resize is only honored when the ad slot is outside of the viewport.
SafeFrame and AMPHTML
AMPHTML ads don't serve into SafeFrames; instead, because AMPHTML is more secure, they serve into friendly iframes by default. If you have a Content Security Policy (CSP) on your site, the restrictions of the CSP also apply to AMPHTML ads in friendly iframes. In that case, call
googletag.pubads().setForceSafeFrame(true) before making any ad requests, to allow the ad to render in a cross-domain iframe without the CSP's restrictions.
The GPT SafeFrame integration consists of three parts:
- The SafeFrame iframe container itself, created by GPT upon display.
- Code inserted within the creative, providing the (external) SafeFrame API to the creative and communicating to the host page using
- Code running outside the SafeFrame iframe as part of GPT which is the other end of the
postMessagecommunication channel. This is the code which performs all of the expansion and geometric measurement for viewability.
Ad Manager supports creatives that use a Safeframe API to interact with websites, such as expanding an ad slot (either as a pushdown or an overlay) when a user clicks on an ad. However, you must modify your GPT tag to enable expansion of ad slots and allow pushdown/overlay interaction by calling
setSafeFrameConfig in the GPT API.
GPT does not externalize host API implementation as the rendering of the SafeFrame is handled by GPT. You can continue using the current GPT API to set up your ads, without any changes to the tag set up.
GPT implements the SafeFrame external party API to allow creatives to interact with the website.
Supported SafeFrame API methods
$sf.ext.expand(supports expansion in both push and overlay modes)
Not supported or partially supported API methods
$sf.ext.cookieis not supported as we do not allow creatives to access publisher cookies.
$sf.ext.metais not supported for publisher defined objects and limited to following system defined objects:
The string representation of the current version of SafeFrame.
Identified whether cookies are enabled on the browser:
You can view examples of SafeFrame-enabled creative implementations or verify your own Google Publisher Tag (GPT) SafeFrame implementations using the SafeFrame creative preview tool.
SafeFrame increases publisher control by limiting interaction between ads and publisher content to those that can be achieved through methods available in the API. The technology standardizes rich media formats, so that creatives using the API can run on any network that supports SafeFrame.
The SafeFrame provided API can be used to calculate viewability. While SafeFrame 1.0 does not directly report viewability metrics, the API allows for access to creative information that can be used by the advertiser to determine whether or not the SafeFrame container is "in view."
Available via the API are the geometric dimensions and location of the SafeFrame container and its content, in relation to the browser or application window, and the screen boundaries. Duration information can be derived by registering a listener to determine how long the ad is viewable.
Active View, which is a Google provided solution for viewable impressions is not part of the SafeFrame viewability specification. This will continue to function without any change. Learn more
Use the Google Publisher Console
You can use the Google Publisher Console to see if a slot is using SafeFrame.