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

InSkin Bidder Adapter #2016

Merged
merged 6 commits into from
Jan 23, 2018
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
210 changes: 210 additions & 0 deletions modules/inskinBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'inskin';

const CONFIG = {
'inskin': {
'BASE_URI': 'https://mfad.inskinad.com/api/v2'
}
};

export const spec = {
code: BIDDER_CODE,

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

/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/

buildRequests: function(validBidRequests) {
// Do we need to group by bidder? i.e. to make multiple requests for
// different endpoints.

let ret = {
method: 'POST',
url: '',
data: '',
bidRequest: []
};

if (validBidRequests.length < 1) {
return ret;
}

let ENDPOINT_URL;

const data = Object.assign({
placements: [],
time: Date.now(),
user: {},
url: utils.getTopWindowUrl(),
referrer: document.referrer,
enableBotFiltering: true,
includePricingData: true,
parallel: true
}, validBidRequests[0].params);

validBidRequests.map(bid => {
let config = CONFIG[bid.bidder];
ENDPOINT_URL = config.BASE_URI;

const placement = Object.assign({
divName: bid.bidId,
adTypes: bid.adTypes || getSize(bid.sizes),
eventIds: [40, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295]
}, bid.params);

placement.adTypes.push(5, 9, 163, 2163, 3006);

if (placement.networkId && placement.siteId) {
data.placements.push(placement);
}
});

ret.data = JSON.stringify(data);
ret.bidRequest = validBidRequests;
ret.url = ENDPOINT_URL;

return ret;
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
let bid;
let bids;
let bidId;
let bidObj;
let bidResponses = [];
let bidsMap = {};

bids = bidRequest.bidRequest;

serverResponse = (serverResponse || {}).body;
for (let i = 0; i < bids.length; i++) {
bid = {};
bidObj = bids[i];
bidId = bidObj.bidId;

bidsMap[bidId] = bidObj;

if (serverResponse) {
const decision = serverResponse.decisions && serverResponse.decisions[bidId];
const price = decision && decision.pricing && decision.pricing.clearPrice;

if (decision && price) {
bid.requestId = bidId;
bid.cpm = price;
bid.width = decision.width;
bid.height = decision.height;
bid.ad = retrieveAd(bidId, decision);
bid.currency = 'USD';
bid.creativeId = decision.adId;
bid.ttl = 360;
bid.netRevenue = true;
bid.referrer = utils.getTopWindowUrl();

bidResponses.push(bid);
}
}
}

if (bidResponses.length) {
window.addEventListener('message', function(e) {
if (!e.data || e.data.from !== 'ism-bid') {
return;
}

const decision = serverResponse.decisions && serverResponse.decisions[e.data.bidId];
if (!decision) {
return;
}

const id = 'ism_tag_' + Math.floor((Math.random() * 10e16));
window[id] = {
bidId: e.data.bidId,
serverResponse
};
const script = document.createElement('script');
script.src = 'https://cdn.inskinad.com/isfe/publishercode/' + bidsMap[e.data.bidId].params.siteId + '/default.js?autoload&id=' + id;
document.getElementsByTagName('head')[0].appendChild(script);
});
}

return bidResponses;
},

getUserSyncs: function(syncOptions) {
return [];
}
};

const sizeMap = [
null,
'120x90',
'120x90',
'468x60',
'728x90',
'300x250',
'160x600',
'120x600',
'300x100',
'180x150',
'336x280',
'240x400',
'234x60',
'88x31',
'120x60',
'120x240',
'125x125',
'220x250',
'250x250',
'250x90',
'0x0',
'200x90',
'300x50',
'320x50',
'320x480',
'185x185',
'620x45',
'300x125',
'800x250'
];

sizeMap[77] = '970x90';
sizeMap[123] = '970x250';
sizeMap[43] = '300x600';

function getSize(sizes) {
const result = [];
sizes.forEach(function(size) {
const index = sizeMap.indexOf(size[0] + 'x' + size[1]);
if (index >= 0) {
result.push(index);
}
});
return result;
}

function retrieveAd(bidId, decision) {
return "<script>window.top.postMessage({from: 'ism-bid', bidId: '" + bidId + "'}, '*');\x3c/script>" + utils.createTrackPixelHtml(decision.impressionUrl);
}

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

Module Name: InSkin Bid Adapter

Module Type: Bid Adapter

Maintainer: [email protected]

# Description

Connects to InSkin Media for receiving bids from configured demand sources.

# Test Parameters
```javascript
var adUnits = [
{
code: 'test-ad-1',
sizes: [[300, 250]],
bids: [
{
bidder: 'inskin',
params: {
networkId: '9874',
siteId: '983808'
}
}
]
}
];
```
Loading