Skip to content

Commit

Permalink
Update TrustX Bid Adapter (#3563)
Browse files Browse the repository at this point in the history
* Add trustx adapter and tests for it

* update integration example

* Update trustx adapter

* Post-review fixes of Trustx adapter

* Code improvement for trustx adapter: changed default price type from gross to net

* Update TrustX adapter to support the 1.0 version

* Make requested changes for TrustX adapter

* Updated markdown file for TrustX adapter

* Fix TrustX adapter and spec file

* Update TrustX adapter: r parameter was added to ad request as cache buster

* Add support of gdpr to Trustx Bid Adapter

* Add wtimeout to ad request params for TrustX Bid Adapter

* TrustX Bid Adapter: remove last ampersand in the ad request

* Update TrustX Bid Adapter to support identical uids in parameters

* Update TrustX Bid Adapter to ignore bids that sizes do not match the size of the request
  • Loading branch information
PWyrembak authored and robertrmartinez committed Feb 22, 2019
1 parent 88a7fe9 commit 2feb988
Show file tree
Hide file tree
Showing 2 changed files with 274 additions and 27 deletions.
61 changes: 52 additions & 9 deletions modules/trustxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const spec = {
buildRequests: function(validBidRequests, bidderRequest) {
const auids = [];
const bidsMap = {};
const slotsMapByUid = {};
const sizeMap = {};
const bids = validBidRequests || [];
let priceType = 'net';
let reqId;
Expand All @@ -45,18 +47,41 @@ export const spec = {
priceType = 'gross';
}
reqId = bid.bidderRequestId;
if (!bidsMap[bid.params.uid]) {
bidsMap[bid.params.uid] = [bid];
auids.push(bid.params.uid);
const {params: {uid}, adUnitCode} = bid;
auids.push(uid);
const sizesId = utils.parseSizesInput(bid.sizes);

if (!slotsMapByUid[uid]) {
slotsMapByUid[uid] = {};
}
const slotsMap = slotsMapByUid[uid];
if (!slotsMap[adUnitCode]) {
slotsMap[adUnitCode] = {adUnitCode, bids: [bid], parents: []};
} else {
bidsMap[bid.params.uid].push(bid);
slotsMap[adUnitCode].bids.push(bid);
}
const slot = slotsMap[adUnitCode];

sizesId.forEach((sizeId) => {
sizeMap[sizeId] = true;
if (!bidsMap[uid]) {
bidsMap[uid] = {};
}

if (!bidsMap[uid][sizeId]) {
bidsMap[uid][sizeId] = [slot];
} else {
bidsMap[uid][sizeId].push(slot);
}
slot.parents.push({parent: bidsMap[uid], key: sizeId, uid});
});
});

const payload = {
u: utils.getTopWindowUrl(),
pt: priceType,
auids: auids.join(','),
sizes: utils.getKeys(sizeMap).join(','),
r: reqId
};

Expand Down Expand Up @@ -138,8 +163,12 @@ function _addBidResponse(serverBid, bidsMap, priceType, bidResponses) {
else {
const awaitingBids = bidsMap[serverBid.auid];
if (awaitingBids) {
awaitingBids.forEach(bid => {
const bidResponse = {
const sizeId = `${serverBid.w}x${serverBid.h}`;
if (awaitingBids[sizeId]) {
const slot = awaitingBids[sizeId][0];

const bid = slot.bids.shift();
bidResponses.push({
requestId: bid.bidId, // bid.bidderRequestId,
bidderCode: spec.code,
cpm: serverBid.price,
Expand All @@ -151,9 +180,23 @@ function _addBidResponse(serverBid, bidsMap, priceType, bidResponses) {
ttl: TIME_TO_LIVE,
ad: serverBid.adm,
dealId: serverBid.dealid
};
bidResponses.push(bidResponse);
});
});

if (!slot.bids.length) {
slot.parents.forEach(({parent, key, uid}) => {
const index = parent[key].indexOf(slot);
if (index > -1) {
parent[key].splice(index, 1);
}
if (!parent[key].length) {
delete parent[key];
if (!utils.getKeys(parent).length) {
delete bidsMap[uid];
}
}
});
}
}
} else {
errorMessage = LOG_ERROR_MESS.noPlacementCode + serverBid.auid;
}
Expand Down
Loading

0 comments on commit 2feb988

Please sign in to comment.