-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
districtmDMX new adapter #2765
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5711b57
adding DMX
ad33b56
Update districtm_spec.js
stevealliance fbd31ff
Update districtmDMX.js
stevealliance fe94313
updating repo fork in github
6054a04
Merge pull request #1 from prebid/master
stevealliance 0384c75
adding all districtm needed file
d2f5de2
remove legacy file
d83db11
remove typo || 0 in the test method
a7d0a85
force default to return a valid width and height
d73cac7
update unit test code for failing test
d5b2617
changed class for an object
c80b0df
remove package-lock.json
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}] | ||
}]; | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.