Search code examples
prebid.js

Getting all bids from each Header bidding partners


We are implementing some header bidding partners on our wrapper using prebid. Is it possible to get all bids from each ssp.

Any help appreciated.


Solution

  • If you’re asking about demand, this is dependent on each SSP. For example there may be a segment pixel or placement in one SSP that will always give you a $10 bid, but that wouldnt apply to the other SSPs.

    If your asking about getting data on all the bids, you may want to check out pbjs.getBidResponses() which returns an object with the ad units and bids

    Heres a sample response from pbjs.getBidResponses() which can then be used however you'd need that data:

    {
        "div-id-one": {
            "bids": [
                {
                    "bidderCode": "appnexus",
                    "width": 970,
                    "height": 250,
                    "statusMessage": "Bid available",
                    "adId": "1293a95bb3e9615",
                    "mediaType": "banner",
                    "creative_id": 77765220,
                    "cpm": 0.7826,
                    "adUrl": "https://...",
                    "requestId": "57f961f3-a32b-45df-a180-9d5e53fb9070",
                    "responseTimestamp": 1513707536256,
                    "requestTimestamp": 1513707535321,
                    "bidder": "appnexus",
                    "adUnitCode": "div-id-one",
                    "timeToRespond": 935,
                    "pbLg": "0.50",
                    "pbMg": "0.70",
                    "pbHg": "0.78",
                    "pbAg": "0.75",
                    "pbDg": "0.78",
                    "pbCg": "0.78",
                    "size": "970x250",
                    "adserverTargeting": {
                        "hb_bidder": "appnexus",
                        "hb_adid": "1293a95bb3e9615",
                        "hb_pb": "0.78",
                        "hb_size": "970x250"
                    }
                }
            ]
        },
        "div-id-two": {
            "bids": []
        }
    }
    

    Theres also a great example on prebid.org on how to output this to console.table that could be helpful as well:

    var responses = pbjs.getBidResponses();
    var output = [];
    for (var adunit in responses) {
        if (responses.hasOwnProperty(adunit)) {
            var bids = responses[adunit].bids;
            for (var i = 0; i < bids.length; i++) {
                var b = bids[i];
                output.push({
                    'adunit': adunit, 'adId': b.adId, 'bidder': b.bidder,
                    'time': b.timeToRespond, 'cpm': b.cpm, 'msg': b.statusMessage
                });
            }
        }
    }
    if (output.length) {
        if (console.table) {
            console.table(output);
        } else {
            for (var j = 0; j < output.length; j++) {
                console.log(output[j]);
            }
        }
    } else {
        console.warn('NO prebid responses');
    }