Skip to content

Commit

Permalink
adkernel adapter additional bid parameters (#2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckbo3hrk authored and jaiminpanchal27 committed Feb 6, 2018
1 parent 620ca80 commit 85e9451
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 46 deletions.
52 changes: 26 additions & 26 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import includes from 'core-js/library/fn/array/includes';
const VIDEO_TARGETING = ['mimes', 'minduration', 'maxduration', 'protocols',
'startdelay', 'linearity', 'boxingallowed', 'playbackmethod', 'delivery',
'pos', 'api', 'ext'];
const VERSION = '1.0';
const VERSION = '1.1';

/**
* Adapter for requesting bids from AdKernel white-label display platform
Expand Down Expand Up @@ -76,8 +76,8 @@ export const spec = {
};
if ('banner' in imp) {
prBid.mediaType = BANNER;
prBid.width = imp.banner.w;
prBid.height = imp.banner.h;
prBid.width = rtbBid.w;
prBid.height = rtbBid.h;
prBid.ad = formatAdMarkup(rtbBid);
}
if ('video' in imp) {
Expand All @@ -96,12 +96,7 @@ export const spec = {
return serverResponses.filter(rsp => rsp.body && rsp.body.ext && rsp.body.ext.adk_usersync)
.map(rsp => rsp.body.ext.adk_usersync)
.reduce((a, b) => a.concat(b), [])
.map(sync_url => {
return {
type: 'iframe',
url: sync_url
}
});
.map(sync_url => ({type: 'iframe', url: sync_url}));
}
};

Expand All @@ -111,56 +106,61 @@ registerBidder(spec);
* Builds parameters object for single impression
*/
function buildImp(bid) {
const size = getAdUnitSize(bid);
const sizes = bid.sizes;
const imp = {
'id': bid.bidId,
'tagid': bid.placementCode
};

if (bid.mediaType === 'video') {
imp.video = {w: size[0], h: size[1]};
imp.video = {w: sizes[0], h: sizes[1]};
if (bid.params.video) {
Object.keys(bid.params.video)
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => imp.video[param] = bid.params.video[param]);
}
} else {
imp.banner = {w: size[0], h: size[1]};
imp.banner = {
format: sizes.map(s => ({'w': s[0], 'h': s[1]})),
topframe: 0
};
}
if (utils.getTopWindowLocation().protocol === 'https:') {
imp.secure = 1;
}
return imp;
}

/**
* Return ad unit single size
* @param bid adunit size definition
* @return {*}
*/
function getAdUnitSize(bid) {
if (bid.mediaType === 'video') {
return bid.sizes;
}
return bid.sizes[0];
}

/**
* Builds complete rtb request
* @param imps collection of impressions
* @param auctionId
*/
function buildRtbRequest(imps, auctionId) {
return {
let req = {
'id': auctionId,
'imp': imps,
'site': createSite(),
'at': 1,
'device': {
'ip': 'caller',
'ua': 'caller'
'ua': 'caller',
'js': 1,
'language': getLanguage()
},
'ext': {
'adk_usersync': 1
}
};
if (utils.getDNT()) {
req.device.dnt = 1;
}
return req;
}

function getLanguage() {
const language = navigator.language ? 'language' : 'userLanguage';
return navigator[language].split('-')[0];
}

/**
Expand Down
1 change: 0 additions & 1 deletion modules/adkernelBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Maintainer: denis@adkernel.com

Connects to AdKernel whitelabel platform.
Banner and video formats are supported.
The AdKernel adapter doesn't support multiple sizes per ad-unit and will use the first one if multiple sizes are defined.


# Test Parameters
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,13 @@ export function getOrigin() {
}
}

/**
* Returns Do Not Track state
*/
export function getDNT() {
return navigator.doNotTrack === '1' || window.doNotTrack === '1' || navigator.msDoNotTrack === '1' || navigator.doNotTrack === 'yes';
}

const compareCodeAndSlot = (slot, adUnitCode) => slot.getAdUnitPath() === adUnitCode || slot.getSlotElementId() === adUnitCode;

/**
Expand Down
41 changes: 22 additions & 19 deletions test/spec/modules/adkernelBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Adkernel adapter', () => {
bidId: 'Bid_01',
params: {zoneId: 1, host: 'rtb.adkernel.com'},
placementCode: 'ad-unit-1',
sizes: [[300, 250]]
sizes: [[300, 250], [300, 200]]
}, bid2_zone2 = {
bidder: 'adkernel',
bidId: 'Bid_02',
Expand Down Expand Up @@ -63,7 +63,9 @@ describe('Adkernel adapter', () => {
crid: '100_001',
price: 3.01,
nurl: 'https://rtb.com/win?i=ZjKoPYSFI3Y_0',
adm: '<!-- admarkup here -->'
adm: '<!-- admarkup here -->',
w: 300,
h: 250
}]
}],
cur: 'USD',
Expand All @@ -78,7 +80,9 @@ describe('Adkernel adapter', () => {
impid: 'Bid_02',
crid: '100_002',
price: 1.31,
adm: '<!-- admarkup here -->'
adm: '<!-- admarkup here -->',
w: 300,
h: 250
}]
}],
cur: 'USD'
Expand Down Expand Up @@ -125,21 +129,19 @@ describe('Adkernel adapter', () => {

describe('banner request building', () => {
let bidRequest;
let mock;

before(() => {
mock = sinon.stub(utils, 'getTopWindowLocation', () => {
return {
protocol: 'https:',
hostname: 'example.com',
host: 'example.com',
pathname: '/index.html',
href: 'https://example.com/index.html'
};
});
let wmock = sinon.stub(utils, 'getTopWindowLocation', () => ({
protocol: 'https:',
hostname: 'example.com',
host: 'example.com',
pathname: '/index.html',
href: 'https://example.com/index.html'
}));
let dntmock = sinon.stub(utils, 'getDNT', () => true);
let request = spec.buildRequests([bid1_zone1])[0];
bidRequest = JSON.parse(request.data.r);
mock.restore();
wmock.restore();
dntmock.restore();
});

it('should be a first-price auction', () => {
Expand All @@ -150,9 +152,9 @@ describe('Adkernel adapter', () => {
expect(bidRequest.imp[0]).to.have.property('banner');
});

it('should have h/w', () => {
expect(bidRequest.imp[0].banner).to.have.property('w', 300);
expect(bidRequest.imp[0].banner).to.have.property('h', 250);
it('should have w/h', () => {
expect(bidRequest.imp[0].banner).to.have.property('format');
expect(bidRequest.imp[0].banner.format).to.be.eql([{w: 300, h: 250}, {w: 300, h: 200}]);
});

it('should respect secure connection', () => {
Expand All @@ -172,7 +174,8 @@ describe('Adkernel adapter', () => {
expect(bidRequest).to.have.property('device');
expect(bidRequest.device).to.have.property('ip', 'caller');
expect(bidRequest.device).to.have.property('ua', 'caller');
})
expect(bidRequest.device).to.have.property('dnt', 1);
});
});

describe('video request building', () => {
Expand Down

0 comments on commit 85e9451

Please sign in to comment.