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

AdRiver Bid Adapter: add new bid adapter #6514

Merged
merged 6 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
129 changes: 129 additions & 0 deletions modules/adriverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// ADRIVER BID ADAPTER for Prebid 1.13
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'adriver';
const ADRIVER_BID_URL = 'https://pb.adriver.ru/cgi-bin/bid.cgi';
const TIME_TO_LIVE = 3000;

export const spec = {

code: BIDDER_CODE,

/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!bid.params.siteid;
},

buildRequests: function (validBidRequests) {
utils.logInfo('validBidRequests', validBidRequests);

let win = utils.getWindowLocation();
let customID = Math.round(Math.random() * 999999999) + '-' + Math.round(new Date() / 1000) + '-1-46-';
let siteId = utils.getBidIdParameter('siteid', validBidRequests[0].params) + '';
let currency = utils.getBidIdParameter('currency', validBidRequests[0].params);
currency = currency ? currency + '' : 'RUB';

const payload = {
'at': 1,
'cur': [currency],
'site': {
'name': win.origin,
'domain': win.hostname,
'id': siteId,
'page': win.href
},
'id': customID,
'user': {
'buyerid': 0
},
'device': {
'ip': '195.209.111.14',
Fridoom007 marked this conversation as resolved.
Show resolved Hide resolved
'ua': window.navigator.userAgent
},
'imp': []
};

utils._each(validBidRequests, (bid) => {
utils._each(bid.sizes, (sizes) => {
let width; let height; let par;
let bidFloor = utils.getBidIdParameter('bidfloor', bid.params);
let dealId = utils.getBidIdParameter('dealid', bid.params);
if (typeof sizes[0] === 'number' && typeof sizes[1] === 'number') {
width = sizes[0];
height = sizes[1];
}
par = {
'id': bid.params.placementId,
'ext': {'query': 'bn=15&custom=111=' + bid.bidId},
'banner': {
'w': width || undefined,
'h': height || undefined
},
'bidfloor': bidFloor || 0,
'bidfloorcur': currency,
'secure': 0
};
if (dealId) {
par.pmp = {
'private_auction': 1,
'deals': [{
'id': dealId,
'bidfloor': bidFloor || 0,
Fridoom007 marked this conversation as resolved.
Show resolved Hide resolved
'bidfloorcur': currency
}]
};
}
utils.logInfo('par', par);
payload.imp.push(par);
});
});

const payloadString = JSON.stringify(payload);

return {
method: 'POST',
url: ADRIVER_BID_URL,
data: payloadString,
};
},

interpretResponse: function (serverResponse, bidRequest) {
utils.logInfo('serverResponse.body.seatbid', serverResponse.body.seatbid);
const bidResponses = [];
let nurl = 0;
utils._each(serverResponse.body.seatbid, (seatbid) => {
utils.logInfo('_each', seatbid);
var bid = seatbid.bid[0];
if (bid.nurl !== undefined) {
nurl = bid.nurl.split('://');
nurl = window.location.protocol + '//' + nurl[1];
nurl = nurl.replace(/\$\{AUCTION_PRICE\}/, bid.price);
}

if (bid.price >= 0 && bid.impid !== undefined && nurl !== 0 && bid.dealid === undefined) {
let bidResponse = {
requestId: bid.ext || undefined,
cpm: bid.price,
width: bid.w,
height: bid.h,
creativeId: bid.impid || undefined,
currency: serverResponse.body.cur,
netRevenue: true,
ttl: TIME_TO_LIVE,
ad: '<IFRAME SRC="' + bid.nurl + '" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true" STYLE ="WIDTH:' + bid.w + 'px; HEIGHT:' + bid.h + 'px"></IFRAME>'
};
utils.logInfo('bidResponse', bidResponse);
bidResponses.push(bidResponse);
}
});
return bidResponses;
}

};
registerBidder(spec);
21 changes: 21 additions & 0 deletions modules/adriverBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Overview

Module Name: AdRiver Bidder Adapter
Module Type: Bidder Adapter
Maintainer: support@adriver.ru

# Description

Module that connects to AdRiver's demand sources.

# Test Parameters

bids: [{
bidder: 'adriver',
params: {
siteid: '216200',
placementId: '55:test_placement',
bidfloor: 1
dealid: 'dealidTest'
}
}]
201 changes: 201 additions & 0 deletions test/spec/modules/adriverBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { expect } from 'chai';
import { spec } from 'modules/adriverBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import * as bidderFactory from 'src/adapters/bidderFactory.js';
import { auctionManager } from 'src/auctionManager.js';
const ENDPOINT = 'https://pb.adriver.ru/cgi-bin/bid.cgi';

describe('adriverAdapter', function () {
const adapter = newBidder(spec);

describe('inherited functions', function () {
it('exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});

describe('isBidRequestValid', function () {
let bid = {
'bidder': 'adriver',
'params': {
'placementId': '55:test_placement',
'siteid': 'testSiteID'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600], [300, 250]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

it('should return true when required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
});

describe('buildRequests', function () {
let getAdUnitsStub;
let bidRequests = [
{
'bidder': 'adriver',
'params': {
'placementId': '55:test_placement',
'siteid': 'testSiteID',
'bidfloor': 3,
'dealid': 'dealidTest'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600], [300, 250]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
'transactionId': '04f2659e-c005-4eb1-a57c-fa93145e3843'
}
];

beforeEach(function() {
getAdUnitsStub = sinon.stub(auctionManager, 'getAdUnits').callsFake(function() {
return [];
});
});

afterEach(function() {
getAdUnitsStub.restore();
});

it('should exist currency', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);

expect(payload.cur).to.exist;
});

it('should exist at', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);

expect(payload.at).to.exist;
expect(payload.at).to.deep.equal(1);
});

it('should parse imp', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);

expect(payload.imp[0]).to.exist;
expect(payload.imp[0].id).to.deep.equal('55:test_placement');

expect(payload.imp[0].ext).to.exist;
expect(payload.imp[0].ext.query).to.deep.equal('bn=15&custom=111=' + '30b31c1838de1e');

expect(payload.imp[0].banner).to.exist;
expect(payload.imp[0].banner.w).to.deep.equal(300);
expect(payload.imp[0].banner.h).to.deep.equal(250);
});

it('should parse pmp', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);

expect(payload.imp[0].pmp).to.exist;

expect(payload.imp[0].pmp.deals).to.exist;

expect(payload.imp[0].pmp.deals[0].bidfloor).to.exist;
expect(payload.imp[0].pmp.deals[0].bidfloor).to.deep.equal(3);

expect(payload.imp[0].pmp.deals[0].bidfloorcur).to.exist;
expect(payload.imp[0].pmp.deals[0].bidfloorcur).to.deep.equal('RUB');
});

it('sends bid request to ENDPOINT via POST', function () {
const request = spec.buildRequests(bidRequests);
expect(request.url).to.equal(ENDPOINT);
expect(request.method).to.equal('POST');
});
});

describe('interpretResponse', function () {
let bfStub;
before(function() {
bfStub = sinon.stub(bidderFactory, 'getIabSubCategory');
});

after(function() {
bfStub.restore();
});

let response = {
'id': '221594457-1615288400-1-46-',
'bidid': 'D8JW8XU8-L5m7qFMNQGs7i1gcuPvYMEDOKsktw6e9uLy5Eebo9HftVXb0VpKj4R2dXa93i6QmRhjextJVM4y1SqodMAh5vFOb_eVkHA',
'seatbid': [{
'bid': [{
'id': '1',
'impid': '/19968336/header-bid-tag-0',
'price': 4.29,
'h': 250,
'w': 300,
'adid': '7121351',
'adomain': ['http://ikea.com'],
'nurl': 'https://ad.adriver.ru/cgi-bin/erle.cgi?expid=D8JW8XU8-L5m7qFMNQGs7i1gcuPvYMEDOKsktw6e9uLy5Eebo9HftVXb0VpKj4R2dXa93i6QmRhjextJVM4y1SqodMAh5vFOb_eVkHA&bid=7121351&wprc=4.29&tuid=-1&custom=207=/19968336/header-bid-tag-0',
'cid': '717570',
'ext': '2c262a7058758d'
}]
}, {
'bid': [{
'id': '1',
'impid': '/19968336/header-bid-tag-0',
'price': 17.67,
'h': 600,
'w': 300,
'adid': '7121369',
'adomain': ['http://ikea.com'],
'nurl': 'https://ad.adriver.ru/cgi-bin/erle.cgi?expid=DdtToXX5cpTaMMxrJSEsOsUIXt3WmC3jOvuNI5DguDrY8edFG60Jg1M-iMkVNKQ4OiAdHSLPJLQQXMUXZfI9VbjMoGCb-zzOTPiMpshI&bid=7121369&wprc=17.67&tuid=-1&custom=207=/19968336/header-bid-tag-0',
'cid': '717570',
'ext': '2c262a7058758d'
}]
}],
'cur': 'RUB'
};

it('should get correct bid response', function () {
let expectedResponse = [
{
requestId: '2c262a7058758d',
cpm: 4.29,
width: 300,
height: 250,
creativeId: '/19968336/header-bid-tag-0',
currency: 'RUB',
netRevenue: true,
ttl: 3000,
ad: '<IFRAME SRC="https://ad.adriver.ru/cgi-bin/erle.cgi?expid=D8JW8XU8-L5m7qFMNQGs7i1gcuPvYMEDOKsktw6e9uLy5Eebo9HftVXb0VpKj4R2dXa93i6QmRhjextJVM4y1SqodMAh5vFOb_eVkHA&bid=7121351&wprc=4.29&tuid=-1&custom=207=/19968336/header-bid-tag-0" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true" STYLE ="WIDTH:300px; HEIGHT:250px"></IFRAME>'
}
];
let bidderRequest = {
bids: [{
bidId: '3db3773286ee59',
adUnitCode: 'code'
}]
};
let result = spec.interpretResponse({ body: response }, {bidderRequest});
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0]));
});

it('handles nobid responses', function () {
let response = {
'version': '0.0.1',
'tags': [{
'uuid': '84ab500420319d',
'tag_id': 5976557,
'auction_id': '297492697822162468',
'nobid': true
}]
};
let bidderRequest;

let result = spec.interpretResponse({ body: response }, {bidderRequest});
expect(result.length).to.equal(0);
});
});
});