Skip to content

Commit

Permalink
AdbookPSP adapter updated with support of multiple Private Auction GA…
Browse files Browse the repository at this point in the history
…M Orders (prebid#7924)

Co-authored-by: Ankur <ankur.p@isocrates.com>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent 0958f52 commit 081cf74
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
37 changes: 27 additions & 10 deletions modules/adbookpspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function impBidsToPrebidBids(
}

const impToPrebidBid =
(bidderRequestBody, bidResponseCurrency, referrer, targetingMap) => (bid) => {
(bidderRequestBody, bidResponseCurrency, referrer, targetingMap) => (bid, bidIndex) => {
try {
const bidRequest = findBidRequest(bidderRequestBody, bid);

Expand All @@ -377,7 +377,7 @@ const impToPrebidBid =
let prebidBid = {
ad: bid.adm,
adId: bid.adid,
adserverTargeting: targetingMap[bid.impid],
adserverTargeting: targetingMap[bidIndex],
adUnitCode: bidRequest.tagid,
bidderRequestId: bidderRequestBody.id,
bidId: bid.id,
Expand Down Expand Up @@ -408,6 +408,9 @@ const impToPrebidBid =
};
}

if (deepAccess(bid, 'ext.pa_win') === true) {
prebidBid.auctionWinner = true;
}
return prebidBid;
} catch (error) {
logError(`${BIDDER_CODE}: Error while building bid`, error);
Expand All @@ -429,29 +432,43 @@ function buildTargetingMap(bids) {
const values = impIds.reduce((result, id) => {
result[id] = {
lineItemIds: [],
orderIds: [],
dealIds: [],
adIds: [],
adAndOrderIndexes: []
};

return result;
}, {});

bids.forEach((bid) => {
values[bid.impid].lineItemIds.push(bid.ext.liid);
values[bid.impid].dealIds.push(bid.dealid);
values[bid.impid].adIds.push(bid.adid);
bids.forEach((bid, bidIndex) => {
let impId = bid.impid;
values[impId].lineItemIds.push(bid.ext.liid);
values[impId].dealIds.push(bid.dealid);
values[impId].adIds.push(bid.adid);

if (deepAccess(bid, 'ext.ordid')) {
values[impId].orderIds.push(bid.ext.ordid);
bid.ext.ordid.split(TARGETING_VALUE_SEPARATOR).forEach((ordid, ordIndex) => {
let adIdIndex = values[impId].adIds.indexOf(bid.adid);
values[impId].adAndOrderIndexes.push(adIdIndex + '_' + ordIndex)
})
}
});

const targetingMap = {};

for (const id of impIds) {
targetingMap[id] = {
bids.forEach((bid, bidIndex) => {
let id = bid.impid;

targetingMap[bidIndex] = {
hb_liid_adbookpsp: values[id].lineItemIds.join(TARGETING_VALUE_SEPARATOR),
hb_deal_adbookpsp: values[id].dealIds.join(TARGETING_VALUE_SEPARATOR),
hb_ad_ord_adbookpsp: values[id].adAndOrderIndexes.join(TARGETING_VALUE_SEPARATOR),
hb_adid_c_adbookpsp: values[id].adIds.join(TARGETING_VALUE_SEPARATOR),
hb_ordid_adbookpsp: values[id].orderIds.join(TARGETING_VALUE_SEPARATOR),
};
}

})
return targetingMap;
}

Expand Down
20 changes: 17 additions & 3 deletions test/spec/modules/adbookpspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,11 @@ describe('adbookpsp bid adapter', () => {
ad: '<div>ad</div>',
adId: '5',
adserverTargeting: {
hb_ad_ord_adbookpsp: '0_0', // the value to the left of the underscore represents the index of the ad id and the number to the right represents the order index
hb_adid_c_adbookpsp: '5',
hb_deal_adbookpsp: 'werwetwerw',
hb_liid_adbookpsp: '2342345',
hb_ordid_adbookpsp: '567843',
},
referrer: 'http://prebid-test-page.io:8080/banner.html',
lineItemId: '2342345',
Expand All @@ -516,9 +518,11 @@ describe('adbookpsp bid adapter', () => {
adId: '10',
adUnitCode: 'div-gpt-ad-837465923534-0',
adserverTargeting: {
hb_ad_ord_adbookpsp: '0_0',
hb_adid_c_adbookpsp: '10',
hb_deal_adbookpsp: 'dsfxcxcvxc',
hb_liid_adbookpsp: '2121221',
hb_ordid_adbookpsp: '5678234',
},
bidId: 'bid4321',
bidderRequestId: '999ccceeee11',
Expand Down Expand Up @@ -556,14 +560,18 @@ describe('adbookpsp bid adapter', () => {

expect(bids).to.have.length(2);
expect(bids[0].adserverTargeting).to.deep.equal({
hb_ad_ord_adbookpsp: '0_0',
hb_adid_c_adbookpsp: '5',
hb_deal_adbookpsp: 'werwetwerw',
hb_liid_adbookpsp: '2342345',
hb_adid_c_adbookpsp: '5',
hb_ordid_adbookpsp: '567843',
});
expect(bids[1].adserverTargeting).to.deep.equal({
hb_ad_ord_adbookpsp: '0_0',
hb_adid_c_adbookpsp: '10',
hb_deal_adbookpsp: 'dsfxcxcvxc',
hb_liid_adbookpsp: '2121221',
hb_adid_c_adbookpsp: '10',
hb_ordid_adbookpsp: '5678234',
});
});

Expand All @@ -580,9 +588,11 @@ describe('adbookpsp bid adapter', () => {
expect(bids).to.have.length(2);
for (const bid of bids) {
expect(bid.adserverTargeting).to.deep.equal({
hb_ad_ord_adbookpsp: '0_0,1_0',
hb_adid_c_adbookpsp: '5,10',
hb_deal_adbookpsp: 'werwetwerw,dsfxcxcvxc',
hb_liid_adbookpsp: '2342345,2121221',
hb_adid_c_adbookpsp: '5,10',
hb_ordid_adbookpsp: '567843,5678234',
});
}
});
Expand Down Expand Up @@ -670,9 +680,11 @@ describe('adbookpsp bid adapter', () => {
);

expect(bids[0].adserverTargeting).to.deep.equal({
hb_ad_ord_adbookpsp: '0_0',
hb_adid_c_adbookpsp: '10',
hb_deal_adbookpsp: 'dsfxcxcvxc',
hb_liid_adbookpsp: '2121221',
hb_ordid_adbookpsp: '5678234',
});
});

Expand Down Expand Up @@ -1279,6 +1291,7 @@ const exchangeResponse = {
nurl: 'http://win.example.url',
ext: {
liid: '2342345',
ordid: '567843',
},
cat: ['IAB2-1', 'IAB2-2', 'IAB2-3'],
adomain: ['advertiser.com'],
Expand All @@ -1301,6 +1314,7 @@ const exchangeResponse = {
nurl: 'http://win.example.url',
ext: {
liid: '2121221',
ordid: '5678234',
},
cat: ['IAB2-3'],
adomain: ['advertiser.com', 'campaign.advertiser.com'],
Expand Down

0 comments on commit 081cf74

Please sign in to comment.