-
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.
- Loading branch information
1 parent
58f839c
commit 2fd51d0
Showing
2 changed files
with
227 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,136 @@ | ||
import * as utils from '../src/utils' | ||
import { registerBidder } from '../src/adapters/bidderFactory' | ||
import { BANNER } from '../src/mediaTypes' | ||
import {Renderer} from '../src/Renderer'; | ||
|
||
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, | ||
adUnitId: params.adUnitId, | ||
placement: params.placement, | ||
placeId: params.placeId, | ||
imageUrl: params.imageUrl | ||
}; | ||
|
||
return bidRequest; | ||
}) | ||
} | ||
|
||
function inImageRender(bid) { | ||
bid.renderer.push(() => { | ||
window._ao_ssp.registerInImage(bid); | ||
}); | ||
} | ||
|
||
function createRenderer() { | ||
const renderer = Renderer.install({ | ||
url: 'https://st.astraone.io/prebidrenderer.js', | ||
loaded: false | ||
}); | ||
|
||
try { | ||
renderer.setRender(inImageRender); | ||
} catch (err) { | ||
utils.logWarn('Prebid Error calling setRender on renderer', err); | ||
} | ||
|
||
return renderer; | ||
} | ||
|
||
function buildBid(bidDada) { | ||
const bid = { | ||
requestId: bidDada.bidId, | ||
cpm: bidDada.price, | ||
width: bidDada.width, | ||
height: bidDada.height, | ||
creativeId: bidDada.content.seanceId, | ||
currency: bidDada.currency, | ||
netRevenue: true, | ||
mediaType: BANNER, | ||
ttl: TTL, | ||
ad: bidDada.content.content, | ||
content: bidDada.content | ||
}; | ||
|
||
Object.assign(bid, { | ||
renderer: createRenderer(bid) | ||
}); | ||
|
||
return bid; | ||
} | ||
|
||
function getMediaTypeFromBid(bid) { | ||
return bid.mediaTypes && Object.keys(bid.mediaTypes)[0] | ||
} | ||
|
||
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; | ||
}, | ||
|
||
/** | ||
* 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,91 @@ | ||
# 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> | ||
<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 div = document.getElementById('test-div'); | ||
if (params && params['hb_adid']) { | ||
pbjs.renderAd(div, params['hb_adid']); | ||
} | ||
} | ||
}); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<h2>Prebid.js InImage Banner Test</h2> | ||
|
||
<div style="width: 600px;" id='test-div'> | ||
<img src="https://creative.astraone.io/files/default_image-1-600x400.jpg" /> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
``` | ||
|