Skip to content
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

Merged
merged 30 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
031fa56
Add trustx adapter and tests for it
PWyrembak Aug 15, 2017
319cadd
update integration example
PWyrembak Aug 15, 2017
0e877f9
Merge remote-tracking branch 'upstream/master'
PWyrembak Aug 16, 2017
0425234
Merge remote-tracking branch 'upstream/master'
PWyrembak Sep 8, 2017
69ab1f4
Update trustx adapter
PWyrembak Sep 9, 2017
817f2fa
Merge remote-tracking branch 'upstream/master'
PWyrembak Sep 19, 2017
ef50012
Post-review fixes of Trustx adapter
PWyrembak Sep 19, 2017
bd5b75c
Merge remote-tracking branch 'upstream/master'
PWyrembak Oct 3, 2017
bff944b
Merge remote-tracking branch 'upstream/master'
PWyrembak Oct 10, 2017
843440d
Code improvement for trustx adapter: changed default price type from …
PWyrembak Oct 10, 2017
cd01e9b
Merge remote-tracking branch 'upstream/master'
PWyrembak Oct 17, 2017
aa249b5
Update TrustX adapter to support the 1.0 version
PWyrembak Oct 17, 2017
119728b
Merge remote-tracking branch 'upstream/master'
PWyrembak Oct 20, 2017
5f60ac3
Make requested changes for TrustX adapter
PWyrembak Oct 20, 2017
2628673
Updated markdown file for TrustX adapter
PWyrembak Oct 24, 2017
b3badf9
Merge remote-tracking branch 'upstream/master'
PWyrembak Oct 26, 2017
292b4dd
Fix TrustX adapter and spec file
PWyrembak Oct 26, 2017
b3e1465
Merge remote-tracking branch 'upstream/master'
PWyrembak Dec 19, 2017
09b581a
Update TrustX adapter: r parameter was added to ad request as cache b…
PWyrembak Dec 19, 2017
7b16a1c
Merge remote-tracking branch 'upstream/master'
PWyrembak May 17, 2018
73b7249
Add support of gdpr to Trustx Bid Adapter
PWyrembak May 17, 2018
08ca36e
Merge remote-tracking branch 'upstream/master'
PWyrembak Aug 6, 2018
4974e55
Add wtimeout to ad request params for TrustX Bid Adapter
PWyrembak Aug 6, 2018
240306f
Merge remote-tracking branch 'upstream/master'
PWyrembak Aug 10, 2018
9175298
TrustX Bid Adapter: remove last ampersand in the ad request
PWyrembak Aug 10, 2018
d98be98
Merge remote-tracking branch 'upstream/master'
PWyrembak Feb 12, 2019
83b3aaf
Update TrustX Bid Adapter to support identical uids in parameters
PWyrembak Feb 15, 2019
3e348d2
Merge remote-tracking branch 'upstream/master'
PWyrembak Feb 15, 2019
fc2e05a
Merge remote-tracking branch 'upstream/master'
PWyrembak Feb 20, 2019
f77c2ee
Update TrustX Bid Adapter to ignore bids that sizes do not match the …
PWyrembak Feb 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 79 additions & 21 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});
Copy link
Collaborator

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.

});
});

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

Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PWyrembak This makes it possible that TrustX will return a bidResponse with a different size for an AdUnit which does not request that size?

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I am not sure this is desirable?

What is the reason for doing this?

If TrustX is flexible about the creative sizes it returns, then why not mark the bidResponse object with a valid size from the bidRequest?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
Expand Down
Loading