Skip to content

Commit

Permalink
Merge branch 'master' into bidderSettings-allowStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Feb 1, 2022
2 parents df27267 + c0d4135 commit c242a08
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 52 deletions.
98 changes: 69 additions & 29 deletions modules/dspxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js';
const BIDDER_CODE = 'dspx';
const ENDPOINT_URL = 'https://buyer.dspx.tv/request/';
const ENDPOINT_URL_DEV = 'https://dcbuyer.dspx.tv/request/';
const DEFAULT_VAST_FORMAT = 'vast2';
const GVLID = 602;

export const spec = {
Expand All @@ -26,37 +25,30 @@ export const spec = {
const referrer = bidderRequest.refererInfo.referer;
const bidId = bidRequest.bidId;
const isDev = params.devMode || false;
const pbcode = bidRequest.adUnitCode || false; // div id
const auctionId = bidRequest.auctionId || false;

let endpoint = isDev ? ENDPOINT_URL_DEV : ENDPOINT_URL;
let payload = {};

if (isBannerRequest(bidRequest)) {
let size = getBannerSizes(bidRequest)[0];
payload = {
_f: 'html',
alternative: 'prebid_js',
inventory_item_id: placementId,
srw: size.width,
srh: size.height,
idt: 100,
rnd: rnd,
ref: referrer,
bid_id: bidId,
};
} else {
let size = getVideoSizes(bidRequest)[0];
let vastFormat = params.vastFormat || DEFAULT_VAST_FORMAT;
payload = {
_f: vastFormat,
alternative: 'prebid_js',
inventory_item_id: placementId,
srw: size.width,
srh: size.height,
idt: 100,
rnd: rnd,
ref: referrer,
bid_id: bidId,
};
let mediaTypesInfo = getMediaTypesInfo(bidRequest);
let type = isBannerRequest(bidRequest) ? BANNER : VIDEO;
let sizes = mediaTypesInfo[type];

let payload = {
_f: 'auto',
alternative: 'prebid_js',
inventory_item_id: placementId,
srw: sizes ? sizes[0].width : 0,
srh: sizes ? sizes[0].height : 0,
idt: 100,
rnd: rnd,
ref: referrer,
bid_id: bidId,
pbver: '$prebid.version$'
};

if (mediaTypesInfo[VIDEO] !== undefined && params.vastFormat !== undefined) {
payload.vf = params.vastFormat;
}

if (params.pfilter !== undefined) {
Expand Down Expand Up @@ -94,6 +86,15 @@ export const spec = {
payload.did_uid2 = bidRequest.userId.uid2;
}

if (auctionId) {
payload.auctionId = auctionId;
}
if (pbcode) {
payload.pbcode = pbcode;
}

payload.media_types = convertMediaInfoForRequest(mediaTypesInfo);

return {
method: 'GET',
url: endpoint,
Expand Down Expand Up @@ -256,4 +257,43 @@ function parseSizes(sizes) {
return [parseSize(sizes)]; // or a single one ? (ie. [728,90])
}

/**
* Get MediaInfo object for server request
*
* @param mediaTypesInfo
* @returns {*}
*/
function convertMediaInfoForRequest(mediaTypesInfo) {
let requestData = {};
Object.keys(mediaTypesInfo).forEach(mediaType => {
requestData[mediaType] = mediaTypesInfo[mediaType].map(size => {
return size.width + 'x' + size.height;
}).join(',');
});
return requestData;
}

/**
* Get media types info
*
* @param bid
*/
function getMediaTypesInfo(bid) {
let mediaTypesInfo = {};

if (bid.mediaTypes) {
Object.keys(bid.mediaTypes).forEach(mediaType => {
if (mediaType === BANNER) {
mediaTypesInfo[mediaType] = getBannerSizes(bid);
}
if (mediaType === VIDEO) {
mediaTypesInfo[mediaType] = getVideoSizes(bid);
}
});
} else {
mediaTypesInfo[BANNER] = getBannerSizes(bid);
}
return mediaTypesInfo;
}

registerBidder(spec);
3 changes: 2 additions & 1 deletion modules/dspxBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ DSPx adapter for Prebid.
bids: [{
bidder: 'dspx',
params: {
placement: '106'
placement: '106',
vastFormat: 'vast2|vast4' // set vast format
}
}]
}
Expand Down
1 change: 1 addition & 0 deletions modules/mediasquareBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const BIDDER_ENDPOINT_WINNING = 'winning';

export const spec = {
code: BIDDER_CODE,
gvlid: 791,
aliases: ['msq'], // short code
supportedMediaTypes: [BANNER, NATIVE, VIDEO],
/**
Expand Down
1 change: 1 addition & 0 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const spec = {
let bidders = []
if (responses) {
_each(responses, (response) => {
if (!(response && response.body && response.body.ext && response.body.ext.responsetimemillis)) return
_each(Object.keys(response.body.ext.responsetimemillis), b => bidders.push(b))
})
}
Expand Down
4 changes: 2 additions & 2 deletions modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_TIMEOUT = 1000;
const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io';
const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io';
const ADAPTER_VERSION = '1.2.9';
const ADAPTER_VERSION = '1.2.10';

function isBidRequestValid(bid) {
const adUnitSizes = getAdUnitSizes(bid);
Expand Down Expand Up @@ -41,7 +41,7 @@ function buildRequests(validBidRequests, bidderRequest) {
const openRtbBidRequestBanner = {
id: bidderRequest.auctionId,
tmax: DEFAULT_TIMEOUT,
at: 2,
at: 1,
regs: {
ext: {
gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? 1 : 0
Expand Down
8 changes: 8 additions & 0 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,15 @@ export function newTargeting(auctionManager) {
let bidsReceived = auctionManager.getBidsReceived();

if (!config.getConfig('useBidCache')) {
// don't use bid cache (i.e. filter out bids not in the latest auction)
bidsReceived = bidsReceived.filter(bid => latestAuctionForAdUnit[bid.adUnitCode] === bid.auctionId)
} else {
// if custom bid cache filter function exists, run for each bid from
// previous auctions. If it returns true, include bid in bid pool
const filterFunction = config.getConfig('bidCacheFilterFunction');
if (typeof filterFunction === 'function') {
bidsReceived = bidsReceived.filter(bid => latestAuctionForAdUnit[bid.adUnitCode] === bid.auctionId || !!filterFunction(bid))
}
}

bidsReceived = bidsReceived
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ export function getCurrencyRates() {
};
}

export function createBidReceived({bidder, cpm, auctionId, responseTimestamp, adUnitCode, adId, status, ttl, requestId}) {
export function createBidReceived({bidder, cpm, auctionId, responseTimestamp, adUnitCode, adId, status, ttl, requestId, mediaType}) {
let bid = {
'bidderCode': bidder,
'width': '300',
Expand Down Expand Up @@ -1259,6 +1259,7 @@ export function createBidReceived({bidder, cpm, auctionId, responseTimestamp, ad
'hb_pb': cpm,
'foobar': '300x250'
}),
'mediaType': mediaType,
'netRevenue': true,
'currency': 'USD',
'ttl': (!ttl) ? 300 : ttl
Expand Down
35 changes: 20 additions & 15 deletions test/spec/modules/dspxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('dspxAdapter', function () {
'bidId': '30b31c1838de1e1',
'bidderRequestId': '22edbae2733bf61',
'auctionId': '1d1a030790a475',
'adUnitCode': 'testDiv1',
'userId': {
'netId': '123',
'uid2': '456'
Expand Down Expand Up @@ -98,7 +99,8 @@ describe('dspxAdapter', function () {
],
'bidId': '30b31c1838de1e3',
'bidderRequestId': '22edbae2733bf69',
'auctionId': '1d1a030790a477'
'auctionId': '1d1a030790a477',
'adUnitCode': 'testDiv2'
},
{
'bidder': 'dspx',
Expand All @@ -120,13 +122,15 @@ describe('dspxAdapter', function () {

'bidId': '30b31c1838de1e4',
'bidderRequestId': '22edbae2733bf67',
'auctionId': '1d1a030790a478'
'auctionId': '1d1a030790a478',
'adUnitCode': 'testDiv3'
},
{
'bidder': 'dspx',
'params': {
'placement': '101',
'devMode': true
'devMode': true,
'vastFormat': 'vast4'
},
'mediaTypes': {
'video': {
Expand All @@ -136,7 +140,8 @@ describe('dspxAdapter', function () {
},
'bidId': '30b31c1838de1e41',
'bidderRequestId': '22edbae2733bf67',
'auctionId': '1d1a030790a478'
'auctionId': '1d1a030790a478',
'adUnitCode': 'testDiv4'
}

];
Expand All @@ -157,16 +162,16 @@ describe('dspxAdapter', function () {
it('sends bid request to our endpoint via GET', function () {
expect(request1.method).to.equal('GET');
expect(request1.url).to.equal(ENDPOINT_URL);
let data = request1.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('_f=html&alternative=prebid_js&inventory_item_id=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e1&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bprivate_auction%5D=0&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgdpr_consent%5D=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&pfilter%5Bgdpr%5D=true&bcat=IAB2%2CIAB4&dvt=desktop&did_netid=123&did_uid2=456');
let data = request1.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&');
expect(data).to.equal('_f=auto&alternative=prebid_js&inventory_item_id=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e1&pbver=test&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bprivate_auction%5D=0&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgdpr_consent%5D=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&pfilter%5Bgdpr%5D=true&bcat=IAB2%2CIAB4&dvt=desktop&did_netid=123&did_uid2=456&auctionId=1d1a030790a475&pbcode=testDiv1&media_types%5Bbanner%5D=300x250');
});

var request2 = spec.buildRequests([bidRequests[1]], bidderRequest)[0];
it('sends bid request to our DEV endpoint via GET', function () {
expect(request2.method).to.equal('GET');
expect(request2.url).to.equal(ENDPOINT_URL_DEV);
let data = request2.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('_f=html&alternative=prebid_js&inventory_item_id=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e2&pfilter%5Bgdpr_consent%5D=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&pfilter%5Bgdpr%5D=true&prebidDevMode=1');
let data = request2.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&');
expect(data).to.equal('_f=auto&alternative=prebid_js&inventory_item_id=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e2&pbver=test&pfilter%5Bgdpr_consent%5D=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&pfilter%5Bgdpr%5D=true&prebidDevMode=1&auctionId=1d1a030790a476&media_types%5Bbanner%5D=300x250');
});

// Without gdprConsent
Expand All @@ -179,23 +184,23 @@ describe('dspxAdapter', function () {
it('sends bid request without gdprConsent to our endpoint via GET', function () {
expect(request3.method).to.equal('GET');
expect(request3.url).to.equal(ENDPOINT_URL);
let data = request3.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('_f=html&alternative=prebid_js&inventory_item_id=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e3&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bprivate_auction%5D=0&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop');
let data = request3.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&');
expect(data).to.equal('_f=auto&alternative=prebid_js&inventory_item_id=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e3&pbver=test&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bprivate_auction%5D=0&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop&auctionId=1d1a030790a477&pbcode=testDiv2&media_types%5Bbanner%5D=300x250');
});

var request4 = spec.buildRequests([bidRequests[3]], bidderRequestWithoutGdpr)[0];
it('sends bid request without gdprConsent to our DEV endpoint via GET', function () {
expect(request4.method).to.equal('GET');
expect(request4.url).to.equal(ENDPOINT_URL_DEV);
let data = request4.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('_f=html&alternative=prebid_js&inventory_item_id=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e4&prebidDevMode=1');
let data = request4.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&');
expect(data).to.equal('_f=auto&alternative=prebid_js&inventory_item_id=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e4&pbver=test&prebidDevMode=1&auctionId=1d1a030790a478&pbcode=testDiv3&media_types%5Bvideo%5D=640x480&media_types%5Bbanner%5D=300x250');
});

var request5 = spec.buildRequests([bidRequests[4]], bidderRequestWithoutGdpr)[0];
it('sends bid video request to our rads endpoint via GET', function () {
it('sends bid video request to our endpoint via GET', function () {
expect(request5.method).to.equal('GET');
let data = request5.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('_f=vast2&alternative=prebid_js&inventory_item_id=101&srw=640&srh=480&idt=100&bid_id=30b31c1838de1e41&prebidDevMode=1');
let data = request5.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&');
expect(data).to.equal('_f=auto&alternative=prebid_js&inventory_item_id=101&srw=640&srh=480&idt=100&bid_id=30b31c1838de1e41&pbver=test&vf=vast4&prebidDevMode=1&auctionId=1d1a030790a478&pbcode=testDiv4&media_types%5Bvideo%5D=640x480');
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/spec/modules/oguryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('OguryBidAdapter', function () {
const defaultTimeout = 1000;
const expectedRequestObject = {
id: bidRequests[0].auctionId,
at: 2,
at: 1,
tmax: defaultTimeout,
imp: [{
id: bidRequests[0].bidId,
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('OguryBidAdapter', function () {
},
ext: {
prebidversion: '$prebid.version$',
adapterversion: '1.2.9'
adapterversion: '1.2.10'
}
};

Expand Down Expand Up @@ -482,7 +482,7 @@ describe('OguryBidAdapter', function () {
advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[0].adomain
},
nurl: openRtbBidResponse.body.seatbid[0].bid[0].nurl,
adapterVersion: '1.2.9',
adapterVersion: '1.2.10',
prebidVersion: '$prebid.version$'
}, {
requestId: openRtbBidResponse.body.seatbid[0].bid[1].impid,
Expand All @@ -499,7 +499,7 @@ describe('OguryBidAdapter', function () {
advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[1].adomain
},
nurl: openRtbBidResponse.body.seatbid[0].bid[1].nurl,
adapterVersion: '1.2.9',
adapterVersion: '1.2.10',
prebidVersion: '$prebid.version$'
}]

Expand Down
Loading

0 comments on commit c242a08

Please sign in to comment.