-
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.
* Added AstraOne adapter * Fixed an argument in function createRenderer * Added unit tests. Added example with GPT in the documentation. Removed bid renderer. * Fixed a small typo
- Loading branch information
1 parent
6b69fcf
commit 7777359
Showing
3 changed files
with
548 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import * as utils from '../src/utils' | ||
import { registerBidder } from '../src/adapters/bidderFactory' | ||
import { BANNER } from '../src/mediaTypes' | ||
|
||
const BIDDER_CODE = 'astraone'; | ||
const SSP_ENDPOINT = 'https://ssp.astraone.io/auction/prebid'; | ||
const TTL = 60; | ||
|
||
function buildBidRequests(validBidRequests) { | ||
return utils._map(validBidRequests, function(validBidRequest) { | ||
const params = validBidRequest.params; | ||
const bidRequest = { | ||
bidId: validBidRequest.bidId, | ||
transactionId: validBidRequest.transactionId, | ||
sizes: validBidRequest.sizes, | ||
placement: params.placement, | ||
placeId: params.placeId, | ||
imageUrl: params.imageUrl | ||
}; | ||
|
||
return bidRequest; | ||
}) | ||
} | ||
|
||
function buildBid(bidData) { | ||
const bid = { | ||
requestId: bidData.bidId, | ||
cpm: bidData.price, | ||
width: bidData.width, | ||
height: bidData.height, | ||
creativeId: bidData.content.seanceId, | ||
currency: bidData.currency, | ||
netRevenue: true, | ||
mediaType: BANNER, | ||
ttl: TTL, | ||
content: bidData.content | ||
}; | ||
|
||
bid.ad = wrapAd(bid, bidData); | ||
|
||
return bid; | ||
} | ||
|
||
function getMediaTypeFromBid(bid) { | ||
return bid.mediaTypes && Object.keys(bid.mediaTypes)[0] | ||
} | ||
|
||
function wrapAd(bid, bidData) { | ||
return `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title></title> | ||
<script src="https://st.astraone.io/prebidrenderer.js"></script> | ||
<style>html, body {width: 100%; height: 100%; margin: 0;}</style> | ||
</head> | ||
<body> | ||
<div data-hyb-ssp-in-image-overlay="${bidData.content.placeId}" style="width: 100%; height: 100%;"></div> | ||
<script> | ||
if (parent.window.frames[window.name]) { | ||
var parentDocument = window.parent.document.getElementById(parent.window.frames[window.name].name); | ||
parentDocument.style.height = "100%"; | ||
parentDocument.style.width = "100%"; | ||
} | ||
var _html = "${encodeURIComponent(JSON.stringify(bid))}"; | ||
window._ao_ssp.registerInImage(JSON.parse(decodeURIComponent(_html))); | ||
</script> | ||
</body> | ||
</html>`; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
/** | ||
* 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(bid) { | ||
return ( | ||
getMediaTypeFromBid(bid) === BANNER && | ||
!!bid.params.placeId && | ||
!!bid.params.imageUrl && | ||
!!bid.params.placement && | ||
(bid.params.placement === 'inImage') | ||
); | ||
}, | ||
|
||
/** | ||
* 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(validBidRequests, bidderRequest) { | ||
const payload = { | ||
url: bidderRequest.refererInfo.referer, | ||
cmp: !!bidderRequest.gdprConsent, | ||
bidRequests: buildBidRequests(validBidRequests) | ||
}; | ||
|
||
if (payload.cmp) { | ||
const gdprApplies = bidderRequest.gdprConsent.gdprApplies; | ||
if (gdprApplies !== undefined) payload['ga'] = gdprApplies; | ||
payload['cs'] = bidderRequest.gdprConsent.consentString; | ||
} | ||
|
||
const payloadString = JSON.stringify(payload); | ||
return { | ||
method: 'POST', | ||
url: SSP_ENDPOINT, | ||
data: payloadString, | ||
options: { | ||
contentType: 'application/json' | ||
} | ||
} | ||
}, | ||
|
||
/** | ||
* 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) { | ||
const serverBody = serverResponse.body; | ||
if (serverBody && utils.isArray(serverBody)) { | ||
return utils._map(serverBody, function(bid) { | ||
return buildBid(bid); | ||
}); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
} | ||
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,198 @@ | ||
# Overview | ||
|
||
|
||
**Module Name**: AstraOne Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: prebid@astraone.io | ||
|
||
# Description | ||
|
||
You can use this adapter to get a bid from AstraOne. | ||
Please reach out to your AstraOne account team before using this plugin to get placeId. | ||
The code below returns a demo ad. | ||
|
||
About us: https://astraone.io | ||
|
||
# Test Parameters | ||
```js | ||
var adUnits = [{ | ||
code: 'test-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [], | ||
} | ||
}, | ||
bids: [{ | ||
bidder: "astraone", | ||
params: { | ||
placement: "inImage", | ||
placeId: "5af45ad34d506ee7acad0c26", | ||
imageUrl: "https://creative.astraone.io/files/default_image-1-600x400.jpg" | ||
} | ||
}] | ||
}]; | ||
``` | ||
|
||
# Example page | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Prebid.js Banner Example</title> | ||
<script async src="prebid.js"></script> | ||
<style> | ||
.banner-block { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
z-index: 1; | ||
border: none; | ||
overflow: hidden; | ||
} | ||
</style> | ||
<script> | ||
var adUnits = [{ | ||
code: 'test-div', | ||
sizes: [],`` | ||
bids: [{ | ||
bidder: "astraone", | ||
params: { | ||
placement: "inImage", | ||
placeId: "5af45ad34d506ee7acad0c26", | ||
imageUrl: "https://creative.astraone.io/files/default_image-1-600x400.jpg" | ||
} | ||
}] | ||
}]; | ||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
pbjs.que.push(function() { | ||
pbjs.addAdUnits(adUnits); | ||
pbjs.requestBids({ | ||
bidsBackHandler: function (e) { | ||
if (pbjs.adserverRequestSent) return; | ||
pbjs.adserverRequestSent = true; | ||
var params = pbjs.getAdserverTargetingForAdUnitCode("test-div"); | ||
var iframe = document.getElementById('test-div'); | ||
if (params && params['hb_adid']) { | ||
iframe.parentElement.style.position = "relative"; | ||
iframe.style.display = "block"; | ||
pbjs.renderAd(iframe.contentDocument, params['hb_adid']); | ||
} | ||
} | ||
}); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h2>Prebid.js InImage Banner Test</h2> | ||
|
||
<div style="width: 600px;"> | ||
<img src="https://creative.astraone.io/files/default_image-1-600x400.jpg" /> | ||
<iframe id='test-div' class="banner-block" style="display: none;"></iframe> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
``` | ||
# Example page with GPT | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Prebid.js Banner Example</title> | ||
<script async src="prebid.js"></script> | ||
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script> | ||
<style> | ||
.banner-block { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
z-index: 1; | ||
border: none; | ||
overflow: hidden; | ||
} | ||
.banner-block div { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> | ||
<script> | ||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
var adUnits = [{ | ||
code: 'div-gpt-ad-1574864639578-0', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [], | ||
} | ||
}, | ||
bids: [{ | ||
bidder: "astraone", | ||
params: { | ||
placement: "inImage", | ||
placeId: "5af45ad34d506ee7acad0c26", | ||
imageUrl: "https://creative.astraone.io/files/default_image-1-600x400.jpg" | ||
} | ||
}] | ||
}]; | ||
var googletag = googletag || {}; | ||
googletag.cmd = googletag.cmd || []; | ||
googletag.cmd.push(() => { | ||
googletag.pubads().disableInitialLoad(); | ||
}); | ||
pbjs.que.push(() => { | ||
pbjs.addAdUnits(adUnits); | ||
pbjs.requestBids({ bidsBackHandler: sendAdServerRequest }); | ||
}); | ||
function sendAdServerRequest() { | ||
googletag.cmd.push(() => { | ||
pbjs.que.push(() => { | ||
pbjs.setTargetingForGPTAsync('div-gpt-ad-1574864639578-0'); | ||
googletag.pubads().refresh(); | ||
}); | ||
}); | ||
} | ||
googletag.cmd.push(() => { | ||
googletag | ||
.defineSlot('/21877108735/rtb-pbjs', [1, 1], 'div-gpt-ad-1574864639578-0') | ||
.addService(googletag.pubads()); | ||
googletag.pubads().enableSingleRequest(); | ||
googletag.enableServices(); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<h2>Prebid.js Banner Ad Unit Test</h2> | ||
|
||
<div style="width: 600px; position: relative"> | ||
<img src="https://creative.astraone.io/files/default_image-1-600x400.jpg" /> | ||
|
||
<div id='div-gpt-ad-1574864639578-0' class="banner-block"> | ||
<script> | ||
googletag.cmd.push(() => { googletag.display('div-gpt-ad-1574864639578-0'); }); | ||
</script> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
``` |
Oops, something went wrong.