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

districtmDMX new adapter #2765

Merged
merged 12 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 10 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
158 changes: 158 additions & 0 deletions modules/districtmDmxAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import {config} from 'src/config';

const BIDDER_CODE = 'districtmDMX';

const DMXURI = 'https://dmx.districtm.io/b/v1';

export class DistrictmDmxAdapter {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pattern described here http://prebid.org/dev-docs/bidder-adaptor.html
Prebid is not using class as of now. This will transpile fine and i think will also work in all browsers.

constructor() {
this.code = BIDDER_CODE;
this.supportedFormat = ['banner'];
}
isBidRequestValid(bid) {
return !!(bid.params.dmxid && bid.params.memberid);
}
interpretResponse(response, bidRequest) {
response = response.body || {};
if (response.seatbid) {
if (Array.isArray(response.seatbid)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use utils.isArray method

const {seatbid} = response;
let winners = seatbid.reduce((bid, ads) => {
let ad = ads.bid.reduce(function(oBid, nBid) {
if (oBid.price < nBid.price) {
const bid = matchRequest(nBid.impid, bidRequest);
const {width, height} = defaultSize(bid);
nBid.cpm = nBid.price;
nBid.bidId = nBid.impid;
nBid.requestId = nBid.impid;
nBid.width = nBid.w || width;
nBid.height = nBid.h || height;
nBid.ad = nBid.adm;
nBid.netRevenue = true;
nBid.creativeId = nBid.crid;
nBid.currency = 'USD';
nBid.ttl = 60;

return nBid;
} else {
oBid.cpm = oBid.price;
return oBid;
}
}, {price: 0});
if (ad.adm) {
bid.push(ad)
}
return bid;
}, [])
let winnersClean = winners.filter(w => {
if (w.bidId) {
return true;
}
return false;
});
return winnersClean;
} else {
return [];
}
} else {
return [];
}
}
buildRequests(bidRequest, bidderRequest) {
let timeout = config.getConfig('bidderTimeout');
let dmxRequest = {
id: utils.generateUUID(),
cur: ['USD'],
tmax: (timeout - 300),
test: this.test() || 0,
site: {
publisher: { id: String(bidRequest[0].params.memberid) || null }
}
}
if (!dmxRequest.test) {
delete dmxRequest.test;
}
if (bidderRequest.gdprConsent) {
dmxRequest.regs = {};
dmxRequest.regs.ext = {};
dmxRequest.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies === true ? 1 : 0;
if (dmxRequest.regs.ext.gdpr) {
dmxRequest.regs.ext.consent = bidderRequest.gdprConsent.consentString;
}
}
let tosendtags = bidRequest.map(dmx => {
var obj = {};
obj.id = dmx.bidId;
obj.tagid = String(dmx.params.dmxid);
obj.secure = window.location.protocol === 'https:' ? 1 : 0;
obj.banner = {
topframe: 1,
w: dmx.sizes[0][0] || 0,
h: dmx.sizes[0][1] || 0,
format: dmx.sizes.map(s => {
return {w: s[0], h: s[1]};
})
};
return obj;
});
dmxRequest.imp = tosendtags;
return {
method: 'POST',
url: DMXURI,
data: JSON.stringify(dmxRequest),
options: {
contentType: 'application/json',
withCredentials: true
},
bidderRequest
}
}
test() {
return window.location.href.indexOf('dmTest=true') !== -1 ? 1 : 0;
}

getUserSyncs(optionsType) {
if (optionsType.iframeEnabled) {
return [{
type: 'iframe',
url: 'https://cdn.districtm.io/ids/index.html'
}];
}
}
}

/**
* Function matchRequest(id: string, BidRequest: object)
* @param id
* @type string
* @param bidRequest
* @type Object
* @returns Object
*
*/
export function matchRequest(id, bidRequest) {
const {bids} = bidRequest.bidderRequest;
const [returnValue] = bids.filter(bid => bid.bidId === id);
return returnValue;
}
export function checkDeepArray(Arr) {
if (Array.isArray(Arr)) {
if (Array.isArray(Arr[0])) {
return Arr[0];
} else {
return Arr;
}
} else {
return Arr;
}
}
export function defaultSize(thebidObj) {
const {sizes} = thebidObj;
const returnObject = {};
returnObject.width = checkDeepArray(sizes)[0];
returnObject.height = checkDeepArray(sizes)[1];
return returnObject;
}
registerBidder(new DistrictmDmxAdapter());
31 changes: 31 additions & 0 deletions modules/districtmDmxAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Overview

```
Module Name: DistrictM Bid Adapter
Module Type: Bidder Adapter
Maintainer: steve@districtm.net
```

# Description

Adapter that connects to DistrictM's demand sources.
This version only support banner

# Test Parameters
```
var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300,600]],
}
},
bids: [{
bidder: 'districtmDMX',
params: {
dmxid: 100001,
memberid: 100003
}
}]
}];
```
Loading