-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Upgrade Admixer adapter for Prebid 1.0 #1755
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,76 @@ | ||
var bidfactory = require('src/bidfactory.js'); | ||
var bidmanager = require('src/bidmanager.js'); | ||
var Ajax = require('src/ajax'); | ||
var utils = require('src/utils.js'); | ||
var adaptermanager = require('src/adaptermanager'); | ||
import * as utils from 'src/utils'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
/** | ||
* Adapter for requesting bids from Admixer. | ||
* | ||
* @returns {{callBids: _callBids,responseCallback: _responseCallback}} | ||
*/ | ||
var AdmixerAdapter = function AdmixerAdapter() { | ||
var invUrl = '//inv-nets.admixer.net/prebid.aspx'; | ||
var invVastUrl = '//inv-nets.admixer.net/videoprebid.aspx'; | ||
|
||
function _callBids(data) { | ||
var bids = data.bids || []; | ||
for (var i = 0, ln = bids.length; i < ln; i++) { | ||
var bid = bids[i]; | ||
var params = { | ||
'sizes': utils.parseSizesInput(bid.sizes).join('-'), | ||
'zone': bid.params && bid.params.zone, | ||
'callback_uid': bid.placementCode | ||
}; | ||
if (params.zone) { | ||
if (bid.mediaType === 'video') { | ||
var videoParams = {}; | ||
if (typeof bid.video === 'object') { | ||
Object.assign(videoParams, bid.video); | ||
} | ||
Object.assign(videoParams, params); | ||
_requestBid(invVastUrl, params); | ||
} else { | ||
_requestBid(invUrl, params); | ||
} | ||
} else { | ||
var bidObject = bidfactory.createBid(2); | ||
bidObject.bidderCode = 'admixer'; | ||
bidmanager.addBidResponse(params.callback_uid, bidObject); | ||
const BIDDER_CODE = 'admixer'; | ||
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx'; | ||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: [], | ||
supportedMediaTypes: ['banner', 'video'], | ||
/** | ||
* 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.zone; | ||
}, | ||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {bidderRequest} - bidderRequest.bids[] is an array of AdUnits and bids | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function (bidderRequest) { | ||
const payload = { | ||
imps: [], | ||
referrer: utils.getTopWindowUrl(), | ||
}; | ||
bidderRequest.forEach((bid) => { | ||
if (bid.bidder === BIDDER_CODE) { | ||
payload.imps.push(bid); | ||
} | ||
} | ||
} | ||
|
||
function _requestBid(url, params) { | ||
Ajax.ajax(url, _responseCallback, params, {method: 'GET', withCredentials: true}); | ||
} | ||
|
||
function _responseCallback(adUnit) { | ||
}); | ||
const payloadString = JSON.stringify(payload); | ||
return { | ||
method: 'GET', | ||
url: ENDPOINT_URL, | ||
data: `data=${payloadString}`, | ||
}; | ||
}, | ||
/** | ||
* 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) { | ||
const bidResponses = []; | ||
// loop through serverResponses { | ||
try { | ||
adUnit = JSON.parse(adUnit); | ||
} catch (_error) { | ||
adUnit = {result: {cpm: 0}}; | ||
utils.logError(_error); | ||
serverResponse.forEach((bidResponse) => { | ||
const bidResp = { | ||
requestId: bidResponse.bidId, | ||
id: bidResponse.bidId, | ||
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. no need for |
||
bidderCode: BIDDER_CODE, | ||
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. This bidderCode param should be removed, it could cause issues if left in place. |
||
cpm: bidResponse.cpm, | ||
width: bidResponse.width, | ||
height: bidResponse.height, | ||
ad: bidResponse.ad, | ||
ttl: bidResponse.ttl, | ||
creativeId: bidResponse.creativeId, | ||
netRevenue: bidResponse.netRevenue, | ||
currency: bidResponse.currency, | ||
vastUrl: bidResponse.vastUrl, | ||
}; | ||
bidResponses.push(bidResp); | ||
}); | ||
} catch (e) { | ||
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. Any errors that are caught during this part should be logged. They can be passed to the utils.logError() method. |
||
} | ||
var adUnitCode = adUnit.callback_uid; | ||
var bid = adUnit.result; | ||
var bidObject; | ||
if (bid.cpm > 0) { | ||
bidObject = bidfactory.createBid(1); | ||
bidObject.bidderCode = 'admixer'; | ||
bidObject.cpm = bid.cpm; | ||
if (bid.vastUrl) { | ||
bidObject.mediaType = 'video'; | ||
bidObject.vastUrl = bid.vastUrl; | ||
bidObject.descriptionUrl = bid.vastUrl; | ||
} else { | ||
bidObject.ad = bid.ad; | ||
} | ||
bidObject.width = bid.width; | ||
bidObject.height = bid.height; | ||
} else { | ||
bidObject = bidfactory.createBid(2); | ||
bidObject.bidderCode = 'admixer'; | ||
} | ||
bidmanager.addBidResponse(adUnitCode, bidObject); | ||
return bidResponses; | ||
}, | ||
getUserSyncs: function (syncOptions) { | ||
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. If this getUserSyncs is not going to be actively used by the adapter, it does not need to be defined and can be removed. |
||
} | ||
|
||
return { | ||
callBids: _callBids, | ||
responseCallback: _responseCallback | ||
}; | ||
}; | ||
|
||
adaptermanager.registerBidAdapter(new AdmixerAdapter(), 'admixer', { | ||
supportedMediaTypes: ['video'] | ||
}); | ||
|
||
module.exports = AdmixerAdapter; | ||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Overview | ||
|
||
Module Name: Admixer Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Connects to Admixer demand source to fetch bids. | ||
Banner and Video formats are supported. | ||
Please use ```admixer``` as the bidder code. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'desktop-banner-ad-div', | ||
sizes: [[300, 250]], // a display size | ||
bids: [ | ||
{ | ||
bidder: "admixer", | ||
params: { | ||
zone: '2eb6bd58-865c-47ce-af7f-a918108c3fd2' | ||
} | ||
} | ||
] | ||
},{ | ||
code: 'mobile-banner-ad-div', | ||
sizes: [[300, 50]], // a mobile size | ||
bids: [ | ||
{ | ||
bidder: "admixer", | ||
params: { | ||
zone: '62211486-c50b-4356-9f0f-411778d31fcc' | ||
} | ||
} | ||
] | ||
},{ | ||
code: 'video-ad', | ||
sizes: [[300, 50]], | ||
mediaType: 'video', | ||
bids: [ | ||
{ | ||
bidder: "admixer", | ||
params: { | ||
zone: 'ebeb1e79-8cb4-4473-b2d0-2e24b7ff47fd' | ||
} | ||
} | ||
] | ||
}, | ||
]; | ||
``` |
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.
#1748 changed the first argument of
interpretResponse
to:so adding something like
serverResponse = serverResponse.body;
just below this line, or however you'd prefer to grab the body, and updating corresponding tests if needed should get this back to working properly