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

RadsBidAdapter: Add adomains/userIds support and change banner ad type priority #6973

Merged
merged 4 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
153 changes: 113 additions & 40 deletions modules/radsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ const BIDDER_CODE = 'rads';
const ENDPOINT_URL = 'https://rads.recognified.net/md.request.php';
const ENDPOINT_URL_DEV = 'https://dcradn1.online-solution.biz/md.request.php';
const DEFAULT_VAST_FORMAT = 'vast2';
const GVLID = 602;

export const spec = {
code: BIDDER_CODE,
aliases: ['rads'],
gvlid: GVLID,
aliases: [],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bid) {
return !!(bid.params.placement);
},
buildRequests: function(validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const params = bidRequest.params;
const videoData = utils.deepAccess(bidRequest, 'mediaTypes.video') || {};
const sizes = utils.parseSizesInput(videoData.playerSize || bidRequest.sizes)[0];
const [width, height] = sizes.split('x');
const placementId = params.placement;

const rnd = Math.floor(Math.random() * 99999999999);
Expand All @@ -30,34 +29,37 @@ export const spec = {

let endpoint = isDev ? ENDPOINT_URL_DEV : ENDPOINT_URL;

let payload = {};
if (isVideoRequest(bidRequest)) {
let vastFormat = params.vastFormat || DEFAULT_VAST_FORMAT;
payload = {
rt: vastFormat,
_f: 'prebid_js',
_ps: placementId,
srw: width,
srh: height,
idt: 100,
rnd: rnd,
p: referrer,
bid_id: bidId,
};
let payload = {
_f: 'prebid_js',
_ps: placementId,
idt: 100,
rnd: rnd,
p: referrer,
bid_id: bidId,
};

let sizes;
if (isBannerRequest(bidRequest)) {
sizes = getBannerSizes(bidRequest);
payload.rt = 'bid-response';
payload.srw = sizes[0].width;
payload.srh = sizes[0].height;
} else {
payload = {
rt: 'bid-response',
_f: 'prebid_js',
_ps: placementId,
srw: width,
srh: height,
idt: 100,
rnd: rnd,
p: referrer,
bid_id: bidId,
};
let vastFormat = params.vastFormat || DEFAULT_VAST_FORMAT;
ncolletti marked this conversation as resolved.
Show resolved Hide resolved
sizes = getVideoSizes(bidRequest);
payload.rt = vastFormat;
payload.srw = sizes[0].width;
payload.srh = sizes[0].height;
}
prepareExtraParams(params, payload, bidderRequest);

if (sizes.length > 1) {
payload.alt_ad_sizes = [];
for (let i = 1; i < sizes.length; i++) {
payload.alt_ad_sizes.push(sizes[i].width + 'x' + sizes[i].height);
}
}

prepareExtraParams(params, payload, bidderRequest, bidRequest);

return {
method: 'GET',
Expand All @@ -84,7 +86,10 @@ export const spec = {
dealId: dealId,
currency: currency,
netRevenue: netRevenue,
ttl: config.getConfig('_bidderTimeout')
ttl: config.getConfig('_bidderTimeout'),
meta: {
advertiserDomains: response.adomain || []
}
};

if (response.vastXml) {
Expand Down Expand Up @@ -151,18 +156,15 @@ function objectToQueryString(obj, prefix) {
}
return str.join('&');
}

/**
* Check if it's a video bid request
* Add extra params to server request
*
* @param {BidRequest} bid - Bid request generated from ad slots
* @returns {boolean} True if it's a video bid
* @param params
* @param payload
* @param bidderRequest
* @param {BidRequest} bidRequest - Bid request generated from ad slots
*/
function isVideoRequest(bid) {
return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video');
}

function prepareExtraParams(params, payload, bidderRequest) {
function prepareExtraParams(params, payload, bidderRequest, bidRequest) {
if (params.pfilter !== undefined) {
payload.pfilter = params.pfilter;
}
Expand Down Expand Up @@ -196,6 +198,77 @@ function prepareExtraParams(params, payload, bidderRequest) {
if (params.ip !== undefined) {
payload.i = params.ip;
}

if (bidRequest.userId && bidRequest.userId.netId) {
payload.did_netid = bidRequest.userId.netId;
}
if (bidRequest.userId && bidRequest.userId.uid2) {
payload.did_uid2 = bidRequest.userId.uid2;
}
}

/**
* Check if it's a banner bid request
*
* @param {BidRequest} bid - Bid request generated from ad slots
* @returns {boolean} True if it's a banner bid
*/
function isBannerRequest(bid) {
return bid.mediaType === 'banner' || !!utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoRequest(bid);
}

/**
* Check if it's a video bid request
*
* @param {BidRequest} bid - Bid request generated from ad slots
* @returns {boolean} True if it's a video bid
*/
function isVideoRequest(bid) {
return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video');
}

/**
* Get video sizes
*
* @param {BidRequest} bid - Bid request generated from ad slots
* @returns {object} True if it's a video bid
*/
function getVideoSizes(bid) {
return parseSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes);
}

/**
* Get banner sizes
*
* @param {BidRequest} bid - Bid request generated from ad slots
* @returns {object} True if it's a video bid
*/
function getBannerSizes(bid) {
return parseSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes);
}

/**
* Parse size
* @param sizes
* @returns {width: number, h: height}
*/
function parseSize(size) {
let sizeObj = {}
sizeObj.width = parseInt(size[0], 10);
sizeObj.height = parseInt(size[1], 10);
return sizeObj;
}

/**
* Parse sizes
* @param sizes
* @returns {{width: number , height: number }[]}
*/
function parseSizes(sizes) {
if (Array.isArray(sizes[0])) { // is there several sizes ? (ie. [[728,90],[200,300]])
return sizes.map(size => parseSize(size));
}
return [parseSize(sizes)]; // or a single one ? (ie. [728,90])
}

registerBidder(spec);
1 change: 1 addition & 0 deletions modules/radsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RADS Bidder Adapter for Prebid.js 1.x
bidder: "rads",
params: {
placement: 3, // placement ID
vastFormat: "vast2", // vast2(default) or vast4
devMode: true // if true: library uses dev server for tests
}
}
Expand Down
39 changes: 30 additions & 9 deletions test/spec/modules/radsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,24 @@ describe('radsAdapter', function () {
'sizes': [
[300, 250]
],
'mediaTypes': {
'video': {
'playerSize': [640, 480],
'context': 'instream'
},
'banner': {
'sizes': [
[100, 100], [400, 400], [500, 500]
]
}
},
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475'
'auctionId': '1d1a030790a475',
'userId': {
'netId': '123',
'uid2': '456'
}
}, {
'bidder': 'rads',
'params': {
Expand All @@ -78,7 +93,7 @@ describe('radsAdapter', function () {
},
'mediaTypes': {
'video': {
'playerSize': [640, 480],
'playerSize': [[640, 480], [500, 500], [600, 600]],
'context': 'instream'
}
},
Expand Down Expand Up @@ -110,27 +125,27 @@ describe('radsAdapter', function () {
it('sends bid request to our endpoint via GET', function () {
expect(request[0].method).to.equal('GET');
let data = request[0].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('rt=bid-response&_f=prebid_js&_ps=6682&srw=300&srh=250&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop&i=1.1.1.1');
expect(data).to.equal('_f=prebid_js&_ps=6682&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&rt=bid-response&srw=100&srh=100&alt_ad_sizes%5B0%5D=400x400&alt_ad_sizes%5B1%5D=500x500&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop&i=1.1.1.1&did_netid=123&did_uid2=456');
});

it('sends bid video request to our rads endpoint via GET', function () {
expect(request[1].method).to.equal('GET');
let data = request[1].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('rt=vast2&_f=prebid_js&_ps=6682&srw=640&srh=480&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgeo%5D%5Bregion%5D=DE-BE&bcat=IAB2%2CIAB4&dvt=desktop');
expect(data).to.equal('_f=prebid_js&_ps=6682&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&rt=vast2&srw=640&srh=480&alt_ad_sizes%5B0%5D=500x500&alt_ad_sizes%5B1%5D=600x600&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgeo%5D%5Bregion%5D=DE-BE&bcat=IAB2%2CIAB4&dvt=desktop');
});

// with gdprConsent
const request2 = spec.buildRequests(bidRequests, bidderRequestGdprConsent);
it('sends bid request to our endpoint via GET', function () {
expect(request2[0].method).to.equal('GET');
let data = request2[0].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('rt=bid-response&_f=prebid_js&_ps=6682&srw=300&srh=250&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&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&i=1.1.1.1');
expect(data).to.equal('_f=prebid_js&_ps=6682&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&rt=bid-response&srw=100&srh=100&alt_ad_sizes%5B0%5D=400x400&alt_ad_sizes%5B1%5D=500x500&pfilter%5Bfloorprice%5D=1000000&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&i=1.1.1.1&did_netid=123&did_uid2=456');
});

it('sends bid video request to our rads endpoint via GET', function () {
expect(request2[1].method).to.equal('GET');
let data = request2[1].data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid');
expect(data).to.equal('rt=vast2&_f=prebid_js&_ps=6682&srw=640&srh=480&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgeo%5D%5Bregion%5D=DE-BE&pfilter%5Bgdpr_consent%5D=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&pfilter%5Bgdpr%5D=true&bcat=IAB2%2CIAB4&dvt=desktop');
expect(data).to.equal('_f=prebid_js&_ps=6682&idt=100&p=some_referrer.net&bid_id=30b31c1838de1e&rt=vast2&srw=640&srh=480&alt_ad_sizes%5B0%5D=500x500&alt_ad_sizes%5B1%5D=600x600&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&pfilter%5Bgeo%5D%5Bregion%5D=DE-BE&pfilter%5Bgdpr_consent%5D=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&pfilter%5Bgdpr%5D=true&bcat=IAB2%2CIAB4&dvt=desktop');
});
});

Expand All @@ -146,7 +161,8 @@ describe('radsAdapter', function () {
'currency': 'EUR',
'ttl': 60,
'netRevenue': true,
'zone': '6682'
'zone': '6682',
'adomain': ['bdomain']
}
};
let serverVideoResponse = {
Expand Down Expand Up @@ -174,7 +190,8 @@ describe('radsAdapter', function () {
currency: 'EUR',
netRevenue: true,
ttl: 300,
ad: '<!-- test creative -->'
ad: '<!-- test creative -->',
meta: {advertiserDomains: ['bdomain']}
}, {
requestId: '23beaa6af6cdde',
cpm: 0.5,
Expand All @@ -186,7 +203,8 @@ describe('radsAdapter', function () {
netRevenue: true,
ttl: 300,
vastXml: '{"reason":7001,"status":"accepted"}',
mediaType: 'video'
mediaType: 'video',
meta: {advertiserDomains: []}
}];

it('should get the correct bid response by display ad', function () {
Expand All @@ -202,6 +220,8 @@ describe('radsAdapter', function () {
}];
let result = spec.interpretResponse(serverBannerResponse, bidRequest[0]);
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]));
expect(result[0].meta.advertiserDomains.length).to.equal(1);
expect(result[0].meta.advertiserDomains[0]).to.equal(expectedResponse[0].meta.advertiserDomains[0]);
});

it('should get the correct rads video bid response by display ad', function () {
Expand All @@ -220,6 +240,7 @@ describe('radsAdapter', function () {
}];
let result = spec.interpretResponse(serverVideoResponse, bidRequest[0]);
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[1]));
expect(result[0].meta.advertiserDomains.length).to.equal(0);
});

it('handles empty bid response', function () {
Expand Down