Skip to content

Commit 2feb988

Browse files
PWyrembakrobertrmartinez
authored andcommitted
Update TrustX Bid Adapter (prebid#3563)
* 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
1 parent 88a7fe9 commit 2feb988

File tree

2 files changed

+274
-27
lines changed

2 files changed

+274
-27
lines changed

modules/trustxBidAdapter.js

+52-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export const spec = {
3636
buildRequests: function(validBidRequests, bidderRequest) {
3737
const auids = [];
3838
const bidsMap = {};
39+
const slotsMapByUid = {};
40+
const sizeMap = {};
3941
const bids = validBidRequests || [];
4042
let priceType = 'net';
4143
let reqId;
@@ -45,18 +47,41 @@ export const spec = {
4547
priceType = 'gross';
4648
}
4749
reqId = bid.bidderRequestId;
48-
if (!bidsMap[bid.params.uid]) {
49-
bidsMap[bid.params.uid] = [bid];
50-
auids.push(bid.params.uid);
50+
const {params: {uid}, adUnitCode} = bid;
51+
auids.push(uid);
52+
const sizesId = utils.parseSizesInput(bid.sizes);
53+
54+
if (!slotsMapByUid[uid]) {
55+
slotsMapByUid[uid] = {};
56+
}
57+
const slotsMap = slotsMapByUid[uid];
58+
if (!slotsMap[adUnitCode]) {
59+
slotsMap[adUnitCode] = {adUnitCode, bids: [bid], parents: []};
5160
} else {
52-
bidsMap[bid.params.uid].push(bid);
61+
slotsMap[adUnitCode].bids.push(bid);
5362
}
63+
const slot = slotsMap[adUnitCode];
64+
65+
sizesId.forEach((sizeId) => {
66+
sizeMap[sizeId] = true;
67+
if (!bidsMap[uid]) {
68+
bidsMap[uid] = {};
69+
}
70+
71+
if (!bidsMap[uid][sizeId]) {
72+
bidsMap[uid][sizeId] = [slot];
73+
} else {
74+
bidsMap[uid][sizeId].push(slot);
75+
}
76+
slot.parents.push({parent: bidsMap[uid], key: sizeId, uid});
77+
});
5478
});
5579

5680
const payload = {
5781
u: utils.getTopWindowUrl(),
5882
pt: priceType,
5983
auids: auids.join(','),
84+
sizes: utils.getKeys(sizeMap).join(','),
6085
r: reqId
6186
};
6287

@@ -138,8 +163,12 @@ function _addBidResponse(serverBid, bidsMap, priceType, bidResponses) {
138163
else {
139164
const awaitingBids = bidsMap[serverBid.auid];
140165
if (awaitingBids) {
141-
awaitingBids.forEach(bid => {
142-
const bidResponse = {
166+
const sizeId = `${serverBid.w}x${serverBid.h}`;
167+
if (awaitingBids[sizeId]) {
168+
const slot = awaitingBids[sizeId][0];
169+
170+
const bid = slot.bids.shift();
171+
bidResponses.push({
143172
requestId: bid.bidId, // bid.bidderRequestId,
144173
bidderCode: spec.code,
145174
cpm: serverBid.price,
@@ -151,9 +180,23 @@ function _addBidResponse(serverBid, bidsMap, priceType, bidResponses) {
151180
ttl: TIME_TO_LIVE,
152181
ad: serverBid.adm,
153182
dealId: serverBid.dealid
154-
};
155-
bidResponses.push(bidResponse);
156-
});
183+
});
184+
185+
if (!slot.bids.length) {
186+
slot.parents.forEach(({parent, key, uid}) => {
187+
const index = parent[key].indexOf(slot);
188+
if (index > -1) {
189+
parent[key].splice(index, 1);
190+
}
191+
if (!parent[key].length) {
192+
delete parent[key];
193+
if (!utils.getKeys(parent).length) {
194+
delete bidsMap[uid];
195+
}
196+
}
197+
});
198+
}
199+
}
157200
} else {
158201
errorMessage = LOG_ERROR_MESS.noPlacementCode + serverBid.auid;
159202
}

0 commit comments

Comments
 (0)