forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redtram Bid Adapter : initial adapter release (prebid#9260)
* Add Redtram Bid Adapter * add on bidWon test * extend tests * remove convertOrtbRequestToProprietaryNative 9260#pullrequestreview-1196218534 Co-authored-by: Oleh Naimushyn <ncm.net@gmail.com>
- Loading branch information
1 parent
7184b6c
commit 809583f
Showing
3 changed files
with
444 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,155 @@ | ||
import { | ||
isFn, | ||
isStr, | ||
deepAccess, | ||
getWindowTop, | ||
triggerPixel | ||
} from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import { config } from '../src/config.js'; | ||
|
||
const BIDDER_CODE = 'redtram'; | ||
const AD_URL = 'https://prebid.redtram.com/pbjs'; | ||
const SYNC_URL = 'https://prebid.redtram.com/sync'; | ||
|
||
function isBidResponseValid(bid) { | ||
if (!bid.requestId || !bid.cpm || !bid.creativeId || | ||
!bid.ttl || !bid.currency || !bid.meta) { | ||
return false; | ||
} | ||
|
||
switch (bid.mediaType) { | ||
case BANNER: | ||
return Boolean(bid.width && bid.height && bid.ad); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
function getBidFloor(bid) { | ||
if (!isFn(bid.getFloor)) { | ||
return deepAccess(bid, 'params.bidFloor', 0); | ||
} | ||
|
||
try { | ||
const bidFloor = bid.getFloor({ | ||
currency: 'USD', | ||
mediaType: '*', | ||
size: '*', | ||
}); | ||
return bidFloor.floor; | ||
} catch (_) { | ||
return 0 | ||
} | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
isBidRequestValid: (bid) => { | ||
return Boolean(bid.bidId && bid.params && bid.params.placementId); | ||
}, | ||
|
||
buildRequests: (validBidRequests = [], bidderRequest) => { | ||
const winTop = getWindowTop(); | ||
const location = winTop.location; | ||
const placements = []; | ||
|
||
const request = { | ||
deviceWidth: winTop.screen.width, | ||
deviceHeight: winTop.screen.height, | ||
language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '', | ||
host: location.host, | ||
page: location.pathname, | ||
placements: placements | ||
}; | ||
|
||
if (bidderRequest) { | ||
if (bidderRequest.uspConsent) { | ||
request.ccpa = bidderRequest.uspConsent; | ||
} | ||
if (bidderRequest.gdprConsent) { | ||
request.gdpr = bidderRequest.gdprConsent; | ||
} | ||
} | ||
|
||
const len = validBidRequests.length; | ||
for (let i = 0; i < len; i++) { | ||
const bid = validBidRequests[i]; | ||
const placement = { | ||
placementId: bid.params.placementId, | ||
bidId: bid.bidId, | ||
schain: bid.schain || {}, | ||
bidfloor: getBidFloor(bid) | ||
}; | ||
|
||
if (typeof bid.userId !== 'undefined') { | ||
placement.userId = bid.userId; | ||
} | ||
|
||
const mediaType = bid.mediaTypes; | ||
|
||
if (mediaType && mediaType[BANNER] && mediaType[BANNER].sizes) { | ||
placement.sizes = mediaType[BANNER].sizes; | ||
placement.adFormat = BANNER; | ||
} | ||
|
||
placements.push(placement); | ||
} | ||
|
||
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) => { | ||
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}`; | ||
} | ||
|
||
const coppa = config.getConfig('coppa') ? 1 : 0; | ||
syncUrl += `&coppa=${coppa}`; | ||
|
||
return [{ | ||
type: syncType, | ||
url: syncUrl | ||
}]; | ||
}, | ||
|
||
onBidWon: (bid) => { | ||
const cpm = deepAccess(bid, 'adserverTargeting.hb_pb') || ''; | ||
if (isStr(bid.nurl) && bid.nurl !== '') { | ||
bid.nurl = bid.nurl.replace(/\${AUCTION_PRICE}/, cpm); | ||
triggerPixel(bid.nurl); | ||
} | ||
} | ||
}; | ||
|
||
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,33 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: redtram Bidder Adapter | ||
Module Type: redtram Bidder Adapter | ||
Maintainer: support@redtram.com | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to redtram demand sources | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'div-prebid', | ||
mediaTypes:{ | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids:[ | ||
{ | ||
bidder: 'redtram', | ||
params: { | ||
placementId: '23611' //test, please replace after test | ||
} | ||
} | ||
] | ||
}, | ||
]; | ||
``` |
Oops, something went wrong.