Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

New Feature for One-off Calls

Open Heray opened this issue 11 years ago • 2 comments

As a publisher, I'd like to have one-off calls to certain ad units. For example, I have an interstitial format only after a user has interacted with my site for a bit. I don't need to call it right away, because some users would not stay on the page for that long.

Heray avatar Aug 18 '15 16:08 Heray

We're working on it! Here's an alpha example we're currently testing with:

var oneOffAdUnits = [{
    code: '/19968336/header-bid-tag-0',
    sizes: [[300, 250], [300, 600]],
    bids: [
            {
                bidder: 'appnexus',
                params: {
                   placementId: '4799418'
                }
            }
    ],
    // called either when timeout is hit or all bids are back.
    // bids: [{bidderCode: 'appnexus', ...}]
    bidsCallbackHandler: function(adUnitCode, bids) {
        // Handle the bid responses
        pbjs.setTargetingForGPTAsync([adUnitCode]);

        // Optional helper function to get slot object from an ad unit code.
        // You may already have the slot object
        var slotObj = pbjs.getGPTSlot(adUnitCode);

        googletag.pubads().refresh([slotObj]);
    }
}]

/* This function will make pre-bid requests and call the bids back callback handler.
   Note that the ad units will not be inserted into the pbjs.adUnits array. This is
   an "one-off" pre-bid call.
   You can also pass in a timeout (in ms) for the requestBids function. The default 
   setting is 3000ms. When the timeout is hit, the bidsCallbackHandler will execute.
*/
pbjs.requestBidsForAdUnits(newAdUnits, 400)

ghost avatar Aug 18 '15 16:08 ghost

We're changing the design to be more flexible with better callback support:

/* Request bids for all ad units.
   The bidsBack function will be called when either PREBID_TIMEOUT is
   reached, or when all bids come back, whichever happens sooner.
*/
pbjs.requestBids({
    // Optionally, you can pass in selected set of ad unit codes to only
    // request bids for those ad units.
    // adUnitCodes: ['/19936/header-bid-tag-0', '/19936/header-bid-tag-1']

    // Or, pass in the ad units. Note that these ad units would not be added
    // to the global adUnits array.
    // [{ code: 'header-bid-tag-0', sizes:[], bids: [] }, ...]

    timeout: PREBID_TIMEOUT,
    bidsBack: function(bidResponses) {
        pbjs.setTargetingForGPTAsync();
        googletag.pubads().refresh(); 

        // Or, you can refresh only selected set of ad units through GPT
        // googletag.pubads().refresh([slot0, slot1]); 
    }
});  

ghost avatar Aug 19 '15 17:08 ghost