Skip to content

Commit

Permalink
Taboola Bid Adapter : add for support fledge (#11192)
Browse files Browse the repository at this point in the history
* Support fledge in taboola adapter

* Append corner cases handling for the empty or partial response

* Swap json parse to safeJsonParse

* Rename test param
  • Loading branch information
aleskanderl authored Mar 19, 2024
1 parent 40dd3b6 commit 4b4648e
Show file tree
Hide file tree
Showing 2 changed files with 401 additions and 4 deletions.
55 changes: 51 additions & 4 deletions modules/taboolaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import {deepAccess, deepSetValue, getWindowSelf, replaceAuctionPrice} from '../src/utils.js';
import {deepAccess, deepSetValue, getWindowSelf, replaceAuctionPrice, isArray, safeJSONParse} from '../src/utils.js';
import {getStorageManager} from '../src/storageManager.js';
import {ajax} from '../src/ajax.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
Expand Down Expand Up @@ -151,12 +151,59 @@ export const spec = {
if (!serverResponse || !serverResponse.body) {
return [];
}

const bids = [];
const fledgeAuctionConfigs = [];
if (!serverResponse.body.seatbid || !serverResponse.body.seatbid.length || !serverResponse.body.seatbid[0].bid || !serverResponse.body.seatbid[0].bid.length) {
return [];
if (!serverResponse.body.ext || !serverResponse.body.ext.igbid || !serverResponse.body.ext.igbid.length) {
return [];
}
} else {
bids.push(...converter.fromORTB({response: serverResponse.body, request: request.data}).bids);
}
if (isArray(serverResponse.body.ext?.igbid)) {
serverResponse.body.ext.igbid.forEach((igbid) => {
if (!igbid || !igbid.igbuyer || !igbid.igbuyer.length || !igbid.igbuyer[0].buyerdata) {
return;
}
let buyerdata = safeJSONParse(igbid.igbuyer[0]?.buyerdata)
if (!buyerdata) {
return;
}
const perBuyerSignals = {};
igbid.igbuyer.forEach(buyerItem => {
if (!buyerItem || !buyerItem.buyerdata || !buyerItem.origin) {
return;
}
let parsedData = safeJSONParse(buyerItem.buyerdata)
if (!parsedData || !parsedData.perBuyerSignals || !(buyerItem.origin in parsedData.perBuyerSignals)) {
return;
}
perBuyerSignals[buyerItem.origin] = parsedData.perBuyerSignals[buyerItem.origin];
});
const impId = igbid?.impid;
fledgeAuctionConfigs.push({
impId,
config: {
seller: buyerdata?.seller,
resolveToConfig: buyerdata?.resolveToConfig,
sellerSignals: {},
sellerTimeout: buyerdata?.sellerTimeout,
perBuyerSignals,
auctionSignals: {},
decisionLogicUrl: buyerdata?.decisionLogicUrl,
interestGroupBuyers: buyerdata?.interestGroupBuyers,
perBuyerTimeouts: buyerdata?.perBuyerTimeouts,
},
});
});
}

const bids = converter.fromORTB({response: serverResponse.body, request: request.data}).bids;
if (fledgeAuctionConfigs.length) {
return {
bids,
fledgeAuctionConfigs,
};
}
return bids;
},
onBidWon: (bid) => {
Expand Down
Loading

0 comments on commit 4b4648e

Please sign in to comment.