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

Vrtcal Bid Adapter: add adomain and make 5.0 compliant #7106

Merged
merged 4 commits into from
Jun 29, 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
94 changes: 94 additions & 0 deletions modules/vrtcalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import {ajax} from '../src/ajax.js';

export const spec = {
code: 'vrtcal',
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
if (bid.bidId == '' || bid.auctionId == '') { return false; } else { return true; }// No extras params required
},
buildRequests: function (bidRequests) {
const requests = bidRequests.map(function (bid) {
const params = {

prebidJS: 1,
prebidAdUnitCode: bid.adUnitCode,
id: bid.bidId,
imp: [{
id: '1',
banner: {
},
bidfloor: 0.75
}],
site: {
id: 'VRTCAL_FILLED',
name: 'VRTCAL_FILLED',
cat: ['VRTCAL_FILLED'],
domain: decodeURIComponent(window.location.href).replace('https://', '').replace('http://', '').split('/')[0]

},
device: {
ua: 'VRTCAL_FILLED',
ip: 'VRTCAL_FILLED'
}
};

if (typeof (bid.mediaTypes) !== 'undefined' && typeof (bid.mediaTypes.banner) !== 'undefined' && typeof (bid.mediaTypes.banner.sizes) !== 'undefined') {
params.imp[0].banner.w = bid.mediaTypes.banner.sizes[0][0];
params.imp[0].banner.h = bid.mediaTypes.banner.sizes[0][1];
} else {
params.imp[0].banner.w = bid.sizes[0][0];
params.imp[0].banner.h = bid.sizes[0][1];
}

return {method: 'POST', url: 'https://rtb.vrtcal.com/bidder_prebid.vap?ssp=1804', data: JSON.stringify(params), options: {withCredentials: false, crossOrigin: true}}
});

return requests;
},
interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse || !serverResponse.body) {
return [];
}

const bidResponses = [];

var response = serverResponse.body;

if (response) {
const bidResponse = {
requestId: response.id,
cpm: response.seatbid[0].bid[0].price,
width: response.seatbid[0].bid[0].w,
height: response.seatbid[0].bid[0].h,
creativeId: response.seatbid[0].bid[0].crid,
currency: 'USD',
netRevenue: true,
ttl: 900,
ad: response.seatbid[0].bid[0].adm,
nurl: response.seatbid[0].bid[0].nurl
};

if (response.seatbid[0].bid[0].adomain && response.seatbid[0].bid[0].adomain.length) {
bidResponse.meta = {
advertiserDomains: response.seatbid[0].bid[0].adomain
};
}

bidResponses.push(bidResponse);
}
return bidResponses;
},
onBidWon: function(bid) {
if (!bid.nurl) { return false; }
const winUrl = bid.nurl.replace(
/\$\{AUCTION_PRICE\}/,
bid.cpm
);
ajax(winUrl, null);
return true;
}
};

registerBidder(spec);
81 changes: 81 additions & 0 deletions test/spec/modules/vrtcalBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { expect } from 'chai'
import { spec } from 'modules/vrtcalBidAdapter'
import { newBidder } from 'src/adapters/bidderFactory'

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

let bidRequest = {
bidId: 'bidID0001',
transactionId: 'transID0001',
sizes: [[ 300, 250 ]]
}

describe('isBidRequestValid', function () {
it('should return true 100% of time as no special additional params are required, thus no additional validation needed', function () {
expect(spec.isBidRequestValid(bidRequest)).to.be.true
})
})

describe('buildRequests', function () {
let bidRequests = [
{
'bidder': 'vrtcal',
'adUnitCode': 'adunit0001',
'sizes': [[300, 250]],
'bidId': 'bidID0001',
'bidderRequestId': 'br0001',
'auctionId': 'auction0001',
}
];

const request = spec.buildRequests(bidRequests);

it('sends bid request to our endpoint via POST', function () {
expect(request[0].method).to.equal('POST');
});

it('adUnitCode should be sent as prebidAdUnitCode parameters on any requests', function () {
expect(request[0].data).to.match(/"prebidAdUnitCode":"adunit0001"/);
});
});

describe('interpretResponse', function () {
it('should form compliant bid object response', function () {
let res = {
body: {
id: 'bidID0001',
seatbid: [{
bid: [{
id: 'VRTB_240d3c8a3c12b68_1',
impid: '1',
price: 0.7554,
adm: 'TEST AD',
nurl: 'https://adplatform.vrtcal.com/wintracker',
w: 300,
h: 250,
crid: 'v2_1064_vrt_vrtcaltestdisplay2_300_250',
adomain: ['vrtcal.com']
}],
seat: '16'
}],
cur: 'USD'
}
}

let ir = spec.interpretResponse(res, bidRequest)

expect(ir.length).to.equal(1)

let en = ir[0]

expect(en.requestId != null &&
en.cpm != null && typeof en.cpm === 'number' &&
en.width != null && typeof en.width === 'number' &&
en.height != null && typeof en.height === 'number' &&
en.ad != null &&
en.creativeId != null
).to.be.true
})
})
})