-
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
Update adapter to prebid v1.0 #1908
Changes from 1 commit
a6762af
2e86861
35b3ec6
aea62dc
33aad90
fea1e24
55056e7
cd90cc8
9e3a814
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,60 +1,93 @@ | ||
var utils = require('src/utils.js'); | ||
var bidfactory = require('src/bidfactory.js'); | ||
var bidmanager = require('src/bidmanager.js'); | ||
var adloader = require('src/adloader.js'); | ||
var url = require('src/url.js'); | ||
var adaptermanager = require('src/adaptermanager'); | ||
import * as utils from 'src/utils'; | ||
import { | ||
config | ||
} from 'src/config'; | ||
import { | ||
registerBidder | ||
} from 'src/adapters/bidderFactory'; | ||
const BIDDER_CODE = 'smartadserver'; | ||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['smart'], // short 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 && bid.params.siteId && bid.params.pageId && bid.params.formatId && bid.params.domain); | ||
}, | ||
/** | ||
* 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) { | ||
// use bidderRequest.bids[] to get bidder-dependent request info | ||
|
||
var SmartAdServer = function SmartAdServer() { | ||
var generateCallback = function(bid) { | ||
var callbackId = 'sas_' + utils.getUniqueIdentifierStr(); | ||
$$PREBID_GLOBAL$$[callbackId] = function(adUnit) { | ||
var bidObject; | ||
if (adUnit) { | ||
utils.logMessage(`[SmartAdServer] bid response for placementCode ${bid.placementCode}`); | ||
bidObject = bidfactory.createBid(1); | ||
bidObject.bidderCode = 'smartadserver'; | ||
bidObject.cpm = adUnit.cpm; | ||
bidObject.currency = adUnit.currency; | ||
bidObject.ad = adUnit.ad; | ||
bidObject.width = adUnit.width; | ||
bidObject.height = adUnit.height; | ||
bidObject.dealId = adUnit.dealId; | ||
bidmanager.addBidResponse(bid.placementCode, bidObject); | ||
} else { | ||
utils.logMessage(`[SmartAdServer] no bid response for placementCode ${bid.placementCode}`); | ||
bidObject = bidfactory.createBid(2); | ||
bidObject.bidderCode = 'smartadserver'; | ||
bidmanager.addBidResponse(bid.placementCode, bidObject); | ||
} | ||
}; | ||
return callbackId; | ||
}; | ||
// if your bidder supports multiple currencies, use config.getConfig(currency) | ||
// to find which one the ad server needs | ||
|
||
return { | ||
callBids: function(params) { | ||
for (var i = 0; i < params.bids.length; i++) { | ||
var bid = params.bids[i]; | ||
var adCall = url.parse(bid.params.domain); | ||
adCall.pathname = '/prebid'; | ||
adCall.search = { | ||
'pbjscbk': '$$PREBID_GLOBAL$$.' + generateCallback(bid), | ||
'siteid': bid.params.siteId, | ||
'pgid': bid.params.pageId, | ||
'fmtid': bid.params.formatId, | ||
'ccy': bid.params.currency || 'USD', | ||
'bidfloor': bid.params.bidfloor || 0.0, | ||
'tgt': encodeURIComponent(bid.params.target || ''), | ||
'tag': bid.placementCode, | ||
'sizes': bid.sizes.map(size => size[0] + 'x' + size[1]).join(','), | ||
'async': 1 | ||
}; | ||
adloader.loadScript(url.format(adCall)); | ||
} | ||
// pull requested transaction ID from bidderRequest.bids[].transactionId | ||
if (!Array.isArray(validBidRequests)) { | ||
validBidRequests = [validBidRequests]; | ||
} | ||
}; | ||
}; | ||
|
||
adaptermanager.registerBidAdapter(new SmartAdServer(), 'smartadserver'); | ||
|
||
module.exports = SmartAdServer; | ||
var bid = validBidRequests[0]; | ||
const payload = { | ||
siteid: bid.params.siteId, | ||
pageid: bid.params.pageId, | ||
formatid: bid.params.formatId, | ||
currencyCode: config.getConfig('currency'), | ||
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.
|
||
bidfloor: bid.params.bidfloor || 0.0, | ||
targeting: bid.params.target && bid.params.target != '' ? bid.params.target : undefined, | ||
tagId: bid.adUnitCode, | ||
sizes: bid.sizes.map(size => ({ | ||
w: size[0], | ||
h: size[1] | ||
})), | ||
pageDomain: utils.getTopWindowUrl(), | ||
transactionId: bid.transactionId, | ||
timeout: config.getConfig('bidderTimeout') | ||
}; | ||
const payloadString = JSON.stringify(payload); | ||
return { | ||
method: 'POST', | ||
url: bid.params.domain + '/prebid/v1', | ||
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 = []; | ||
if (serverResponse) { | ||
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.
|
||
const bidResponse = { | ||
requestId: bidRequest.bidId, | ||
bidderCode: spec.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.
|
||
cpm: serverResponse.cpm, | ||
width: serverResponse.width, | ||
height: serverResponse.height, | ||
creativeId: serverResponse.creativeId, | ||
dealId: serverResponse.dealId, | ||
currency: serverResponse.currency, | ||
netRevenue: serverResponse.isNetCpm, | ||
ttl: serverResponse.ttl, | ||
referrer: utils.getTopWindowUrl(), | ||
ad: serverResponse.ad | ||
}; | ||
bidResponses.push(bidResponse); | ||
} | ||
return bidResponses; | ||
}, | ||
getUserSyncs: function (syncOptions) { | ||
// iframe || image | ||
return undefined; | ||
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 you're not using userSyncs, just don't include this function definition rather than returning |
||
} | ||
} | ||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Smart Ad Server Bidder Adapter | ||
Module Type: Bidder Adapter | ||
``` | ||
|
||
# Description | ||
|
||
Connect to Smart for bids. | ||
|
||
The Smart adapter requires setup and approval from the Smart team. | ||
Please reach out to your Technical account manager for more information. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
sizes: [[300, 250]], // a display size | ||
bids: [ | ||
{ | ||
bidder: "smart", | ||
params: { | ||
domain: 'http://prg.smartadserver.com', | ||
siteId: 32216, | ||
pageId: 881291, | ||
formatId: 13695, | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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.
This will always be an array, so this is unnecessary