-
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.
Brainx Bid Adapter : initial release (#12413)
* add brainx adpater * fix adpater md * delete console * fix repeat * Modify fixed parameters * Modify endpoint to be optional * fix email * update endpoint url * remove hello_html & x-domain history changes * fix size * remove empty line * Update brainxBidAdapter.md --------- Co-authored-by: hugh.qu <[email protected]> Co-authored-by: Chris Huie <[email protected]>
- Loading branch information
1 parent
e060b74
commit 8686d9e
Showing
4 changed files
with
306 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -92,4 +92,4 @@ <h5>Div-1</h5> | |
</div> | ||
</body> | ||
|
||
</html> | ||
</html> |
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,117 @@ | ||
import { deepAccess, generateUUID, isArray, logWarn } from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
// import { config } from 'src/config.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import { ortbConverter } from '../libraries/ortbConverter/converter.js' | ||
// import { config } from '../src/config.js'; | ||
|
||
const BIDDER_CODE = 'brainx'; | ||
const METHOD = 'POST'; | ||
const TTL = 200; | ||
const NET_REV = true; | ||
let ENDPOINT = 'https://dsp.brainx.tech/bid' | ||
// let ENDPOINT = 'http://adx-engine-gray.tec-do.cn/bid' | ||
|
||
const converter = ortbConverter({ | ||
context: { | ||
// `netRevenue` and `ttl` are required properties of bid responses - provide a default for them | ||
netRevenue: NET_REV, // or false if your adapter should set bidResponse.netRevenue = false | ||
ttl: TTL // default bidResponse.ttl (when not specified in ORTB response.seatbid[].bid[].exp) | ||
} | ||
}); | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
// gvlid: IAB_GVL_ID, | ||
// aliases: [ | ||
// { code: "myalias", gvlid: IAB_GVL_ID_IF_DIFFERENT } | ||
// ], | ||
isBidRequestValid: function (bid) { | ||
if (!(hasBanner(bid) || hasVideo(bid))) { | ||
logWarn('Invalid bid request - missing required mediaTypes'); | ||
return false; | ||
} | ||
if (!(bid && bid.params)) { | ||
logWarn('Invalid bid request - missing required bid data'); | ||
return false; | ||
} | ||
|
||
if (!(bid.params.pubId)) { | ||
logWarn('Invalid bid request - missing required field pubId'); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
buildRequests(bidRequests, bidderRequest) { | ||
const data = converter.toORTB({ bidRequests, bidderRequest }) | ||
ENDPOINT = String(deepAccess(bidRequests[0], 'params.endpoint')) ? deepAccess(bidRequests[0], 'params.endpoint') : ENDPOINT | ||
data.user = { | ||
buyeruid: generateUUID() | ||
} | ||
return { | ||
method: METHOD, | ||
url: `${ENDPOINT}?token=${String(deepAccess(bidRequests[0], 'params.pubId'))}`, | ||
data | ||
} | ||
}, | ||
interpretResponse(response, request) { | ||
let bids = []; | ||
if (response.body && response.body.seatbid && isArray(response.body.seatbid)) { | ||
response.body.seatbid.forEach(function (bidder) { | ||
if (isArray(bidder.bid)) { | ||
bidder.bid.map((bid) => { | ||
let serverBody = response.body; | ||
// bidRequest = request.originalBidRequest, | ||
let mediaType = BANNER; | ||
let currency = serverBody.cur || 'USD' | ||
|
||
const cpm = (parseFloat(bid.price) || 0).toFixed(2); | ||
const categories = deepAccess(bid, 'cat', []); | ||
|
||
const bidRes = { | ||
ad: bid.adm, | ||
width: bid.w, | ||
height: bid.h, | ||
requestId: bid.impid, | ||
cpm: cpm, | ||
currency: currency, | ||
mediaType: mediaType, | ||
ttl: TTL, | ||
creativeId: bid.crid || bid.id, | ||
netRevenue: NET_REV, | ||
nurl: bid.nurl, | ||
lurl: bid.lurl, | ||
meta: { | ||
mediaType: mediaType, | ||
primaryCatId: categories[0], | ||
secondaryCatIds: categories.slice(1), | ||
} | ||
}; | ||
if (bid.adomain && isArray(bid.adomain) && bid.adomain.length > 0) { | ||
bidRes.meta.advertiserDomains = bid.adomain; | ||
bidRes.meta.clickUrl = bid.adomain[0]; | ||
} | ||
bids.push(bidRes); | ||
}) | ||
} | ||
}); | ||
} | ||
|
||
return bids; | ||
}, | ||
// getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) { }, | ||
// onTimeout: function (timeoutData) { }, | ||
// onBidWon: function (bid) { }, | ||
// onSetTargeting: function (bid) { }, | ||
// onBidderError: function ({ error, bidderRequest }) { }, | ||
// onAdRenderSucceeded: function (bid) { }, | ||
supportedMediaTypes: [BANNER] | ||
} | ||
function hasBanner(bidRequest) { | ||
return !!deepAccess(bidRequest, 'mediaTypes.banner'); | ||
} | ||
function hasVideo(bidRequest) { | ||
return !!deepAccess(bidRequest, 'mediaTypes.video'); | ||
} | ||
|
||
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,56 @@ | ||
# brianx Bidder Adapter | ||
|
||
## Overview | ||
|
||
``` | ||
Module Name: brianx Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
## Description | ||
|
||
Module that connects to brianx's demand sources | ||
|
||
## Bid Parameters | ||
|
||
| Name | Scope | Type | Description | Example | | ||
| ---------- | ------------ | ------ | ------------------------------------ | -------------------------------------- | | ||
| `pubId` | required | String | The Pub Id provided by Brainx Ads. | `F7B53DBC-85C1-4685-9A06-9CF4B6261FA3` | | ||
| `endpoint` | optional | String | The endpoint provided by Brainx Url. | `https://dsp.brainx.tech/bid` | | ||
|
||
## Example | ||
|
||
### Banner Ads | ||
|
||
```javascript | ||
var adUnits = [{ | ||
code: 'banner-ad-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [ | ||
[320, 250], | ||
[320, 480] | ||
] | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'brianx', | ||
params: { | ||
pubId: 'F7B53DBC-85C1-4685-9A06-9CF4B6261FA3', | ||
endpoint: 'https://dsp.brainx.tech/bid' | ||
} | ||
}] | ||
}]; | ||
``` | ||
|
||
* For video ads, enable prebid cache. | ||
|
||
```javascript | ||
pbjs.setConfig({ | ||
ortb2: { | ||
ortbVersion: '2.5' | ||
}, | ||
debug: false // or true | ||
}); | ||
``` |
Oops, something went wrong.