-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Trafficgate Bid Adapter: move to OpenRTB Converter #10007
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
Changes from 2 commits
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 |
---|---|---|
@@ -1,95 +1,155 @@ | ||
import { getWindowLocation, deepAccess } from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; | ||
import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; | ||
import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
import {BANNER, VIDEO} from '../src/mediaTypes.js'; | ||
import {ortbConverter} from '../libraries/ortbConverter/converter.js'; | ||
import {deepAccess, mergeDeep, deepSetValue, convertTypes} from '../src/utils.js'; | ||
|
||
const BIDDER_CODE = 'trafficgate'; | ||
const URL = 'https://[HOST].bc-plugin.com/?c=o&m=multi' | ||
const URL = 'https://[HOST].bc-plugin.com/prebidjs' | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER, VIDEO, NATIVE], | ||
supportedMediaTypes: [BANNER, VIDEO], | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
transformBidParams, | ||
isBannerBid | ||
}; | ||
|
||
isBidRequestValid: function (bid) { | ||
return !!(bid.bidId && bid.params && parseInt(bid.params.placementId) && bid.params.host) | ||
}, | ||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {BidRequest[]} validBidRequests A non-empty list of valid bid requests that should be sent to the Server. | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests) { | ||
// convert Native ORTB definition to old-style prebid native definition | ||
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests); | ||
if (validBidRequests && validBidRequests.length === 0) return []; | ||
|
||
const location = getWindowLocation() | ||
const placements = [] | ||
|
||
validBidRequests.forEach((bidReq) => { | ||
placements.push({ | ||
placementId: bidReq.params.placementId, | ||
bidId: bidReq.bidId, | ||
traffic: getMediatype(bidReq) | ||
}) | ||
}) | ||
registerBidder(spec) | ||
|
||
return { | ||
method: 'POST', | ||
url: URL.replace('[HOST]', validBidRequests[0].params.host), | ||
data: { | ||
language: (navigator && navigator.language) ? navigator.language : '', | ||
secure: +(location.protocol === 'https:'), | ||
host: location.hostname, | ||
page: location.pathname, | ||
placements: placements | ||
const converter = ortbConverter({ | ||
context: { | ||
netRevenue: true, | ||
ttl: 300 | ||
}, | ||
imp(buildImp, bidRequest, context) { | ||
const imp = buildImp(bidRequest, context); | ||
mergeDeep(imp, { | ||
ext: { | ||
bidder: { | ||
placementId: bidRequest.params.placementId, | ||
host: bidRequest.params.host | ||
} | ||
} | ||
}); | ||
if (bidRequest.params.customFloor && !imp.bidfloor) { | ||
imp.bidfloor = bidRequest.params.customFloor; | ||
} | ||
return imp; | ||
}, | ||
|
||
interpretResponse: function (opts) { | ||
const body = opts.body | ||
const response = [] | ||
|
||
for (let i = 0; i < body.length; i++) { | ||
const item = body[i] | ||
if (isBidResponseValid(item)) { | ||
response.push(item) | ||
request(buildRequest, imps, bidderRequest, context) { | ||
const req = buildRequest(imps, bidderRequest, context); | ||
mergeDeep(req, { | ||
at: 1, | ||
}) | ||
const bid = context.bidRequests[0]; | ||
if (bid.params.coppa) { | ||
deepSetValue(req, 'regs.coppa', 1); | ||
} | ||
if (bid.params.doNotTrack) { | ||
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. also this is something prebid willl set based on several checks here: So I think not overwriting is the right thing to do here 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. I removed this too. |
||
deepSetValue(req, 'device.dnt', 1); | ||
} | ||
if (bid.params.test) { | ||
req.test = 1 | ||
} | ||
return req; | ||
}, | ||
bidResponse(buildBidResponse, bid, context) { | ||
const bidResponse = buildBidResponse(bid, context); | ||
if (bid.ext) { | ||
bidResponse.meta.networkId = bid.ext.networkId; | ||
bidResponse.meta.advertiserDomains = bid.ext.advertiserDomains; | ||
} | ||
return bidResponse; | ||
}, | ||
response(buildResponse, bidResponses, ortbResponse, context) { | ||
const response = buildResponse(bidResponses, ortbResponse, context); | ||
return response.bids | ||
}, | ||
overrides: { | ||
imp: { | ||
bidfloor(setBidFloor, imp, bidRequest, context) { | ||
const floor = {}; | ||
setBidFloor(floor, bidRequest, {...context, currency: 'USD'}); | ||
if (floor.bidfloorcur === 'USD') { | ||
Object.assign(imp, floor); | ||
} | ||
}, | ||
video(orig, imp, bidRequest, context) { | ||
if (FEATURES.VIDEO) { | ||
let videoParams = bidRequest.mediaTypes[VIDEO]; | ||
if (videoParams) { | ||
videoParams = Object.assign({}, videoParams, bidRequest.params.video); | ||
bidRequest = {...bidRequest, mediaTypes: {[VIDEO]: videoParams}} | ||
} | ||
orig(imp, bidRequest, context); | ||
if (imp.video && videoParams?.context === 'outstream') { | ||
imp.video.placement = imp.video.placement || 4; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return response | ||
} | ||
} | ||
}); | ||
|
||
registerBidder(spec) | ||
function transformBidParams(params, isOpenRtb) { | ||
return convertTypes({ | ||
'customFloor': 'number', | ||
'placementId': 'number', | ||
'host': 'string' | ||
}, params); | ||
} | ||
|
||
function isBidResponseValid (bid) { | ||
if (!bid.requestId || !bid.cpm || !bid.creativeId || | ||
!bid.ttl || !bid.currency) { | ||
function isBidRequestValid(bidRequest) { | ||
const isValid = bidRequest.params.placementId && bidRequest.params.host; | ||
if (!isValid) { | ||
return false | ||
} | ||
switch (bid['mediaType']) { | ||
case BANNER: | ||
return Boolean(bid.width && bid.height && bid.ad) | ||
case VIDEO: | ||
return Boolean(bid.vastUrl) | ||
case NATIVE: | ||
return Boolean(bid.title && bid.image && bid.impressionTrackers) | ||
default: | ||
return false | ||
if (isBannerBid(bidRequest)) { | ||
return deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0; | ||
} | ||
return true | ||
} | ||
|
||
function getMediatype(bidRequest) { | ||
if (deepAccess(bidRequest, 'mediaTypes.banner')) { | ||
return BANNER; | ||
} | ||
if (deepAccess(bidRequest, 'mediaTypes.video')) { | ||
return VIDEO; | ||
function buildRequests(bids, bidderRequest) { | ||
let videoBids = bids.filter(bid => isVideoBid(bid)); | ||
let bannerBids = bids.filter(bid => isBannerBid(bid)); | ||
let requests = bannerBids.length ? [createRequest(bannerBids, bidderRequest, BANNER)] : []; | ||
videoBids.forEach(bid => { | ||
requests.push(createRequest([bid], bidderRequest, VIDEO)); | ||
}); | ||
return requests; | ||
} | ||
|
||
function createRequest(bidRequests, bidderRequest, mediaType) { | ||
return { | ||
method: 'POST', | ||
url: URL.replace('[HOST]', bidRequests[0].params.host), | ||
data: converter.toORTB({bidRequests, bidderRequest, context: {mediaType}}) | ||
} | ||
if (deepAccess(bidRequest, 'mediaTypes.native')) { | ||
return NATIVE; | ||
} | ||
|
||
function isVideoBid(bid) { | ||
return !!deepAccess(bid, 'mediaTypes.video'); | ||
} | ||
|
||
function isBannerBid(bid) { | ||
return !!deepAccess(bid, 'mediaTypes.banner'); | ||
} | ||
|
||
function interpretResponse(resp, req) { | ||
if (!resp.body) { | ||
resp.body = {nbr: 0}; | ||
} | ||
return converter.fromORTB({request: req.data, response: resp.body}); | ||
} | ||
|
||
export const spec2 = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER, VIDEO], | ||
|
||
isBidRequestValid: function (bid) { | ||
return !!(bid.bidId && bid.params && parseInt(bid.params.placementId) && bid.params.host) | ||
}, | ||
} |
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.
I believe this should be taken from
config.getConfig('coppa')
as priority, which I believe the ortbconverter may already grab it.So this might need to be changed to a conditional only set if
req.regs.coppa
not already setThere 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.
Okey. I removed it.