-
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
Underdog Media 1.0 Compliance #1801
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -1,112 +1,117 @@ | ||
import * as utils from 'src/utils'; | ||
import { config } from 'src/config'; | ||
var bidfactory = require('src/bidfactory.js'); | ||
var bidmanager = require('src/bidmanager.js'); | ||
var adloader = require('src/adloader.js'); | ||
var utils = require('src/utils.js'); | ||
var adaptermanager = require('src/adaptermanager'); | ||
|
||
function UnderdogMediaAdapter() { | ||
const UDM_ADAPTER_VERSION = '1.0.0'; | ||
var getJsStaticUrl = window.location.protocol + '//udmserve.net/udm/img.fetch?tid=1;dt=9;callback=$$PREBID_GLOBAL$$.handleUnderdogMediaCB;'; | ||
var bidParams = {}; | ||
|
||
function _callBids(params) { | ||
bidParams = params; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
const BIDDER_CODE = 'underdogmedia'; | ||
const UDM_ADAPTER_VERSION = '1.0'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
bidParams: [], | ||
|
||
isBidRequestValid: function (bid) { | ||
return !!((bid.params && bid.params.siteId) && (bid.sizes && bid.sizes.length > 0)); | ||
}, | ||
|
||
buildRequests: function (validBidRequests) { | ||
var sizes = []; | ||
var siteId = 0; | ||
|
||
bidParams.bids.forEach(bidParam => { | ||
validBidRequests.forEach(bidParam => { | ||
sizes = utils.flatten(sizes, utils.parseSizesInput(bidParam.sizes)); | ||
siteId = bidParam.params.siteId; | ||
}); | ||
adloader.loadScript(getJsStaticUrl + 'sid=' + siteId + ';sizes=' + sizes.join(','), null, false); | ||
} | ||
|
||
function _callback(response) { | ||
var mids = response.mids; | ||
bidParams.bids.forEach(bidParam => { | ||
var filled = false; | ||
mids.forEach(mid => { | ||
return { | ||
method: 'GET', | ||
url: `${window.location.protocol}//udmserve.net/udm/img.fetch`, | ||
data: `tid=1;dt=10;sid=${siteId};sizes=${sizes.join(',')}`, | ||
bidParams: validBidRequests | ||
}; | ||
}, | ||
|
||
interpretResponse: function (serverResponse, bidRequest) { | ||
const bidResponses = []; | ||
bidRequest.bidParams.forEach(bidParam => { | ||
serverResponse.body.mids.forEach(mid => { | ||
if (mid.useCount > 0) { | ||
return; | ||
} | ||
|
||
if (!mid.useCount) { | ||
mid.useCount = 0; | ||
} | ||
|
||
var size_not_found = true; | ||
utils.parseSizesInput(bidParam.sizes).forEach(size => { | ||
if (size === mid.width + 'x' + mid.height) { | ||
size_not_found = false; | ||
} | ||
}); | ||
|
||
if (size_not_found) { | ||
return; | ||
} | ||
|
||
var bid = bidfactory.createBid(1, bidParam); | ||
bid.bidderCode = bidParam.bidder; | ||
bid.width = mid.width; | ||
bid.height = mid.height; | ||
const bidResponse = { | ||
requestId: bidParam.bidId, | ||
bidderCode: spec.code, | ||
cpm: parseFloat(mid.cpm), | ||
width: mid.width, | ||
height: mid.height, | ||
ad: mid.ad_code_html, | ||
creativeId: mid.mid, | ||
currency: 'USD', | ||
netRevenue: false, | ||
ttl: config.getConfig('_bidderTimeout'), | ||
}; | ||
|
||
bid.cpm = parseFloat(mid.cpm); | ||
if (bid.cpm <= 0) { | ||
if (bidResponse.cpm <= 0) { | ||
return; | ||
} | ||
mid.useCount++; | ||
bid.ad = mid.ad_code_html; | ||
bid.ad = _makeNotification(bid, mid, bidParam) + bid.ad; | ||
if (!(bid.ad || bid.adUrl)) { | ||
if (bidResponse.ad.length <= 0) { | ||
return; | ||
} | ||
bidmanager.addBidResponse(bidParam.placementCode, bid); | ||
filled = true; | ||
|
||
mid.useCount++; | ||
|
||
bidResponse.ad += makeNotification(bidResponse, mid, bidParam); | ||
|
||
bidResponses.push(bidResponse); | ||
}); | ||
if (!filled) { | ||
var nobid = bidfactory.createBid(2, bidParam); | ||
nobid.bidderCode = bidParam.bidder; | ||
bidmanager.addBidResponse(bidParam.placementCode, nobid); | ||
} | ||
}); | ||
} | ||
|
||
$$PREBID_GLOBAL$$.handleUnderdogMediaCB = _callback; | ||
return bidResponses; | ||
}, | ||
}; | ||
|
||
function _makeNotification(bid, mid, bidParam) { | ||
var url = mid.notification_url; | ||
function makeNotification (bid, mid, bidParam) { | ||
var url = mid.notification_url; | ||
|
||
url += UDM_ADAPTER_VERSION; | ||
url += ';cb=' + Math.random(); | ||
url += ';qqq=' + (1 / bid.cpm); | ||
url += ';hbt=' + config.getConfig('bidderTimeout'); | ||
url += ';style=adapter'; | ||
url += ';vis=' + encodeURIComponent(document.visibilityState); | ||
url += UDM_ADAPTER_VERSION; | ||
url += ';cb=' + Math.random(); | ||
url += ';qqq=' + (1 / bid.cpm); | ||
url += ';hbt=' + config.getConfig('_bidderTimeout'); | ||
url += ';style=adapter'; | ||
url += ';vis=' + encodeURIComponent(document.visibilityState); | ||
|
||
url += ';traffic_info=' + encodeURIComponent(JSON.stringify(_getUrlVars())); | ||
if (bidParam.params.subId) { | ||
url += ';subid=' + encodeURIComponent(bidParam.params.subId); | ||
} | ||
return '<script async src="' + url + '"></script>'; | ||
url += ';traffic_info=' + encodeURIComponent(JSON.stringify(getUrlVars())); | ||
if (bidParam.params.subId) { | ||
url += ';subid=' + encodeURIComponent(bidParam.params.subId); | ||
} | ||
return '<script async src="' + url + '"></script>'; | ||
} | ||
|
||
function _getUrlVars() { | ||
var vars = {}; | ||
var hash; | ||
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | ||
for (var i = 0; i < hashes.length; i++) { | ||
hash = hashes[i].split('='); | ||
if (!hash[0].match(/^utm/)) { | ||
continue; | ||
} | ||
function getUrlVars() { | ||
var vars = {}; | ||
var hash; | ||
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | ||
for (var i = 0; i < hashes.length; i++) { | ||
hash = hashes[i].split('='); | ||
if (hash[0].match(/^utm_/)) { | ||
vars[hash[0]] = hash[1].substr(0, 150); | ||
} | ||
return vars; | ||
} | ||
|
||
return { | ||
callBids: _callBids | ||
}; | ||
return vars; | ||
} | ||
|
||
adaptermanager.registerBidAdapter(new UnderdogMediaAdapter(), 'underdogmedia'); | ||
|
||
module.exports = UnderdogMediaAdapter; | ||
registerBidder(spec); |
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,27 @@ | ||
# Overview | ||
|
||
**Module Name**: Underdog Media Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: jake@underdogmedia.com | ||
|
||
# Description | ||
|
||
Module that connects to Underdog Media's servers to fetch bids. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
sizes: [[300, 250]], // a display size | ||
bids: [ | ||
{ | ||
bidder: "underdogmedia", | ||
params: { | ||
siteId: '12143' | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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.
More params can be added to request object here. So you can add
bidParams
to bidRequest and access that ininterpretResponse
method.By doing this you can remove
bidParams
line 15.