Options to serve responsive ads on Google DFP / AdManager iOS

1k Views Asked by At

Currently I'm trying to setup the Google DFP ads for using a dynamic responsive frame. By this I want to create a banner ad which has a relation to the screen size rather than predefining a size such as 300x250 or 300x240.

The DFPBannerView should be able to take a custom CGRect as argument and the DFP lineitem should take the full size of the CGRect.

I tried this by the following techniques:

  • Creating a DFP ad unit with smart banner as primary size. This doesn't work because a lineitem in DFP requires a fixed size. Furthermore, the smart banner seems to be limited to 90 in height.

  • Creating a DFP ad unit with the out of page as primary size. I didn't managed to get impressions on this ad unit.

Is there any way Google DFP can be setup for mobile banners to take the full size that is set?

1

There are 1 best solutions below

0
On

Not sure if I understood correctly but I guess you will have to do something like this: https://www.monetizemore.com/blog/how-to-make-dfp-ad-units-responsive-2/

I used this example to add responsive units to my existing DFP calls.

Note that I don't used this top script of "var useSSL". I used what DFP gives me at unit creation.

I created 2 Ads unit and created 3 sizes that I needeed to each unit (728x90, 468x60 and 320x50). Mine calls for Adsense ads, but sure you can call your line itens.

After all and to be more direct as possible I just added:

var mapping = googletag.sizeMapping().

addSize([992, 0], [728, 90]).
addSize([768, 0], [468, 60]).
addSize([320, 0], [320, 50]).build();

var mapping2 = googletag.sizeMapping().

addSize([992, 0], [728, 90]).
addSize([768, 0], [468, 60]).
addSize([320, 0], [320, 50]).build();

googletag.defineSlot('/1071122/Your-ads-div-id1', [300, 250], 'div-gpt-ad-123123123-0').defineSizeMapping(mapping).addService(googletag.pubads());
googletag.defineSlot('/1071122/Your-ads-div-id2', [300, 250], 'div-gpt-ad-123123123-0').defineSizeMapping(mapping2).addService(googletag.pubads());

While searching for examples to do this I found many tricky methods. But sincerely don't need nothing of that. I just did it work right now and this thread was one of the "answers" that I found looking for examples. Bookmarked this to help if I was able to do to my site. If I can, maybe I resume all code to make it work like:

<!-- Adsense/DFP default header -->
<script type="text/javascript" async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
  var googletag = googletag || {};
  googletag.cmd = googletag.cmd || [];
</script>

<script>
googletag.cmd.push(function() {

    //here you create a var to map your sizes for this unit - mine is equal in addSizes but you can create how many you need and with different sizes you like. First [992, 0] is for resolution and later [728, 90] is the banner size to this resolution (you can put more than one size for each resolution if you like)
    var mapping = googletag.sizeMapping().

    addSize([992, 0], [728, 90]).
    addSize([768, 0], [468, 60]).
    addSize([320, 0], [320, 50]).build();

    var mapping2 = googletag.sizeMapping().

    addSize([992, 0], [728, 90]).
    addSize([768, 0], [468, 60]).
    addSize([320, 0], [320, 50]).build();

    googletag.defineSlot('/1231231/your-ads-div-id-1', [300, 250], 'div-gpt-ad-1231231231231-0').defineSizeMapping(mapping).addService(googletag.pubads());
    googletag.defineSlot('/1231231/your-ads-div-id-2', [300, 250], 'div-gpt-ad-1231231231231-0').defineSizeMapping(mapping2).addService(googletag.pubads());

    googletag.pubads().enableSingleRequest();
    googletag.pubads().collapseEmptyDivs();
    googletag.enableServices();

});
</script>

That's it. With this code you have two responsive ad units calling DFP (Ads) Adsense banners with 3 sizes to 3 different resolutions.

And of course, in your HTML you'll have to call these DIVs like:

<!-- /1231231/your-ads-div-id-1 -->
<div id="div-gpt-ad-123123123-0">
<script>
googletag.cmd.push(function() { googletag.display("div-gpt-ad-1231231231231-0"); });
</script>
</div>