-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'prebid:master' into adverxo_adapter
- Loading branch information
Showing
62 changed files
with
2,843 additions
and
773 deletions.
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
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,70 @@ | ||
/** | ||
* Helper function to build request payload for banner ads. | ||
* @param {Object} bidRequest - The bid request object. | ||
* @param {string} endpointUrl - The endpoint URL specific to the bidder. | ||
* @returns {Array} An array of server requests. | ||
*/ | ||
export function buildBannerRequests(bidRequest, endpointUrl) { | ||
const serverRequests = []; | ||
const sizes = bidRequest.mediaTypes.banner.sizes; | ||
|
||
sizes.forEach(([width, height]) => { | ||
bidRequest.params.requestedSizes = [width, height]; | ||
|
||
const payload = { | ||
ctype: 'div', | ||
pzoneid: bidRequest.params.zoneId, | ||
width, | ||
height, | ||
}; | ||
|
||
const payloadString = Object.keys(payload) | ||
.map((key) => `${key}=${encodeURIComponent(payload[key])}`) | ||
.join('&'); | ||
|
||
serverRequests.push({ | ||
method: 'GET', | ||
url: endpointUrl, | ||
data: payloadString, | ||
bidderRequest: bidRequest, | ||
}); | ||
}); | ||
|
||
return serverRequests; | ||
} | ||
|
||
/** | ||
* Helper function to interpret server response for banner ads. | ||
* @param {Object} serverResponse - The server response object. | ||
* @param {Object} bidderRequest - The matched bid request for this response. | ||
* @returns {Array} An array of bid responses. | ||
*/ | ||
export function interpretBannerResponse(serverResponse, bidderRequest) { | ||
const response = serverResponse.body; | ||
const bidResponses = []; | ||
|
||
if (response && response.template && response.template.html) { | ||
const { bidId } = bidderRequest; | ||
const [width, height] = bidderRequest.params.requestedSizes; | ||
|
||
const bidResponse = { | ||
requestId: bidId, | ||
cpm: response.hb.cpm, | ||
creativeId: response.banner.hash, | ||
currency: 'USD', | ||
netRevenue: response.hb.netRevenue, | ||
ttl: 600, | ||
ad: response.template.html, | ||
mediaType: 'banner', | ||
meta: { | ||
advertiserDomains: response.hb.adomains || [], | ||
}, | ||
width, | ||
height, | ||
}; | ||
|
||
bidResponses.push(bidResponse); | ||
} | ||
|
||
return bidResponses; | ||
} |
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,30 @@ | ||
import { VIDEO } from '../../src/mediaTypes.js'; | ||
import { deepAccess, isFn } from '../../src/utils.js'; | ||
|
||
const DEFAULT_FLOOR = 0.0; | ||
|
||
/** | ||
* Get floors from Prebid Price Floors module | ||
* | ||
* @param {object} bid Bid request object | ||
* @param {string} currency Ad server currency | ||
* @param {string} mediaType Bid media type | ||
* @return {number} Floor price | ||
*/ | ||
export function getBidFloor (bid, currency, mediaType) { | ||
const floors = []; | ||
|
||
if (isFn(bid.getFloor)) { | ||
(deepAccess(bid, `mediaTypes.${mediaType}.${mediaType === VIDEO ? 'playerSize' : 'sizes'}`) || []).forEach(size => { | ||
const floor = bid.getFloor({ | ||
currency: currency || 'USD', | ||
mediaType, | ||
size | ||
}).floor; | ||
|
||
floors.push(!isNaN(floor) ? floor : DEFAULT_FLOOR); | ||
}); | ||
} | ||
|
||
return floors.length ? Math.min(...floors) : DEFAULT_FLOOR; | ||
} |
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
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
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
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
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
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
Oops, something went wrong.