forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
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 master
- Loading branch information
Showing
22 changed files
with
1,253 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,16 @@ | ||
<!-- This script tag should be returned by your ad server --> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js"></script> | ||
<script> | ||
// This is the `renderAd` function from Prebid.js moved within the creative iframe | ||
var renderAd = function (ev) { | ||
var key = ev.message ? "message" : "data"; | ||
var data = {}; | ||
try { | ||
data = JSON.parse(ev[key]); | ||
} catch (e) { | ||
// Do nothing. No ad found. | ||
} | ||
if (data.ad || data.adUrl) { | ||
if (data.ad) { | ||
document.write(data.ad); | ||
document.close(); | ||
} else if (data.adUrl) { | ||
document.write('<IFRAME SRC="' + data.adUrl + '" WIDTH="'+ data.width +'" HEIGHT="'+ data.height +'" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true"></IFRAME>'); | ||
document.close(); | ||
} | ||
} | ||
}; | ||
var ucTagData = {}; | ||
ucTagData.adServerDomain = ""; | ||
ucTagData.pubUrl = "%%PATTERN:url%%"; | ||
ucTagData.targetingMap = "%%PATTERN:TARGETINGMAP%%"; | ||
ucTagData.hbPb = "%%PATTERN:hb_pb%%"; | ||
|
||
var requestAdFromPrebid = function () { | ||
var message = JSON.stringify({ | ||
message: 'Prebid creative requested: %%PATTERN:hb_adid%%', | ||
adId: '%%PATTERN:hb_adid%%' | ||
}); | ||
window.parent.postMessage(message, '*'); | ||
}; | ||
|
||
var listenAdFromPrebid = function () { | ||
window.addEventListener("message", renderAd, false); | ||
}; | ||
|
||
listenAdFromPrebid(); | ||
requestAdFromPrebid(); | ||
try { | ||
ucTag.renderAd(document, ucTagData); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
</script> |
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
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,147 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
const BIDDER_CODE = 'pilotx'; | ||
const ENDPOINT_URL = '//adn.pilotx.tv/hb' | ||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: ['banner', 'video'], | ||
aliases: ['pilotx'], // 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) { | ||
let sizesCheck = !!bid.sizes | ||
let paramSizesCheck = !!bid.params.sizes | ||
var sizeConfirmed = false | ||
if (sizesCheck) { | ||
if (bid.sizes.length < 1) { | ||
return false | ||
} else { | ||
sizeConfirmed = true | ||
} | ||
} | ||
if (paramSizesCheck) { | ||
if (bid.params.sizes.length < 1 && !sizeConfirmed) { | ||
return false | ||
} else { | ||
sizeConfirmed = true | ||
} | ||
} | ||
if (!sizeConfirmed) { | ||
return false | ||
} | ||
return !!(bid.params.placementId); | ||
}, | ||
/** | ||
* 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, bidderRequest) { | ||
let payloadItems = {}; | ||
validBidRequests.forEach(bidRequest => { | ||
let sizes = []; | ||
let placementId = this.setPlacementID(bidRequest.params.placementId) | ||
payloadItems[placementId] = {} | ||
if (bidRequest.sizes.length > 0) { | ||
if (Array.isArray(bidRequest.sizes[0])) { | ||
for (let i = 0; i < bidRequest.sizes.length; i++) { | ||
sizes[i] = [(bidRequest.sizes[i])[0], (bidRequest.sizes[i])[1]] | ||
} | ||
} else { | ||
sizes[0] = [bidRequest.sizes[0], bidRequest.sizes[1]] | ||
} | ||
payloadItems[placementId]['sizes'] = sizes | ||
} | ||
if (bidRequest.mediaTypes != null) { | ||
for (let i in bidRequest.mediaTypes) { | ||
payloadItems[placementId][i] = { | ||
...bidRequest.mediaTypes[i] | ||
} | ||
} | ||
} | ||
let consentTemp = '' | ||
let consentRequiredTemp = false | ||
if (bidderRequest && bidderRequest.gdprConsent) { | ||
consentTemp = bidderRequest.gdprConsent.consentString | ||
// will check if the gdprApplies field was populated with a boolean value (ie from page config). If it's undefined, then default to true | ||
consentRequiredTemp = (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true | ||
} | ||
|
||
payloadItems[placementId]['gdprConsentString'] = consentTemp | ||
payloadItems[placementId]['gdprConsentRequired'] = consentRequiredTemp | ||
payloadItems[placementId]['bidId'] = bidRequest.bidId | ||
}); | ||
const payload = payloadItems; | ||
const payloadString = JSON.stringify(payload); | ||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: payloadString, | ||
}; | ||
}, | ||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
const serverBody = serverResponse.body; | ||
const bidResponses = []; | ||
if (serverBody.mediaType == 'banner') { | ||
const bidResponse = { | ||
requestId: serverBody.requestId, | ||
cpm: serverBody.cpm, | ||
width: serverBody.width, | ||
height: serverBody.height, | ||
creativeId: serverBody.creativeId, | ||
currency: serverBody.currency, | ||
netRevenue: false, | ||
ttl: serverBody.ttl, | ||
ad: serverBody.ad, | ||
mediaType: 'banner', | ||
meta: { | ||
mediaType: 'banner', | ||
advertiserDomains: serverBody.advertiserDomains | ||
} | ||
} | ||
bidResponses.push(bidResponse) | ||
} else if (serverBody.mediaType == 'video') { | ||
const bidResponse = { | ||
requestId: serverBody.requestId, | ||
cpm: serverBody.cpm, | ||
width: serverBody.width, | ||
height: serverBody.height, | ||
creativeId: serverBody.creativeId, | ||
currency: serverBody.currency, | ||
netRevenue: false, | ||
ttl: serverBody.ttl, | ||
vastUrl: serverBody.vastUrl, | ||
mediaType: 'video', | ||
meta: { | ||
mediaType: 'video', | ||
advertiserDomains: serverBody.advertiserDomains | ||
} | ||
} | ||
bidResponses.push(bidResponse) | ||
} | ||
|
||
return bidResponses; | ||
}, | ||
|
||
/** | ||
* Formats placement ids for adserver ingestion purposes | ||
* @param {string[]} The placement ID/s in an array | ||
*/ | ||
setPlacementID: function (placementId) { | ||
if (Array.isArray(placementId)) { | ||
return placementId.join('#') | ||
} | ||
return placementId | ||
}, | ||
} | ||
registerBidder(spec); |
Oops, something went wrong.