简体   繁体   English

如何正确编写 DFP 页外广告单元?

[英]How to properly write a DFP out of page ad unit?

I am developing a javascript-rendered mobile web interstitial.我正在开发一个 javascript 渲染的移动网络插页式广告。 The layout is fully responsive, hence it will take 100% of the provided screen\\iframe.布局是完全响应的,因此它将占用提供的 screen\\iframe 的 100%。

I now wish to display the interstitial through DFP.我现在希望通过 DFP 展示插页式广告。

At first I created a sized ad unit (320x480) and it worked just fine, but the interstitial was limited to the boundaries of the iframe.起初,我创建了一个大小合适的广告单元 (320x480),效果很好,但插页式广告仅限于 iframe 的边界。

I founf a new line item type called Out-of-page .我创建了一个名为Out-of-page的新订单项类型。 The documentation states that:该文件指出:

They may include pop-ups and floating line items and are sometimes called interstitials.它们可能包括弹出窗口和浮动订单项,有时也称为插页式广告。

But when I try to embed the interstitial in a test site, what happens is that the iframe stays 1x1, making the interstitial invisible (if I manually enlarge it with a debugger, I see it)但是当我尝试在测试站点中嵌入插页式广告时,会发生 iframe 保持 1x1 的情况,使插页式广告不可见(如果我用调试器手动放大它,我会看到它)


My settings:我的设置:

  • line item with inventory sizes of 1x1 and out of page广告资源尺寸为 1x1 且页外的订单项
  • creative with my code snippet用我的代码片段创意
  • ad unit is defined as size 1x1广告单元的尺寸定义为 1x1

I read in the documentation that:我在文档中读到:

If you're using a DoubleClick tag creative, you must ensure that the creative code trafficked on the other end of the DoubleClick tag (ie, another DFP network) is properly coded for an out-of-page ad unit.如果您使用的是 DoubleClick 代码广告素材,则必须确保在 DoubleClick 代码的另一端(即另一个 DFP 网络)投放的广告素材代码针对页外广告单元正确编码。

What does it mean, in terms of DFP Out-of-page interstitial, that the ad is "properly coded"?就 DFP 页外插页式广告而言,广告“正确编码”是什么意思? How do I force the interstitial to take all the size of the screen?如何强制插页式广告占据屏幕的所有尺寸?

After consulting with DFP support, I was able to create an out of page interstitial ad unit by following these steps:在咨询 DFP 支持后,我能够按照以下步骤创建页外插页式广告单元:

  1. Create a new Ad Unit, with inventory size of "Out of Page"创建一个新的广告单元,广告资源尺寸为“页外”
  2. Create a new Line Item and a mobile creative with inventory size "Out of Page", this line item targets the former Ad Unit.创建一个新的订单项和一个广告资源尺寸为“页外”的移动广告素材,此订单项定位到以前的广告单元。
  3. Generate new tags under the Inventory tabs, selected "Enable synchronous requests" and "Out of Page" on step 2. The "Enable synchronous requests" seems to be the key to make this work.在 Inventory 选项卡下生成新标签,在第 2 步选择“Enable synchronous requests”和“Out of Page”。“Enable synchronous requests”似乎是完成这项工作的关键。

    According to Google Support:根据谷歌支持:

    We usually recommend our publishers to implement Sync GPT when serving out of page (interstitial) ads as the creative renders in a element instead of an iFrame我们通常建议我们的发布商在提供页外(插页式)广告时实施同步 GPT,因为广告素材呈现在元素而不是 iFrame 中

  4. Place this tag in a test page (with the necessary html, head and body tags) and Voilà!将此标签放在测试页面中(带有必要的 html、head 和 body 标签),瞧!

Not sure this is what you need, and I don't have that much experience with DFP, but I just ran into a similar problem that I solved by managing the size of the iframe manually.不确定这是您需要的,而且我对 DFP 没有太多经验,但我遇到了类似的问题,我通过手动管理 iframe 的大小解决了这个问题。 Maybe this can help you too.也许这也可以帮助你。

The DFP API has an event you can listen to that lets you know that the ad has finished rendering, upon which I would suggest you change the iframe properties to be full width, and a whatever height would work for the placement. DFP API 有一个您可以收听的事件,让您知道广告已完成呈现,我建议您将 iframe 属性更改为全宽,并且任何高度都适用于展示位置。

Assuming you have jQuery on your page, this can be done quite easily.假设您的页面上有 jQuery,这可以很容易地完成。 After setting up the DFP plugin (calling defineSlot etc.) you can add a listener for this event like so:设置 DFP 插件(调用defineSlot等)后,您可以为该事件添加一个侦听器,如下所示:

googletag.pubads().addEventListener('slotRenderEnded', function(){
  var $adFrame = $('#id-of-the-iframe');
  $adFrame.css({width: '100%', height: '500px'});
});

This is outlined in DFP docs here . 此处的DFP 文档对此进行了概述。

Hope this helps.希望这可以帮助。

EDIT: After posting I realized that the code example I posted is from the DFP GPT library.编辑:发布后我意识到我发布的代码示例来自 DFP GPT 库。 Perhaps you are not using this.也许你没有使用这个。 This SO question has a link to a library that someone has created to listen to events that DFP fires. 这个 SO 问题有一个指向某人创建的用于侦听 DFP 触发的事件的库的链接。 Perhaps you can use that and use the technique I described?也许您可以使用它并使用我描述的技术?

Again - hope this helps :)再次 - 希望这有帮助:)

I just ran into this.我刚遇到这个。 It seems that DFP has gotten rid of the Enable Synchronous Requests option. DFP 似乎已经去掉了启用同步请求选项。 This was never that great of a solution (as others pointed out) for a couple of reasons.由于几个原因,这从来都不是一个很好的解决方案(正如其他人指出的那样)。 First, it doesn't work well if you have async requests on the same page.首先,如果您在同一页面上有异步请求,则效果不佳。 And second, it is "blocking" and slows your page down.其次,它会“阻塞”并减慢您的页面速度。

Friendly iFrame友好的 iFrame

It seems that now the preferred method is to use a "Friendly iFrame".似乎现在首选的方法是使用“友好 iFrame”。 To use a Friendly iFrame, when setting up your creative in DFP, uncheck the "Serve into a SafeFrame".要使用友好 iFrame,请在 DFP 中设置您的广告素材时,取消选中“投放到 SafeFrame”。 DFP will now serve your ad into a "Friendly iFrame". DFP 现在会将您的广告投放到“友好 iFrame”中。 A Friendly iFrame is an iFrame that is served from the same domain as the parent window.友好 iFrame 是从与父窗口相同的域提供的 iFrame。 Because the domains match, browser security rules allow JavaScript in the iframe to access the parent window (via window.parent.document ).由于域匹配,浏览器安全规则允许 iframe 中的 JavaScript 访问父窗口(通过window.parent.document )。 Now you can adjust the size of the iframe to make it full screen.现在您可以调整 iframe 的大小以使其全屏显示。 To do this, add something like the below to your ad code:为此,请在您的广告代码中添加如下内容:

window.parent.document.getElementById(window.name).style.cssText = "position: fixed; top: 0; left: 0; bottom: 0; width: 100%; height: 100%; margin: 0;";

If your ad has a way to close itself, make sure to also shrink the Friendly iFrame back down on close (otherwise the expanded Friendly iFrame will block mouse actions on the underlying page).如果您的广告可以自行关闭,请确保在关闭时也缩小友好 iFrame(否则展开的友好 iFrame 会阻止底层页面上的鼠标操作)。 You can do this like so:你可以这样做:

window.parent.document.getElementById(window.name).style.cssText = "position: relative; width: 0px; height: 0px;";

A Couple of Notes一些注意事项

For security reasons, whenever possible, SafeFrame is the preferred way to serve ads.出于安全原因,只要有可能,SafeFrame 是投放广告的首选方式。 SafeFrame provides an API for communicating with the parent window without allowing full access. SafeFrame 提供了一个 API 来与父窗口通信,但不允许完全访问。 SafeFrame includes an expand option for increasing the size of the iFrame, however, DFP's SafeFrame implementation doesn't seem to allow you to expand to fullscreen. SafeFrame 包含一个用于增加 iFrame 大小的扩展选项,但是,DFP 的 SafeFrame 实现似乎不允许您扩展到全屏。 For this reason, it seems best to use a Friendly iFrame for interstitials.出于这个原因,最好为插页式广告使用友好的 iFrame。 You can try out DFP's SafeFrame implementation here .您可以在此处试用 DFP 的 SafeFrame 实施。

Note that you should only allow content that you fully trust to run in a Friendly iFrame as it can do a lot of malicious stuff (such as stealing user session cookies, etc).请注意,您应该只允许您完全信任的内容在 Friendly iFrame 中运行,因为它可以做很多恶意的事情(例如窃取用户会话 cookie 等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM