-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Brainx Bid Adapter : initial release #12413
Changes from 5 commits
c34d66c
c52b2e7
5426a3b
59e0a80
bb0a25b
bf48d1f
5714faa
cc503eb
bbd6677
4273be8
d949c07
f57629a
8af84c4
4d530d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// creative will be rendered, e.g. GAM delivering a SafeFrame | ||
|
||
// this code is autogenerated, also available in 'build/creative/creative.js' | ||
<script>!function(){"use strict";const e="Prebid Event",n=(()=>{const e={frameBorder:0,scrolling:"no",marginHeight:0,marginWidth:0,topMargin:0,leftMargin:0,allowTransparency:"true"};return(n,t)=>{const r=n.createElement("iframe");return Object.entries(Object.assign({},t,e)).forEach((([e,n])=>r.setAttribute(e,n))),r}})();function t(e){return!!e.frames.__pb_locator__}window.pbRender=function(r){let o=r.parent;try{for(;o!==r.top&&!t(o);)o=o.parent;t(o)||(o=r.parent)}catch(e){}return function({adId:t,pubUrl:s,clickUrl:i}){const c=new URL(s,window.location).origin;function a(e,n,r){const s=new MessageChannel;s.port1.onmessage=u(r),o.postMessage(JSON.stringify(Object.assign({message:e,adId:t},n)),c,[s.port2])}function d(n){a(e,{event:"adRenderFailed",info:{reason:n?.reason||"exception",message:n?.message}}),n?.stack&&console.error(n)}function u(e){return function(){try{return e.apply(this,arguments)}catch(e){d(e)}}}a("Prebid Request",{options:{clickUrl:i}},(function(o){let s;try{s=JSON.parse(o.data)}catch(e){return}if("Prebid Response"===s.message&&s.adId===t){const t=n(r.document,{width:0,height:0,style:"display: none",srcdoc:`<script>${s.renderer}<\/script>`});t.onload=u((function(){const o=t.contentWindow;o.Promise.resolve(o.render(s,{sendMessage:a,mkFrame:n},r)).then((()=>a(e,{event:"adRenderSucceeded"})),d)})),r.document.body.appendChild(t)}}))}}(window)}();</script> | ||
<script>(()=>{"use strict";const e="Prebid Event",n=(()=>{const e={frameBorder:0,scrolling:"no",marginHeight:0,marginWidth:0,topMargin:0,leftMargin:0,allowTransparency:"true"};return(n,t)=>{const r=n.createElement("iframe");return Object.entries(Object.assign({},t,e)).forEach((([e,n])=>r.setAttribute(e,n))),r}})();function t(e){return!!e.frames.__pb_locator__}window.pbRender=function(r){let o=r.parent;try{for(;o!==r.top&&!t(o);)o=o.parent;t(o)||(o=r.parent)}catch(e){}return function({adId:t,pubUrl:s,clickUrl:i}){const a=new URL(s,window.location).origin;function c(e,n,r){const s=new MessageChannel;s.port1.onmessage=l(r),o.postMessage(JSON.stringify(Object.assign({message:e,adId:t},n)),a,[s.port2])}function d(n){c(e,{event:"adRenderFailed",info:{reason:n?.reason||"exception",message:n?.message}}),n?.stack&&console.error(n)}function l(e){return function(){try{return e.apply(this,arguments)}catch(e){d(e)}}}c("Prebid Request",{options:{clickUrl:i}},(function(o){let s;try{s=JSON.parse(o.data)}catch(e){return}if("Prebid Response"===s.message&&s.adId===t){const t=n(r.document,{width:0,height:0,style:"display: none",srcdoc:`<script>${s.renderer}<\/script>`});t.onload=l((function(){const o=t.contentWindow;o.Promise.resolve(o.render(s,{sendMessage:c,mkFrame:n},r)).then((()=>c(e,{event:"adRenderSucceeded"})),d)})),r.document.body.appendChild(t)}}))}}(window)})();</script> | ||
|
||
<script> | ||
pbRender({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove changes to this file in the pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already restored |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
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; | ||
|
||
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 }) | ||
data.user = { | ||
buyeruid: generateUUID() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is odd, it will change every request |
||
} | ||
return { | ||
method: METHOD, | ||
url: `${String(deepAccess(bidRequests[0], 'params.endpoint'))}?token=${String(deepAccess(bidRequests[0], 'params.pubId'))}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. endpoint cannot be a required parameter. It is incredibly awkward for publishers to have to enter a hostname on thousands of adunits when this is a global config. It may be an optional parameter, but a default is required. You may also ask the publisher to
At least this is not then replicated thousands of times for each adunit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thank you for your reply. We will continue to make adjustments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, bretg, we have made adjustments to the above issues. Please review it again. |
||
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); |
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` | required | String | The endpoint provided by Brainx Url. | `http://adx-engine-gray.tec-do.cn/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: 'http://adx-engine-gray.tec-do.cn/bid' | ||
} | ||
}] | ||
}]; | ||
``` | ||
|
||
* For video ads, enable prebid cache. | ||
|
||
```javascript | ||
pbjs.setConfig({ | ||
ortb2: { | ||
ortbVersion: '2.5' | ||
}, | ||
debug: true // or false | ||
}); | ||
``` |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove changes to this file in pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already restored