-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update TrustX Bid Adapter #3563
Changes from 28 commits
031fa56
319cadd
0e877f9
0425234
69ab1f4
817f2fa
ef50012
bd5b75c
bff944b
843440d
cd01e9b
aa249b5
119728b
5f60ac3
2628673
b3badf9
292b4dd
b3e1465
09b581a
7b16a1c
73b7249
08ca36e
4974e55
240306f
9175298
d98be98
83b3aaf
3e348d2
fc2e05a
f77c2ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
}; | ||
|
||
|
@@ -91,6 +116,7 @@ export const spec = { | |
interpretResponse: function(serverResponse, bidRequest) { | ||
serverResponse = serverResponse && serverResponse.body; | ||
const bidResponses = []; | ||
const remainingServerBids = []; | ||
const bidsMap = bidRequest.bidsMap; | ||
const priceType = bidRequest.data.pt; | ||
|
||
|
@@ -103,7 +129,12 @@ export const spec = { | |
|
||
if (!errorMessage && serverResponse.seatbid) { | ||
serverResponse.seatbid.forEach(respItem => { | ||
_addBidResponse(_getBidFromResponse(respItem), bidsMap, priceType, bidResponses); | ||
_addBidResponse(_getBidFromResponse(respItem), bidsMap, priceType, bidResponses, remainingServerBids); | ||
}); | ||
} | ||
if (remainingServerBids.length) { | ||
remainingServerBids.forEach(serverBid => { | ||
_addBidResponse(serverBid, bidsMap, priceType, bidResponses); | ||
}); | ||
} | ||
if (errorMessage) utils.logError(errorMessage); | ||
|
@@ -130,30 +161,57 @@ function _getBidFromResponse(respItem) { | |
return respItem && respItem.bid && respItem.bid[0]; | ||
} | ||
|
||
function _addBidResponse(serverBid, bidsMap, priceType, bidResponses) { | ||
function _addBidResponse(serverBid, bidsMap, priceType, bidResponses, remainingServerBids) { | ||
if (!serverBid) return; | ||
let errorMessage; | ||
if (!serverBid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(serverBid); | ||
if (!serverBid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); | ||
else { | ||
const ignoreSizes = !remainingServerBids; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PWyrembak This makes it possible that TrustX will return a For instance if I request two adUnits, {
code: 'Test-Slot-1',
mediaTypes: {
banner: {
sizes: [
[728, 90]
],
}
},
bids: [{
bidder: "trustx",
params: {
uid: '44',
priceType: 'gross' // by default is 'net'
}
}]
},
{
code: 'Test-Slot-2',
mediaTypes: {
banner: {
sizes: [
[300, 250], [300, 600]
],
}
},
bids: [{
bidder: "trustx",
params: {
uid: 45,
priceType: 'gross'
}
}]
} Then I can see TrustX bid on the 728x90 slot but it uses a size from the other adUnit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also lead to confusion within the analytics adapters and downstream GPT reporting possibly if I am not mistaken. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @robertrmartinez We have updated our bid adapter logic in order to ignore bids which don't match respective slot sizes. Please review. |
||
const awaitingBids = bidsMap[serverBid.auid]; | ||
if (awaitingBids) { | ||
awaitingBids.forEach(bid => { | ||
const bidResponse = { | ||
requestId: bid.bidId, // bid.bidderRequestId, | ||
bidderCode: spec.code, | ||
cpm: serverBid.price, | ||
width: serverBid.w, | ||
height: serverBid.h, | ||
creativeId: serverBid.auid, // bid.bidId, | ||
currency: 'USD', | ||
netRevenue: priceType !== 'gross', | ||
ttl: TIME_TO_LIVE, | ||
ad: serverBid.adm, | ||
dealId: serverBid.dealid | ||
}; | ||
bidResponses.push(bidResponse); | ||
let sizeId = `${serverBid.w}x${serverBid.h}`; | ||
|
||
if (!awaitingBids[sizeId]) { | ||
if (ignoreSizes) { | ||
sizeId = utils.getKeys(awaitingBids)[0]; | ||
} else { | ||
remainingServerBids.push(serverBid); | ||
return; | ||
} | ||
} | ||
|
||
const slot = awaitingBids[sizeId][0]; | ||
|
||
const bid = slot.bids.shift(); | ||
bidResponses.push({ | ||
requestId: bid.bidId, // bid.bidderRequestId, | ||
bidderCode: spec.code, | ||
cpm: serverBid.price, | ||
width: serverBid.w, | ||
height: serverBid.h, | ||
creativeId: serverBid.auid, // bid.bidId, | ||
currency: 'USD', | ||
netRevenue: priceType !== 'gross', | ||
ttl: TIME_TO_LIVE, | ||
ad: serverBid.adm, | ||
dealId: serverBid.dealid | ||
}); | ||
|
||
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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a circular reference which is not ideal.
But I will not hold up the merge for it.