-
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.
Axis Bid Adapter : initial release (#9684)
* New Adapter: Axis * minor improvements * fixed coppa and tmax * updated iabCat --------- Co-authored-by: Maksym Pavliv <[email protected]>
- Loading branch information
1 parent
c3409af
commit 5fba72d
Showing
3 changed files
with
707 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,210 @@ | ||
import { isFn, deepAccess, logMessage, logError } from '../src/utils.js'; | ||
import { convertOrtbRequestToProprietaryNative } from '../src/native.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 = 'axis'; | ||
const AD_URL = 'https://prebid.axis-marketplace.com/pbjs'; | ||
const SYNC_URL = 'https://cs.axis-marketplace.com'; | ||
|
||
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 } = bid; | ||
const schain = bid.schain || {}; | ||
const { integration, token } = params; | ||
const bidfloor = getBidFloor(bid); | ||
|
||
const placement = { | ||
integration, | ||
token, | ||
bidId, | ||
schain, | ||
bidfloor | ||
}; | ||
|
||
if (mediaTypes && mediaTypes[BANNER]) { | ||
placement.adFormat = BANNER; | ||
placement.pos = mediaTypes[BANNER].pos; | ||
placement.sizes = mediaTypes[BANNER].sizes; | ||
} else if (mediaTypes && mediaTypes[VIDEO]) { | ||
placement.adFormat = VIDEO; | ||
placement.pos = mediaTypes[VIDEO].pos; | ||
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.placement = mediaTypes[VIDEO].placement; | ||
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; | ||
placement.context = mediaTypes[VIDEO].context; | ||
} else if (mediaTypes && mediaTypes[NATIVE]) { | ||
placement.native = mediaTypes[NATIVE]; | ||
placement.adFormat = NATIVE; | ||
} | ||
|
||
return placement; | ||
} | ||
|
||
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 (e) { | ||
logError(e); | ||
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.integration && params.token); | ||
|
||
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 = {}) => { | ||
// convert Native ORTB definition to old-style prebid native definition | ||
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests); | ||
|
||
let deviceWidth = 0; | ||
let deviceHeight = 0; | ||
|
||
let winLocation; | ||
try { | ||
const winTop = window.top; | ||
deviceWidth = winTop.screen.width; | ||
deviceHeight = winTop.screen.height; | ||
winLocation = winTop.location; | ||
} catch (e) { | ||
logMessage(e); | ||
winLocation = window.location; | ||
} | ||
|
||
const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.page; | ||
let refferLocation; | ||
try { | ||
refferLocation = refferUrl && new URL(refferUrl); | ||
} catch (e) { | ||
logMessage(e); | ||
} | ||
|
||
let location = refferLocation || winLocation; | ||
const language = (navigator && navigator.language) ? navigator.language.split('-')[0] : ''; | ||
const host = location.host; | ||
const page = location.pathname; | ||
const secure = location.protocol === 'https:' ? 1 : 0; | ||
const placements = []; | ||
const request = { | ||
deviceWidth, | ||
deviceHeight, | ||
language, | ||
secure, | ||
host, | ||
page, | ||
placements, | ||
iabCat: deepAccess(bidderRequest, 'ortb2.site.cat'), | ||
coppa: deepAccess(bidderRequest, 'ortb2.regs.coppa') ? 1 : 0, | ||
ccpa: bidderRequest.uspConsent || undefined, | ||
gdpr: bidderRequest.gdprConsent || undefined, | ||
tmax: bidderRequest.timeout || 3000, | ||
}; | ||
|
||
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) => { | ||
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=${uspConsent.consentString}`; | ||
} | ||
|
||
const coppa = config.getConfig('coppa') ? 1 : 0; | ||
syncUrl += `&coppa=${coppa}`; | ||
|
||
return [{ | ||
type: syncType, | ||
url: syncUrl | ||
}]; | ||
} | ||
}; | ||
|
||
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,83 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Axis Bidder Adapter | ||
Module Type: Axis Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Connects to Axis exchange for bids. | ||
Axis 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] ], | ||
pos: 1 | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'axis', | ||
params: { | ||
integration: '000000', | ||
token: '000000' | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'addunit2', | ||
mediaTypes: { | ||
video: { | ||
playerSize: [ [640, 480] ], | ||
minduration: 5, | ||
maxduration: 60, | ||
pos: 1 | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'axis', | ||
params: { | ||
integration: '000000', | ||
token: '000000' | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'addunit3', | ||
mediaTypes: { | ||
native: { | ||
title: { | ||
required: true | ||
}, | ||
body: { | ||
required: true | ||
}, | ||
icon: { | ||
required: true, | ||
size: [64, 64] | ||
} | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'axis', | ||
params: { | ||
integration: '000000', | ||
token: '000000' | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
Oops, something went wrong.