How to handle multiple adSlots from GPT togheter with prebid.js

600 views Asked by At

Im migrating from Adnuntius too GPT and are using prebid.js I need diffrent slots on each page and when im trying to define them, i only get them to work if i have diffrent sizes on each slot.Lets say that i use 970x250 on the first one and change the second one to 300x250 it will work.

I Think my issue is somewhere where i define the slots, or maybe with our adunit?

I want to be able to use the same size for all slots. site_level is our adunit name from gpt

var div_sizes_l = [[970, 250], [980, 200], [980, 240]];
var PREBID_TIMEOUT = 1000;
var FAILSAFE_TIMEOUT = 3000;

var adUnits = [
    {
        code: 'div-gpt-ad-Landing_Top',  
        mediaTypes: {
            banner: {
                sizes:  div_sizes_l,
            }
        },
        bids: [
            {
                bidder: 'rubicon',
                params: {
                    accountId: '20562',
                    siteId: '2153438',
                    zoneId: '11258332'
                }
            }
        ]
    },
    //
    {
        code: 'div-gpt-ad-Landing_Middle',
        mediaTypes: {
            banner: {
                sizes:  div_sizes_l,
            }
        },
        bids: [
            {
                bidder: 'rubicon',
                params: {
                    accountId: '20562',
                    siteId: '2153438',
                    zoneId: '11258344'
                }
            },
        ]
    },
];

var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
    googletag.pubads().disableInitialLoad();
});

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

pbjs.que.push(function() {
    pbjs.addAdUnits(adUnits);
    pbjs.requestBids({
        bidsBackHandler: initAdserver,
        timeout: PREBID_TIMEOUT
    });
});

function initAdserver() {
    if (pbjs.initAdserverSet) return;
    pbjs.initAdserverSet = true;
    googletag.cmd.push(function() {
        pbjs.que.push(function() {
            pbjs.setTargetingForGPTAsync();
            googletag.pubads().refresh();
        });
    });
}
// in case PBJS doesn't load
setTimeout(function() {
    initAdserver();
}, FAILSAFE_TIMEOUT);

 googletag.cmd = googletag.cmd || [];

 googletag.cmd.push(function() {
    googletag.defineSlot('/21855748559/site_level', 
   div_sizes_l, 
  'div-gpt-ad-Landing_Top').addService(googletag.pubads());
    googletag.pubads().setTargeting('position', 'Landing_Top');

    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
});
googletag.cmd.push(function() {
    googletag.defineSlot('/21855748559/site_level', 
    div_sizes_l, 
   'div-gpt-ad-Landing_Middle').addService(googletag.pubads());
    googletag.pubads().setTargeting('position', 'Landing_Middle');

    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
});
1

There are 1 answers

1
ngIf_happy On

Your prebid code is correct, it will be able to use that variable for all sizes in the auction across both adunits. However, because you are using Rubicon, this is why there is a problem. Their adapter specifically requires an array of adunit sizes ID#s for them to then read and pass you a bid response of the right size. [See here for their docs] (http://prebid.org/dev-docs/bidders/rubicon.html). Example:

{
    bidder: 'rubicon',
    params: {
        accountId: '20562',
        siteId: '2153438',
        zoneId: '11258332',
        sizes: [15, 3, 2]
    }
}

As well here is their sizeMap for you to reference to pass the correct size IDs to them, this was pulled straight from their [adapter source] (https://github.com/prebid/Prebid.js/blob/master/modules/rubiconBidAdapter.js):

var sizeMap = {
  1: '468x60',
  2: '728x90',
  5: '120x90',
  8: '120x600',
  9: '160x600',
  10: '300x600',
  13: '200x200',
  14: '250x250',
  15: '300x250',
  16: '336x280',
  17: '240x400',
  19: '300x100',
  31: '980x120',
  32: '250x360',
  33: '180x500',
  35: '980x150',
  37: '468x400',
  38: '930x180',
  39: '750x100',
  40: '750x200',
  41: '750x300',
  42: '2x4',
  43: '320x50',
  44: '300x50',
  48: '300x300',
  53: '1024x768',
  54: '300x1050',
  55: '970x90',
  57: '970x250',
  58: '1000x90',
  59: '320x80',
  60: '320x150',
  61: '1000x1000',
  64: '580x500',
  65: '640x480',
  66: '930x600',
  67: '320x480',
  68: '1800x1000',
  72: '320x320',
  73: '320x160',
  78: '980x240',
  79: '980x300',
  80: '980x400',
  83: '480x300',
  94: '970x310',
  96: '970x210',
  101: '480x320',
  102: '768x1024',
  103: '480x280',
  105: '250x800',
  108: '320x240',
  113: '1000x300',
  117: '320x100',
  125: '800x250',
  126: '200x600',
  144: '980x600',
  145: '980x150',
  152: '1000x250',
  156: '640x320',
  159: '320x250',
  179: '250x600',
  195: '600x300',
  198: '640x360',
  199: '640x200',
  213: '1030x590',
  214: '980x360',
  221: '1x1',
  229: '320x180',
  232: '580x400',
  234: '6x6',
  251: '2x2',
  257: '400x600',
  264: '970x1000',
  265: '1920x1080',
  278: '320x500',
  288: '640x380'
};