Skip to content

Commit

Permalink
PubMatic Adapter: Bug fix to read all bids from seatBid array (#2520)
Browse files Browse the repository at this point in the history
* Support multiple bids for same adSize

* Add isArray check for seatbids
  • Loading branch information
PubMatic-OpenWrap authored and mike-chowla committed May 15, 2018
1 parent 3436a13 commit 27dca0f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
47 changes: 26 additions & 21 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,27 +268,32 @@ export const spec = {
interpretResponse: (response, request) => {
const bidResponses = [];
try {
if (response.body && response.body.seatbid && response.body.seatbid[0] && response.body.seatbid[0].bid) {
response.body.seatbid[0].bid.forEach(bid => {
let newBid = {
requestId: bid.impid,
cpm: (parseFloat(bid.price) || 0).toFixed(2),
width: bid.w,
height: bid.h,
creativeId: bid.crid || bid.id,
dealId: bid.dealid,
currency: CURRENCY,
netRevenue: NET_REVENUE,
ttl: 300,
referrer: utils.getTopWindowUrl(),
ad: bid.adm
};

if (bid.ext && bid.ext.deal_channel) {
newBid['dealChannel'] = dealChannelValues[bid.ext.deal_channel] || null;
}

bidResponses.push(newBid);
if (response.body && response.body.seatbid && utils.isArray(response.body.seatbid)) {
// Supporting multiple bid responses for same adSize
response.body.seatbid.forEach(seatbidder => {
seatbidder.bid &&
utils.isArray(seatbidder.bid) &&
seatbidder.bid.forEach(bid => {
let newBid = {
requestId: bid.impid,
cpm: (parseFloat(bid.price) || 0).toFixed(2),
width: bid.w,
height: bid.h,
creativeId: bid.crid || bid.id,
dealId: bid.dealid,
currency: CURRENCY,
netRevenue: NET_REVENUE,
ttl: 300,
referrer: utils.getTopWindowUrl(),
ad: bid.adm
};

if (bid.ext && bid.ext.deal_channel) {
newBid['dealChannel'] = dealChannelValues[bid.ext.deal_channel] || null;
}

bidResponses.push(newBid);
});
});
}
} catch (error) {
Expand Down
29 changes: 29 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ describe('PubMatic adapter', () => {
'deal_channel': 6
}
}]
}, {
'bid': [{
'id': '74858439-49D7-4169-BA5D-44A046315BEF',
'impid': '22bddb28db77e',
'price': 1.7,
'adm': 'image3.pubmatic.com Layer based creative',
'h': 250,
'w': 300,
'ext': {
'deal_channel': 5
}
}]
}]
}
};
Expand Down Expand Up @@ -213,13 +225,30 @@ describe('PubMatic adapter', () => {
expect(response[0].ttl).to.equal(300);
expect(response[0].referrer).to.include(utils.getTopWindowUrl());
expect(response[0].ad).to.equal(bidResponses.body.seatbid[0].bid[0].adm);

expect(response[1].requestId).to.equal(bidResponses.body.seatbid[1].bid[0].impid);
expect(response[1].cpm).to.equal((bidResponses.body.seatbid[1].bid[0].price).toFixed(2));
expect(response[1].width).to.equal(bidResponses.body.seatbid[1].bid[0].w);
expect(response[1].height).to.equal(bidResponses.body.seatbid[1].bid[0].h);
if (bidResponses.body.seatbid[1].bid[0].crid) {
expect(response[1].creativeId).to.equal(bidResponses.body.seatbid[1].bid[0].crid);
} else {
expect(response[1].creativeId).to.equal(bidResponses.body.seatbid[1].bid[0].id);
}
expect(response[1].dealId).to.equal(bidResponses.body.seatbid[1].bid[0].dealid);
expect(response[1].currency).to.equal('USD');
expect(response[1].netRevenue).to.equal(false);
expect(response[1].ttl).to.equal(300);
expect(response[1].referrer).to.include(utils.getTopWindowUrl());
expect(response[1].ad).to.equal(bidResponses.body.seatbid[1].bid[0].adm);
});

it('should check for dealChannel value selection', () => {
let request = spec.buildRequests(bidRequests);
let response = spec.interpretResponse(bidResponses, request);
expect(response).to.be.an('array').with.length.above(0);
expect(response[0].dealChannel).to.equal('PMPG');
expect(response[1].dealChannel).to.equal('PREF');
});

it('should check for unexpected dealChannel value selection', () => {
Expand Down

0 comments on commit 27dca0f

Please sign in to comment.