Skip to content

Commit

Permalink
Add AdkernelAdn adapter (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckbo3hrk authored and matthewlane committed Nov 7, 2017
1 parent 6107cc8 commit a2b5cfa
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 0 deletions.
7 changes: 7 additions & 0 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@
params: {
placement_id: 0
}
},
{
bidder: 'adkernelAdn',
params: {
pubId: 50357, //REQUIRED
host: 'dsp-staging.adkernel.com' //OPTIONAL
}
}
]
}, {
Expand Down
145 changes: 145 additions & 0 deletions modules/adkernelAdnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';

const DEFAULT_ADKERNEL_DSP_DOMAIN = 'tag.adkernel.com';
const VIDEO_TARGETING = ['mimes', 'protocols', 'api'];
const DEFAULT_MIMES = ['video/mp4', 'video/webm', 'application/x-shockwave-flash', 'application/javascript'];
const DEFAULT_PROTOCOLS = [2, 3, 5, 6];
const DEFAULT_APIS = [1, 2];

function isRtbDebugEnabled() {
return utils.getTopWindowLocation().href.indexOf('adk_debug=true') !== -1;
}

function buildImp(bidRequest) {
const sizes = bidRequest.sizes;
let imp = {
id: bidRequest.bidId,
tagid: bidRequest.placementCode
};
if (bidRequest.mediaType === 'video' || utils.deepAccess(bidRequest, 'mediaTypes.video')) {
imp.video = {
w: sizes[0],
h: sizes[1],
mimes: DEFAULT_MIMES,
protocols: DEFAULT_PROTOCOLS,
api: DEFAULT_APIS
};
if (bidRequest.params.video) {
Object.keys(bidRequest.params.video)
.filter(param => VIDEO_TARGETING.includes(param))
.forEach(param => imp.video[param] = bidRequest.params.video[param]);
}
} else {
imp.banner = {
format: utils.parseSizesInput(bidRequest.sizes)
};
}
return imp;
}

function buildRequestParams(auctionId, transactionId, tags) {
let loc = utils.getTopWindowLocation();
return {
id: auctionId,
tid: transactionId,
site: {
page: loc.href,
ref: utils.getTopWindowReferrer(),
secure: ~~(loc.protocol === 'https:')
},
imp: tags
};
}

function buildBid(tag) {
let bid = {
requestId: tag.impid,
bidderCode: spec.code,
cpm: tag.bid,
width: tag.w,
height: tag.h,
creativeId: tag.crid,
currency: 'USD',
ttl: 720,
netRevenue: true
};
if (tag.tag) {
bid.ad = `<!DOCTYPE html><html><head><title></title><body style='margin:0px;padding:0px;'>${tag.tag}</body></head>`;
bid.mediaType = BANNER;
} else if (tag.vast_url) {
bid.vastUrl = tag.vast_url;
bid.mediaType = VIDEO;
}
return bid;
}

export const spec = {

code: 'adkernelAdn',

supportedMediaTypes: [VIDEO],

isBidRequestValid: function(bidRequest) {
return 'params' in bidRequest && (typeof bidRequest.params.host === 'undefined' || typeof bidRequest.params.host === 'string') &&
typeof bidRequest.params.pubId === 'number';
},

buildRequests: function(bidRequests) {
let transactionId;
let auctionId;
let dispatch = bidRequests.map(buildImp)
.reduce((acc, curr, index) => {
let bidRequest = bidRequests[index];
let pubId = bidRequest.params.pubId;
let host = bidRequest.params.host || DEFAULT_ADKERNEL_DSP_DOMAIN;
acc[host] = acc[host] || {};
acc[host][pubId] = acc[host][pubId] || [];
acc[host][pubId].push(curr);
transactionId = bidRequest.transactionId;
auctionId = bidRequest.bidderRequestId;
return acc;
}, {});
let requests = [];
Object.keys(dispatch).forEach(host => {
Object.keys(dispatch[host]).forEach(pubId => {
let request = buildRequestParams(auctionId, transactionId, dispatch[host][pubId]);
requests.push({
method: 'POST',
url: `//${host}/tag?account=${pubId}&pb=1${isRtbDebugEnabled() ? '&debug=1' : ''}`,
data: JSON.stringify(request)
})
});
});
return requests;
},

interpretResponse: function(serverResponse) {
let response = serverResponse.body;
if (!response.tags) {
return [];
}
if (response.debug) {
utils.logInfo(`ADKERNEL DEBUG:\n${response.debug}`);
}
return response.tags.map(buildBid);
},

getUserSyncs: function(syncOptions, serverResponses) {
if (!syncOptions.iframeEnabled || !serverResponses || serverResponses.length === 0) {
return [];
}
return serverResponses.filter(rps => 'syncpages' in rps.body)
.map(rsp => rsp.body.syncpages)
.reduce((a, b) => a.concat(b), [])
.map(sync_url => {
return {
type: 'iframe',
url: sync_url
}
});
}
};

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

```
Module Name: AdKernel ADN Bidder Adapter
Module Type: Bidder Adapter
Maintainer: denis@adkernel.com
```

# Description

Connects to AdKernel Ad Delivery Network
Banner and video formats are supported.


# Test Parameters
```
var adUnits = [
{
code: 'banner-ad-div',
sizes: [[300, 250], [300, 200]],
bids: [
{
bidder: 'adkernelAdn',
params: {
pubId: 50357,
host: 'dsp-staging.adkernel.com'
}
}
]
}, {
code: 'video-ad-player',
sizes: [640, 480],
bids: [
{
bidder: 'adkernelAdn',
mediaType : 'video',
params: {
pubId: 50357,
host: 'dsp-staging.adkernel.com'
}
}
]
}
];
```
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ exports.getTopWindowUrl = function () {
return href;
};

exports.getTopWindowReferrer = function() {
try {
return window.top.document.referrer;
} catch (e) {
return document.referrer;
}
};

exports.logWarn = function (msg) {
if (debugTurnedOn() && console.warn) {
console.warn('WARNING: ' + msg);
Expand Down
Loading

0 comments on commit a2b5cfa

Please sign in to comment.