-
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
Vertamedia Adapter for 1.0 #1789
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
16b9617
Vertamedia prebid.js adapter initial
Gorokhov 267f04c
sync
Gorokhov 99a311f
remove https
Gorokhov f861ad2
add http
8295748
remove let
9738c9a
fix typo
ec830c3
fix spaces
ec77d6d
add descriptionUrl; remove log
d346ac8
fix getSize
9f73124
Merge branch 'master' into master
Millerrok edc9745
add usege parseSizesInput
eefc347
Merge branch 'master' of https://github.com/Vertamedia/Prebid.js
82b2830
Add support for vastTag
ec7c583
Merge branch 'master' of https://github.com/prebid/Prebid.js
afcc529
Add moulty bid request; set vastUrl for bider;
e45235f
Merge branch 'master' of https://github.com/prebid/Prebid.js
d548fb8
Merge branch 'master' of https://github.com/prebid/Prebid.js
f3e6eaa
update for vertamedia adapter to Prebid 1.0
e4c30e8
Add vertamedia md file
78b4827
Add required fields
0945af1
Remove defaults; fix md file;
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,119 +1,125 @@ | ||
import Adapter from 'src/adapter'; | ||
import bidfactory from 'src/bidfactory'; | ||
import bidmanager from 'src/bidmanager'; | ||
import * as utils from 'src/utils'; | ||
import { ajax } from 'src/ajax'; | ||
import { STATUS } from 'src/constants'; | ||
import adaptermanager from 'src/adaptermanager'; | ||
|
||
const ENDPOINT = '//rtb.vertamedia.com/hb/'; | ||
|
||
function VertamediaAdapter() { | ||
const baseAdapter = new Adapter('vertamedia'); | ||
let bidRequest; | ||
|
||
baseAdapter.callBids = function (bidRequests) { | ||
if (!bidRequests || !bidRequests.bids || bidRequests.bids.length === 0) { | ||
return; | ||
} | ||
|
||
var RTBDataParams = prepareAndSaveRTBRequestParams(bidRequests.bids[0]); | ||
|
||
if (!RTBDataParams) { | ||
return; | ||
} | ||
|
||
ajax(ENDPOINT, handleResponse, RTBDataParams, { | ||
contentType: 'text/plain', | ||
withCredentials: true, | ||
method: 'GET' | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
import {VIDEO} from 'src/mediaTypes'; | ||
|
||
const URL = '//rtb.vertamedia.com/hb/'; | ||
const BIDDER_CODE = 'vertamedia'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [VIDEO], | ||
isBidRequestValid: function (bid) { | ||
return Boolean(bid && bid.params && bid.params.aid); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests | ||
* @param bidRequests | ||
* @param bidderRequest | ||
*/ | ||
buildRequests: function (bidRequests, bidderRequest) { | ||
return bidRequests.map((bid) => { | ||
return { | ||
data: prepareRTBRequestParams(bid), | ||
contentType: 'text/plain', | ||
withCredentials: true, | ||
bidderRequest, | ||
method: 'GET', | ||
url: URL | ||
} | ||
}); | ||
}; | ||
|
||
function prepareAndSaveRTBRequestParams(bid) { | ||
if (!bid || !bid.params || !bid.params.aid || !bid.placementCode) { | ||
return; | ||
}, | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids | ||
* @param serverResponse | ||
* @param bidderRequest | ||
* @return {Bid[]} An array of bids which were nested inside the server | ||
*/ | ||
interpretResponse: function (serverResponse, {bidderRequest}) { | ||
serverResponse = serverResponse.body; | ||
const isInvalidValidResp = !serverResponse || !serverResponse.bids || !serverResponse.bids.length; | ||
let bids = []; | ||
|
||
if (isInvalidValidResp) { | ||
let extMessage = serverResponse && serverResponse.ext && serverResponse.ext.message ? `: ${serverResponse.ext.message}` : ''; | ||
let errorMessage = `in response for ${bidderRequest.bidderCode} adapter ${extMessage}`; | ||
|
||
utils.logError(errorMessage); | ||
|
||
return bids; | ||
} | ||
|
||
bidRequest = bid; | ||
|
||
let size = getSize(bid.sizes); | ||
|
||
bidRequest.width = size.width; | ||
bidRequest.height = size.height; | ||
|
||
return { | ||
aid: bid.params.aid, | ||
w: size.width, | ||
h: size.height, | ||
domain: document.location.hostname | ||
}; | ||
} | ||
|
||
function getSize(requestSizes) { | ||
const parsed = {}; | ||
const size = utils.parseSizesInput(requestSizes)[0]; | ||
|
||
if (typeof size !== 'string') { | ||
return parsed; | ||
} | ||
|
||
let parsedSize = size.toUpperCase().split('X'); | ||
|
||
return { | ||
width: parseInt(parsedSize[0], 10) || undefined, | ||
height: parseInt(parsedSize[1], 10) || undefined | ||
}; | ||
} | ||
|
||
/* Notify Prebid of bid responses so bids can get in the auction */ | ||
function handleResponse(response) { | ||
var parsed; | ||
|
||
try { | ||
parsed = JSON.parse(response); | ||
} catch (error) { | ||
utils.logError(error); | ||
} | ||
|
||
if (!parsed || parsed.error || !parsed.bids || !parsed.bids.length) { | ||
bidmanager.addBidResponse(bidRequest.placementCode, createBid(STATUS.NO_BID)); | ||
serverResponse.bids.forEach(serverBid => { | ||
if (serverBid.cpm !== 0) { | ||
const bid = createBid(serverBid, bidderRequest); | ||
bids.push(bid); | ||
} | ||
}); | ||
|
||
return; | ||
} | ||
return bids; | ||
}, | ||
}; | ||
|
||
/** | ||
* Prepare all parameters for request | ||
* @param bid {object} | ||
* @returns {object} | ||
*/ | ||
function prepareRTBRequestParams(bid) { | ||
let size = getSize(bid.sizes); | ||
|
||
return { | ||
domain: utils.getTopWindowLocation().hostname, | ||
callbackId: bid.bidId, | ||
aid: bid.params.aid, | ||
h: size.height, | ||
w: size.width | ||
}; | ||
} | ||
|
||
bidmanager.addBidResponse(bidRequest.placementCode, createBid(STATUS.GOOD, parsed.bids[0])); | ||
/** | ||
* Prepare size for request | ||
* @param requestSizes {array} | ||
* @returns {object} bid The bid to validate | ||
*/ | ||
function getSize(requestSizes) { | ||
const size = utils.parseSizesInput(requestSizes)[0]; | ||
const parsed = {}; | ||
|
||
if (typeof size !== 'string') { | ||
return parsed; | ||
} | ||
|
||
function createBid(status, tag) { | ||
var bid = bidfactory.createBid(status, tag); | ||
let parsedSize = size.toUpperCase().split('X'); | ||
|
||
bid.code = baseAdapter.getBidderCode(); | ||
bid.bidderCode = bidRequest.bidder; | ||
|
||
if (!tag || status !== STATUS.GOOD) { | ||
return bid; | ||
} | ||
|
||
bid.mediaType = 'video'; | ||
bid.cpm = tag.cpm; | ||
bid.creative_id = tag.cmpId; | ||
bid.width = bidRequest.width; | ||
bid.height = bidRequest.height; | ||
bid.descriptionUrl = tag.url; | ||
bid.vastUrl = tag.url; | ||
|
||
return bid; | ||
} | ||
|
||
return Object.assign(this, { | ||
callBids: baseAdapter.callBids, | ||
setBidderCode: baseAdapter.setBidderCode | ||
}); | ||
return { | ||
height: parseInt(parsedSize[1], 10) || undefined, | ||
width: parseInt(parsedSize[0], 10) || undefined | ||
}; | ||
} | ||
|
||
adaptermanager.registerBidAdapter(new VertamediaAdapter(), 'vertamedia', { | ||
supportedMediaTypes: ['video'] | ||
}); | ||
/** | ||
* Configure new bid by response | ||
* @param bidRequest {object} | ||
* @param bidResponse {object} | ||
* @returns {object} | ||
*/ | ||
function createBid(bidResponse, bidRequest) { | ||
return { | ||
bidderCode: bidRequest.bidderCode, | ||
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.
|
||
requestId: bidResponse.requestId, | ||
descriptionUrl: bidResponse.url, | ||
creativeId: bidResponse.cmpId, | ||
vastUrl: bidResponse.vastUrl, | ||
height: bidResponse.height, | ||
currency: bidResponse.cur, | ||
width: bidResponse.width, | ||
cpm: bidResponse.cpm, | ||
mediaType: 'video', | ||
netRevenue: true, | ||
ttl: 3600 | ||
}; | ||
} | ||
|
||
module.exports = VertamediaAdapter; | ||
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,26 @@ | ||
# Overview | ||
|
||
**Module Name**: VertaMedia Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: [email protected] | ||
|
||
# Description | ||
|
||
Get access to multiple demand partners across VertaMedia AdExchange and maximize your yield with VertaMedia header bidding adapter. | ||
|
||
VertaMedia header bidding adapter connects with VertaMedia demand sources in order to fetch bids. | ||
This adapter provides a solution for accessing Video demand | ||
|
||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
code: 'div-test-div', | ||
sizes: [[640, 480]], // ad size | ||
bids: [{ | ||
bidder: 'vertamedia', // adapter name | ||
params: { | ||
aid: 332842 | ||
} | ||
}] | ||
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.
|
||
``` |
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.
contentType
istext/plain
by default andwithCrendentials
is also set to true.Both can be removed from here.