-
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
New Adapter: Oraki #11727
New Adapter: Oraki #11727
Changes from 4 commits
56be073
5ea0492
9b86138
776989b
a3ffa44
8cdd4cf
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 |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import { logMessage, deepAccess } from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; | ||
import { config } from '../src/config.js'; | ||
|
||
const BIDDER_CODE = 'oraki'; | ||
const AD_URL = 'https://eu1.oraki.io/pbjs'; | ||
const SYNC_URL = 'https://sync.oraki.io'; | ||
|
||
function isBidResponseValid(bid) { | ||
if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency) { | ||
return false; | ||
} | ||
|
||
switch (bid.mediaType) { | ||
case BANNER: | ||
return Boolean(bid.width && bid.height && bid.ad); | ||
case VIDEO: | ||
return Boolean(bid.vastUrl || bid.vastXml); | ||
case NATIVE: | ||
return Boolean(bid.native && bid.native.impressionTrackers && bid.native.impressionTrackers.length); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
function getPlacementReqData(bid) { | ||
const { params, bidId, mediaTypes, transactionId, userIdAsEids } = bid; | ||
const schain = bid.schain || {}; | ||
const { placementId, endpointId } = params; | ||
const bidfloor = getBidFloor(bid); | ||
|
||
const placement = { | ||
bidId, | ||
schain, | ||
bidfloor | ||
}; | ||
|
||
if (placementId) { | ||
placement.placementId = placementId; | ||
placement.type = 'publisher'; | ||
} else if (endpointId) { | ||
placement.endpointId = endpointId; | ||
placement.type = 'network'; | ||
} | ||
|
||
if (mediaTypes && mediaTypes[BANNER]) { | ||
placement.adFormat = BANNER; | ||
placement.sizes = mediaTypes[BANNER].sizes; | ||
} else if (mediaTypes && mediaTypes[VIDEO]) { | ||
placement.adFormat = VIDEO; | ||
placement.playerSize = mediaTypes[VIDEO].playerSize; | ||
placement.minduration = mediaTypes[VIDEO].minduration; | ||
placement.maxduration = mediaTypes[VIDEO].maxduration; | ||
placement.mimes = mediaTypes[VIDEO].mimes; | ||
placement.protocols = mediaTypes[VIDEO].protocols; | ||
placement.startdelay = mediaTypes[VIDEO].startdelay; | ||
placement.plcmt = mediaTypes[VIDEO].plcmt; | ||
placement.skip = mediaTypes[VIDEO].skip; | ||
placement.skipafter = mediaTypes[VIDEO].skipafter; | ||
placement.minbitrate = mediaTypes[VIDEO].minbitrate; | ||
placement.maxbitrate = mediaTypes[VIDEO].maxbitrate; | ||
placement.delivery = mediaTypes[VIDEO].delivery; | ||
placement.playbackmethod = mediaTypes[VIDEO].playbackmethod; | ||
placement.api = mediaTypes[VIDEO].api; | ||
placement.linearity = mediaTypes[VIDEO].linearity; | ||
} else if (mediaTypes && mediaTypes[NATIVE]) { | ||
placement.native = mediaTypes[NATIVE]; | ||
placement.adFormat = NATIVE; | ||
} | ||
|
||
if (transactionId) { | ||
placement.ext = placement.ext || {}; | ||
placement.ext.tid = transactionId; | ||
} | ||
|
||
if (userIdAsEids && userIdAsEids.length) { | ||
placement.eids = userIdAsEids; | ||
} | ||
|
||
return placement; | ||
} | ||
|
||
function getBidFloor(bid) { | ||
try { | ||
const bidFloor = bid.getFloor({ | ||
currency: 'USD', | ||
mediaType: '*', | ||
size: '*', | ||
}); | ||
return bidFloor.floor; | ||
} catch { | ||
return 0; | ||
} | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER, VIDEO, NATIVE], | ||
|
||
isBidRequestValid: (bid = {}) => { | ||
const { params, bidId, mediaTypes } = bid; | ||
let valid = Boolean(bidId && params && (params.placementId || params.endpointId)); | ||
|
||
if (mediaTypes && mediaTypes[BANNER]) { | ||
valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes); | ||
} else if (mediaTypes && mediaTypes[VIDEO]) { | ||
valid = valid && Boolean(mediaTypes[VIDEO] && mediaTypes[VIDEO].playerSize); | ||
} else if (mediaTypes && mediaTypes[NATIVE]) { | ||
valid = valid && Boolean(mediaTypes[NATIVE]); | ||
} else { | ||
valid = false; | ||
} | ||
return valid; | ||
}, | ||
|
||
buildRequests: (validBidRequests = [], bidderRequest = {}) => { | ||
const device = deepAccess(bidderRequest, 'ortb2.device'); | ||
const page = deepAccess(bidderRequest, 'refererInfo.page', ''); | ||
|
||
let pageURL; | ||
try { | ||
pageURL = page && new URL(page); | ||
} catch (e) { | ||
logMessage(e); | ||
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. If your test bid requests don't have proper locations this pollutes our circleci output a bunch 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. 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. Could you please point out the code line that is causing this problem? |
||
} | ||
|
||
const placements = []; | ||
const request = { | ||
deviceWidth: device?.w || 0, | ||
deviceHeight: device?.h || 0, | ||
language: device?.language?.split('-')[0] || '', | ||
secure: pageURL.protocol === 'https:' ? 1 : 0, | ||
host: pageURL.host, | ||
page: pageURL.href, | ||
placements, | ||
coppa: deepAccess(bidderRequest, 'ortb2.regs.coppa') ? 1 : 0, | ||
tmax: bidderRequest.timeout | ||
}; | ||
|
||
if (bidderRequest.uspConsent) { | ||
request.ccpa = bidderRequest.uspConsent; | ||
} | ||
|
||
if (bidderRequest.gdprConsent) { | ||
request.gdpr = { | ||
consentString: bidderRequest.gdprConsent.consentString | ||
}; | ||
} | ||
|
||
if (bidderRequest.gppConsent) { | ||
request.gpp = bidderRequest.gppConsent.gppString; | ||
request.gpp_sid = bidderRequest.gppConsent.applicableSections; | ||
} else if (bidderRequest.ortb2?.regs?.gpp) { | ||
request.gpp = bidderRequest.ortb2.regs.gpp; | ||
request.gpp_sid = bidderRequest.ortb2.regs.gpp_sid; | ||
} | ||
|
||
const len = validBidRequests.length; | ||
for (let i = 0; i < len; i++) { | ||
const bid = validBidRequests[i]; | ||
placements.push(getPlacementReqData(bid)); | ||
} | ||
|
||
return { | ||
method: 'POST', | ||
url: AD_URL, | ||
data: request | ||
}; | ||
}, | ||
|
||
interpretResponse: (serverResponse) => { | ||
let response = []; | ||
for (let i = 0; i < serverResponse.body.length; i++) { | ||
let resItem = serverResponse.body[i]; | ||
if (isBidResponseValid(resItem)) { | ||
const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : []; | ||
resItem.meta = { ...resItem.meta, advertiserDomains }; | ||
|
||
response.push(resItem); | ||
} | ||
} | ||
return response; | ||
}, | ||
|
||
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) => { | ||
let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image'; | ||
let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`; | ||
|
||
if (gdprConsent && gdprConsent.consentString) { | ||
if (typeof gdprConsent.gdprApplies === 'boolean') { | ||
syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; | ||
} else { | ||
syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; | ||
} | ||
} | ||
|
||
if (uspConsent && uspConsent.consentString) { | ||
syncUrl += `&ccpa_consent=${uspConsent.consentString}`; | ||
} | ||
|
||
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) { | ||
syncUrl += '&gpp=' + gppConsent.gppString; | ||
syncUrl += '&gpp_sid=' + gppConsent.applicableSections.join(','); | ||
} | ||
|
||
const coppa = config.getConfig('coppa') ? 1 : 0; | ||
patmmccann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
syncUrl += `&coppa=${coppa}`; | ||
|
||
return [{ | ||
type: syncType, | ||
url: syncUrl | ||
}]; | ||
} | ||
}; | ||
|
||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Oraki Bidder Adapter | ||
Module Type: Oraki Bidder Adapter | ||
Maintainer: ben@oraki.io | ||
``` | ||
|
||
# Description | ||
|
||
Connects to Oraki exchange for bids. | ||
Oraki bid adapter supports Banner, Video (instream and outstream) and Native. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
// Will return static test banner | ||
{ | ||
code: 'adunit1', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [ [300, 250], [320, 50] ], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'oraki', | ||
params: { | ||
placementId: 'testBanner', | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'addunit2', | ||
mediaTypes: { | ||
video: { | ||
playerSize: [ [640, 480] ], | ||
context: 'instream', | ||
minduration: 5, | ||
maxduration: 60, | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'oraki', | ||
params: { | ||
placementId: 'testVideo', | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'addunit3', | ||
mediaTypes: { | ||
native: { | ||
title: { | ||
required: true | ||
}, | ||
body: { | ||
required: true | ||
}, | ||
icon: { | ||
required: true, | ||
size: [64, 64] | ||
} | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'oraki', | ||
params: { | ||
placementId: 'testNative', | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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.
Why do 21 bid adapters use this exact same code block. Is one person committing twenty bid adapters?
If so, can you start to move code blocks into to libraries for better maintenance?