i'm searching for solution, that can expand SafeFrame custom ad from inside of custom creative in Google DFP, is that possible somehow?
Google DFP - Resize SafeFrame custom creative outer Iframe container from inside (expand ad)
6.8k views Asked by PayteR At
2
There are 2 answers
0
Richard
On
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:
/* Main object for namespacing */
var Ad = function(obj) {};
/*
Register your ad with the dimensions of the current ad.
- This is basically an event handler for the the ad frame.
- 728 initial ad width
- 90 initial ad height
*/
Ad.prototype.registerExpand = function() {
$sf.ext.register(728, 90, function(status, data){});
};
/* Expand function to be called on click or load */
Ad.prototype.expandAd = function() {
/* Get the current geometry of your ad */
var self = $sf.ext.geom().self;
/*
Set the new geometry
- Increase height 315 pixels
- Expand downward by setting the bottom to the new height minus the current height
*/
$sf.ext.expand({
h: 315,
b: 315 - self.h
});
};
/* Intialize, register, and expand */
var ad = new Ad();
ad.registerExpand();
ad.expandAd();
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in IFRAME
- Why a component? Drawer of mui Does not work inside Iframe
- How can I catch all DOMExceptions thrown in Firefox?
- Embeded Google slides opens new tab on screen touch (mobile mode)
- Jira helpdesk widget doesn't create an iframe when script is loaded dynamically
- HTTP Client Hint headers are not sent from an iframe
- Excel embedding through OneDrive: preview is correct, while the end result is not
- SameSite None Cookie on Authentication Cookie On WordPress Website
- Is it possible to interact with SSO between Website A and Website B?
- SSO to Grafana embeded in iframe
- AudioContext not heard although it is running
- How to disable page-break before a long iframe while printing?
- How to get a postMessage message from Duda into the embedded iframe?
- auto login with Grafana
- PagerDuty Integration
- iframe hosted on CloudRun not firing onLoad event in React JS
Related Questions in ADS
- Google adsense ads.txt status cannot be not found
- How to clear cache of a json file in my Godaddy Wordpress website automatically when I update it
- How to fix - The selected currency and country of Nigeria/NGN are incompatible
- How remove disgusting disqus ads
- Targeting with Google Apps Script for Google Ads Performance Max Campaign
- Video.js keeps playing after pausing it (while playing ads via IMA)
- I can't set the custom conversion event to be active in Meta Pixel. what did i do wrong?
- Can I use AppLovin Max Programmatic Method to show MRec Ads inside a widget in Flutter?
- Prevent Expandable Ads as a Publisher
- Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGoogleMobileAdsModule' could not be found
- Facebook Developer Accout Restriction
- Data safety form for Admob (Answer new questions about account deletion)
- Google ads remarketing label conversion
- How to use Platformview to view Applovin_max MREC and banner ads
- Seeking Strategies to Enhance Facebook Ad Conversions for E-Commerce in the US and UK Markets
Related Questions in GOOGLE-DFP
- 2 GAM Sponsorship line items never rotate despite sharing a unit. The second only appears in it's second slot the first only has one slot
- What is this error all zero-area slot sizes were removed?
- One of the following macros is required in code snippet: %%VIEW_URL_UNESC%%, %%VIEW_URL_ESC%%
- Prebid - exisiting gpt tag conflicts with Prebid js script
- infinite scroll - can not serve multiple ads on same page using same ad unit
- Can I avoid or restrict to push the Native fills for certain ads which is served from DFP_DS or Admob they not relevant to our app in iOS
- Ad Manager (DFP) popup banner
- Can a SafeFrame render inside another SafeFrame?
- How to show a advert depending on screen size
- How to catch error in googletag.cmd.push(function() { googletag.display('div-id'); });?
- Copying creatives while preserving line item associations in DFP/GAM
- Google-Mobile-Ads-SDK fails with initialization error while used in both main app and framework
- Why am I getting "Invalid GPT fixed size specification"
- google-dfp enable lazy loading only on certain ads
- Can I get the link of IMA ad?
Related Questions in DOUBLE-CLICK-ADVERTISING
- Double-click bid manager v2 create query with groupBys
- Google ad manager 360 - ad request discrepancy due to placing GPT tags via multiple GAMs
- How to pass creativeId into CampaignCreativeAssociations.insert() method using Google CM360 API
- Copying creatives while preserving line item associations in DFP/GAM
- How to resolve the error: "columns[11]: custom variable cannot be found" when running an SA360 API call?
- Changing an iframe ad's img src with Javascript
- API call to dfareporting.ads.insert failed with error: 12043 : Creative must be assigned to the campaign before it can be associated with the ad
- Unexpected error while getting the method or property insert on object Apiary.dfareporting.ads
- GoogleJsonResponseException: API call to dfareporting.ads.insert failed with error: Invalid value at 'profile_id' (TYPE_INT64)
- How to use double click bid manager(DBM) API in python
- How do I setup DFP GPT ad slot for multiple ad placements on same page?
- Disable DoubleClick Tag When Embedded YouTube Video Loads
- "Unexpected error" thrown when using UrlFetch
- Dollar sign + double curly braces inside string in google sheets (some kind of variable?)
- Deactivating DoubleClick via Google Analytics
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
There are 2 possible solutions:
1) using
SafeFrame APIpros:
cons:
2) code your own API with
window.postMessage()javascript methodcons:
pros:
1) using
SafeFrame APIThis 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-tagto<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