i'm searching for solution, that can expand SafeFrame custom ad from inside of custom creative in Google DFP, is that possible somehow?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I couldn't find any solid documentation on this so the example from PayteR helped me immensely! I had to play with the new dimension to get the ad to expand the right way.
Here is some sample code I created from PayteR's example:
There are 2 possible solutions:
1) using
SafeFrame API
pros:
cons:
2) code your own API with
window.postMessage()
javascript methodcons:
pros:
1) using
SafeFrame API
This API is realatively easy to use, you can see some examples in GPT Safeframe preview tool.
First you need to update your DFP initialization script in
<head>
of your websiteThis will allow to expand SafeFrame ads on your website. More about this in Control SafeFrame Container behavior through GPT.
Now you can create custom creative and serve it as SafeFrame on your website. Here is my one example. This Example can "wait" util it's visible, and then will expand to height of
<div id="container">
that is inside of SafeFrame:2. code your own API with
window.postMessage()
javascript methodFirst, you need to put this code, to your DFP initialization script in
<head>
of your website. This code will add an ID of Ad slot as#hash-tag
to<iframe>
's src so you can get it from inside of your creative.Second, you need to add this code to your website, better as separated .js file.
And third thing is your custom code in custom type of creative in DFP. Here is example, that is similar to that in first example, but here this script can wait until all content and image is loaded and then will expand/shrink your iframe with creative:
That's all. When you want to change anything on your website from inside of iframe, you can code your own cmd on your website and call this command from inside of the iframe.
Edit 1: just noticed now, that
var divGptAdId = '%%PATTERN:url%%;
will not return correct id of div on the page in #hash way, so now it's needed to give him a correct container div id change:to