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 all 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
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});
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 @@ -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]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for this.

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