-
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
Adding Orbitsoft adapter #1378
Merged
Merged
Adding Orbitsoft adapter #1378
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
82686c9
Adding Orbitsoft module
dmitriy-shimko-nrich d068d59
Adding Orbitsoft module (corrected)
dmitriy-shimko-nrich a24ab8a
Merge branch 'master' of https://github.com/prebid/Prebid.js
dmitriy-shimko-nrich 42f1d66
Adding Orbitsoft module (correction of remarks)
dmitriy-shimko-nrich aba01a3
Adding Orbitsoft module (correction of remarks)
dmitriy-shimko-nrich be50c55
Adding Orbitsoft module (correction to alias-able)
dmitriy-shimko-nrich 0af08c9
Adding Orbitsoft module (correction to alias-able)
dmitriy-shimko-nrich ccf57ef
Adding Orbitsoft module (correction to alias-able)
dmitriy-shimko-nrich e492c4c
Merge branch 'master' of https://github.com/prebid/Prebid.js
dmitriy-shimko-nrich 28d89b0
Adding Orbitsoft module (correction to alias-able)
dmitriy-shimko-nrich 1c873a0
Adding Orbitsoft module (correction to new constructor)
dmitriy-shimko-nrich 6337b57
Adding Orbitsoft module (delete unnecessary aliases)
dmitriy-shimko-nrich 60aa74b
Adding Orbitsoft module (delete unnecessary aliases)
dmitriy-shimko-nrich 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,228 @@ | ||
import { getBidRequest } from 'src/utils'; | ||
|
||
let CONSTANTS = require('src/constants'); | ||
let bidmanager = require('src/bidmanager'); | ||
let bidfactory = require('src/bidfactory'); | ||
let adloader = require('src/adloader'); | ||
let utils = require('src/utils'); | ||
let adaptermanager = require('src/adaptermanager'); | ||
let Adapter = require('src/adapter').default; | ||
|
||
let ORBITSOFT_BIDDERCODE = 'orbitsoft'; | ||
let styleParamsToFieldsMap = { | ||
'title.family': 'f1', // headerFont | ||
'title.size': 'fs1', // headerFontSize | ||
'title.weight': 'w1', // headerWeight | ||
'title.style': 's1', // headerStyle | ||
'title.color': 'c3', // headerColor | ||
'description.family': 'f2', // descriptionFont | ||
'description.size': 'fs2', // descriptionFontSize | ||
'description.weight': 'w2', // descriptionWeight | ||
'description.style': 's2', // descriptionStyle | ||
'description.color': 'c4', // descriptionColor | ||
'url.family': 'f3', // urlFont | ||
'url.size': 'fs3', // urlFontSize | ||
'url.weight': 'w3', // urlWeight | ||
'url.style': 's3', // urlStyle | ||
'url.color': 'c5', // urlColor | ||
'colors.background': 'c2', // borderColor | ||
'colors.border': 'c1', // borderColor | ||
'colors.link': 'c6', // lnkColor | ||
}; | ||
|
||
let OrbitsoftAdapter = function OrbitsoftAdapter() { | ||
let baseAdapter = new Adapter(ORBITSOFT_BIDDERCODE); | ||
|
||
baseAdapter.callBids = function(params) { | ||
let bids = params.bids || []; | ||
|
||
for (let i = 0; i < bids.length; i++) { | ||
let bidRequest = bids[i]; | ||
let callbackId = bidRequest.bidId; | ||
let jptCall = buildJPTCall(bidRequest, callbackId); | ||
|
||
if (jptCall) { | ||
adloader.loadScript(jptCall); | ||
} else { | ||
// indicate that there is no bid for this placement | ||
let bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); | ||
bid.bidderCode = params.bidderCode; | ||
bidmanager.addBidResponse(bidRequest.placementCode, bid); | ||
} | ||
} | ||
} | ||
|
||
function buildJPTCall(bid, callbackId) { | ||
// Determine tag params | ||
let placementId = utils.getBidIdParameter('placementId', bid.params); | ||
|
||
let referrer = utils.getBidIdParameter('ref', bid.params); | ||
let location = utils.getBidIdParameter('loc', bid.params); | ||
let jptCall = utils.getBidIdParameter('requestUrl', bid.params); | ||
if (jptCall.length === 0) { | ||
// No param requestUrl | ||
// @if NODE_ENV='debug' | ||
utils.logMessage('No param requestUrl'); | ||
// @endif | ||
return null; | ||
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 there are errors creating the bid request, you should return a NO_BID to prebid 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. Fixed (on line 47) |
||
} else { | ||
jptCall += '?'; | ||
} | ||
|
||
jptCall = utils.tryAppendQueryString(jptCall, 'callback', '$$PREBID_GLOBAL$$.handleOASCB'); | ||
jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); | ||
jptCall = utils.tryAppendQueryString(jptCall, 'scid', placementId); | ||
|
||
// Sizes takes a bit more logic | ||
let sizeQueryString; | ||
let parsedSizes = utils.parseSizesInput(bid.sizes); | ||
|
||
// Combine string into proper query string | ||
let parsedSizesLength = parsedSizes.length; | ||
if (parsedSizesLength > 0) { | ||
// First value should be "size" | ||
sizeQueryString = 'size=' + parsedSizes[0]; | ||
jptCall += sizeQueryString + '&'; | ||
} | ||
|
||
// Append custom attributes: | ||
let paramsCopy = Object.assign({}, bid.params); | ||
|
||
// Delete attributes already used | ||
delete paramsCopy.placementId; | ||
delete paramsCopy.referrer; | ||
delete paramsCopy.style; | ||
delete paramsCopy.customParams; | ||
|
||
// Get the reminder | ||
jptCall += utils.parseQueryStringParameters(paramsCopy); | ||
|
||
// Append location & referrer | ||
if (location === '') { | ||
location = utils.getTopWindowUrl(); | ||
} | ||
if (referrer === '') { | ||
referrer = window.top.document.referrer; | ||
} | ||
jptCall = utils.tryAppendQueryString(jptCall, 'loc', location); | ||
jptCall = utils.tryAppendQueryString(jptCall, 'ref', referrer); | ||
|
||
// Remove the trailing "&" | ||
jptCall = removeTrailingAmp(jptCall); | ||
|
||
// @if NODE_ENV='debug' | ||
utils.logMessage('jpt request built: ' + jptCall); | ||
// @endif | ||
|
||
// Append a timer here to track latency | ||
bid.startTime = new Date().getTime(); | ||
|
||
return jptCall; | ||
} | ||
|
||
// Remove the trailing "&" | ||
function removeTrailingAmp(url) { | ||
if (url.lastIndexOf('&') === url.length - 1) { | ||
url = url.substring(0, url.length - 1); | ||
} | ||
return url; | ||
} | ||
|
||
// Expose the callback to the global object | ||
$$PREBID_GLOBAL$$.handleOASCB = function (jptResponseObj) { | ||
let bidCode; | ||
|
||
if (jptResponseObj && jptResponseObj.callback_uid) { | ||
let responseCPM; | ||
let id = jptResponseObj.callback_uid; | ||
let placementCode = ''; | ||
let bidObj = getBidRequest(id); | ||
if (bidObj) { | ||
bidCode = bidObj.bidder; | ||
|
||
placementCode = bidObj.placementCode; | ||
|
||
// Set the status | ||
bidObj.status = CONSTANTS.STATUS.GOOD; | ||
} | ||
|
||
// @if NODE_ENV='debug' | ||
utils.logMessage('JSONP callback function called for ad ID: ' + id); | ||
// @endif | ||
|
||
let bid = []; | ||
if (jptResponseObj.cpm && jptResponseObj.cpm !== 0) { | ||
// Store bid response | ||
responseCPM = jptResponseObj.cpm; | ||
// Bid status is good (indicating 1) | ||
bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidObj); | ||
bid.bidderCode = bidCode; | ||
bid.cpm = responseCPM; | ||
bid.adUrl = jptResponseObj.content_url; | ||
bid.width = jptResponseObj.width; | ||
bid.height = jptResponseObj.height; | ||
|
||
// Styles params | ||
let styles = utils.getBidIdParameter('style', bidObj.params); | ||
let stylesParams = {}; | ||
for (let currentValue in styles) { | ||
if (styles.hasOwnProperty(currentValue)) { | ||
let currentStyle = styles[currentValue]; | ||
for (let field in currentStyle) { | ||
if (currentStyle.hasOwnProperty(field)) { | ||
let styleField = styleParamsToFieldsMap[currentValue + '.' + field]; | ||
if (styleField !== undefined) { | ||
stylesParams[styleField] = currentStyle[field]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
bid.adUrl += '&' + utils.parseQueryStringParameters(stylesParams); | ||
|
||
// Custom params | ||
let customParams = utils.getBidIdParameter('customParams', bidObj.params); | ||
let customParamsArray = {}; | ||
for (let customField in customParams) { | ||
if (customParams.hasOwnProperty(customField)) { | ||
customParamsArray['c.' + customField] = customParams[customField]; | ||
} | ||
} | ||
let customParamsLink = utils.parseQueryStringParameters(customParamsArray); | ||
if (customParamsLink) { | ||
// Don't append a "&" here, we have already done it in parseQueryStringParameters | ||
bid.adUrl += customParamsLink; | ||
} | ||
|
||
// Remove the trailing "&" | ||
bid.adUrl = removeTrailingAmp(bid.adUrl); | ||
|
||
bidmanager.addBidResponse(placementCode, bid); | ||
} else { | ||
// No response data | ||
// @if NODE_ENV='debug' | ||
utils.logMessage('No prebid response from Orbitsoft for placement code ' + placementCode); | ||
// @endif | ||
// indicate that there is no bid for this placement | ||
bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidObj); | ||
bid.bidderCode = bidCode; | ||
bidmanager.addBidResponse(placementCode, bid); | ||
} | ||
} else { | ||
// No response data | ||
// @if NODE_ENV='debug' | ||
utils.logMessage('No prebid response for placement'); | ||
// @endif | ||
} | ||
}; | ||
|
||
return Object.assign(this, { | ||
callBids: baseAdapter.callBids, | ||
setBidderCode: baseAdapter.setBidderCode, | ||
buildJPTCall: buildJPTCall | ||
}); | ||
}; | ||
|
||
adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), ORBITSOFT_BIDDERCODE); | ||
|
||
module.exports = OrbitsoftAdapter; |
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.
I see you are hitting the AppNexus endpoint. Is there a reason you cannot use an AppNexus alias instead of creating your own adapter?
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.
@mkendall07 AppNexus has built-in enpoint URL for bid requesting. Our adapter sends bid request to various endpoint URL where customers install our product. Endpoint URL is defined by the requestUrl parameter and different for diffrent customers.
We also have additional options for requesting bids and ads.