-
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.
Update adxcg adapter for prebid 1.0 (#1741)
* updated adxcg adapter for prebid 1.0 * update for prebid 1.0 with dead code and bidder removed * updates to spec file for prebid 1.0 - removal of biddercode check * updated adxcg bidadapter for prebid-1.0 with response headers
- Loading branch information
1 parent
90c66f2
commit d5f1cd1
Showing
3 changed files
with
414 additions
and
294 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 |
---|---|---|
@@ -1,139 +1,155 @@ | ||
import bidfactory from 'src/bidfactory'; | ||
import bidmanager from 'src/bidmanager'; | ||
import * as utils from 'src/utils'; | ||
import { STATUS } from 'src/constants'; | ||
import adaptermanager from 'src/adaptermanager'; | ||
import { ajax } from 'src/ajax'; | ||
import * as url from 'src/url'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
import {NATIVE, VIDEO} from 'src/mediaTypes'; | ||
|
||
/** | ||
* Adapter for requesting bids from Adxcg | ||
* updated from latest prebid repo on 2017.08.30 | ||
* Adapter for requesting bids from adxcg.net | ||
* updated to latest prebid repo on 2017.10.20 | ||
*/ | ||
function AdxcgAdapter() { | ||
let bidRequests = {}; | ||
|
||
function _callBids(params) { | ||
if (params.bids && params.bids.length > 0) { | ||
let adZoneIds = []; | ||
let prebidBidIds = []; | ||
let sizes = []; | ||
|
||
params.bids.forEach(bid => { | ||
bidRequests[bid.bidId] = bid; | ||
adZoneIds.push(utils.getBidIdParameter('adzoneid', bid.params)); | ||
prebidBidIds.push(bid.bidId); | ||
sizes.push(utils.parseSizesInput(bid.sizes).join('|')); | ||
}); | ||
|
||
let location = utils.getTopWindowLocation(); | ||
let secure = location.protocol == 'https:'; | ||
|
||
let requestUrl = url.parse(location.href); | ||
requestUrl.search = null; | ||
requestUrl.hash = null; | ||
|
||
let adxcgRequestUrl = url.format({ | ||
protocol: secure ? 'https' : 'http', | ||
hostname: secure ? 'ad-emea-secure.adxcg.net' : 'ad-emea.adxcg.net', | ||
pathname: '/get/adi', | ||
search: { | ||
renderformat: 'javascript', | ||
ver: 'r20141124', | ||
adzoneid: adZoneIds.join(','), | ||
format: sizes.join(','), | ||
prebidBidIds: prebidBidIds.join(','), | ||
url: escape(url.format(requestUrl)), | ||
secure: secure ? '1' : '0' | ||
} | ||
}); | ||
|
||
utils.logMessage(`submitting request: ${adxcgRequestUrl}`); | ||
ajax(adxcgRequestUrl, handleResponse, null, { | ||
withCredentials: true | ||
}); | ||
} | ||
} | ||
|
||
function handleResponse(response) { | ||
let adxcgBidReponseList; | ||
|
||
try { | ||
adxcgBidReponseList = JSON.parse(response); | ||
utils.logMessage(`adxcgBidReponseList: ${JSON.stringify(adxcgBidReponseList)}`); | ||
} catch (error) { | ||
adxcgBidReponseList = []; | ||
utils.logError(error); | ||
} | ||
const BIDDER_CODE = 'adxcg'; | ||
const SUPPORTED_AD_TYPES = [VIDEO, NATIVE]; | ||
const SOURCE = 'pbjs10'; | ||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: SUPPORTED_AD_TYPES, | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {object} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: function (bid) { | ||
return !!(bid.params.adzoneid); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* an array of validBidRequests | ||
* Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
utils.logMessage(`buildRequests: ${JSON.stringify(validBidRequests)}`); | ||
|
||
let adZoneIds = []; | ||
let prebidBidIds = []; | ||
let sizes = []; | ||
|
||
validBidRequests.forEach(bid => { | ||
adZoneIds.push(utils.getBidIdParameter('adzoneid', bid.params)); | ||
prebidBidIds.push(bid.bidId); | ||
sizes.push(utils.parseSizesInput(bid.sizes).join('|')); | ||
}); | ||
|
||
adxcgBidReponseList.forEach(adxcgBidReponse => { | ||
let bidRequest = bidRequests[adxcgBidReponse.bidId]; | ||
delete bidRequests[adxcgBidReponse.bidId]; | ||
|
||
let bid = bidfactory.createBid(STATUS.GOOD, bidRequest); | ||
|
||
bid.creative_id = adxcgBidReponse.creativeId; | ||
bid.code = 'adxcg'; | ||
bid.bidderCode = 'adxcg'; | ||
bid.cpm = adxcgBidReponse.cpm; | ||
|
||
if (adxcgBidReponse.ad) { | ||
bid.ad = adxcgBidReponse.ad; | ||
} else if (adxcgBidReponse.vastUrl) { | ||
bid.vastUrl = adxcgBidReponse.vastUrl; | ||
bid.descriptionUrl = adxcgBidReponse.vastUrl; | ||
bid.mediaType = 'video'; | ||
} else if (adxcgBidReponse.nativeResponse) { | ||
bid.mediaType = 'native'; | ||
|
||
let nativeResponse = adxcgBidReponse.nativeResponse; | ||
|
||
bid['native'] = { | ||
clickUrl: escape(nativeResponse.link.url), | ||
impressionTrackers: nativeResponse.imptrackers | ||
}; | ||
|
||
nativeResponse.assets.forEach(asset => { | ||
if (asset.title && asset.title.text) { | ||
bid['native'].title = asset.title.text; | ||
} | ||
|
||
if (asset.img && asset.img.url) { | ||
bid['native'].image = asset.img.url; | ||
} | ||
|
||
if (asset.data && asset.data.label == 'DESC' && asset.data.value) { | ||
bid['native'].body = asset.data.value; | ||
} | ||
|
||
if (asset.data && asset.data.label == 'SPONSORED' && asset.data.value) { | ||
bid['native'].sponsoredBy = asset.data.value; | ||
} | ||
}); | ||
let location = utils.getTopWindowLocation(); | ||
let secure = location.protocol === 'https:'; | ||
|
||
let requestUrl = url.parse(location.href); | ||
requestUrl.search = null; | ||
requestUrl.hash = null; | ||
|
||
let adxcgRequestUrl = url.format({ | ||
protocol: secure ? 'https' : 'http', | ||
hostname: secure ? 'hbps.adxcg.net' : 'hbp.adxcg.net', | ||
pathname: '/get/adi', | ||
search: { | ||
renderformat: 'javascript', | ||
ver: 'r20171019PB10', | ||
adzoneid: adZoneIds.join(','), | ||
format: sizes.join(','), | ||
prebidBidIds: prebidBidIds.join(','), | ||
url: encodeURIComponent(url.format(requestUrl)), | ||
secure: secure ? '1' : '0', | ||
source: SOURCE, | ||
pbjs: '$prebid.version$' | ||
} | ||
}); | ||
|
||
bid.width = adxcgBidReponse.width; | ||
bid.height = adxcgBidReponse.height; | ||
return { | ||
method: 'GET', | ||
url: adxcgRequestUrl, | ||
}; | ||
}, | ||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {*} serverResponse A successful response from the server. | ||
* @return {bidRequests[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequests) { | ||
let bids = []; | ||
|
||
serverResponse = serverResponse.body; | ||
if (serverResponse) { | ||
serverResponse.forEach(serverResponseOneItem => { | ||
let bid = {}; | ||
|
||
bid.requestId = serverResponseOneItem.bidId; | ||
bid.cpm = serverResponseOneItem.cpm; | ||
bid.creativeId = parseInt(serverResponseOneItem.creativeId); | ||
bid.currency = 'USD'; | ||
bid.netRevenue = serverResponseOneItem.netRevenue ? serverResponseOneItem.netRevenue : true; | ||
bid.ttl = 300; | ||
|
||
if (serverResponseOneItem.deal_id != null && serverResponseOneItem.deal_id.trim().length > 0) { | ||
bid.dealId = serverResponseOneItem.deal_id; | ||
} | ||
|
||
utils.logMessage(`submitting bid[${bidRequest.placementCode}]: ${JSON.stringify(bid)}`); | ||
bidmanager.addBidResponse(bidRequest.placementCode, bid); | ||
}); | ||
if (serverResponseOneItem.ad) { | ||
bid.ad = serverResponseOneItem.ad; | ||
} else if (serverResponseOneItem.vastUrl) { | ||
bid.vastUrl = serverResponseOneItem.vastUrl; | ||
bid.descriptionUrl = serverResponseOneItem.vastUrl; | ||
bid.mediaType = 'video'; | ||
} else if (serverResponseOneItem.nativeResponse) { | ||
bid.mediaType = 'native'; | ||
|
||
let nativeResponse = serverResponseOneItem.nativeResponse; | ||
|
||
bid['native'] = { | ||
clickUrl: encodeURIComponent(nativeResponse.link.url), | ||
impressionTrackers: nativeResponse.imptrackers | ||
}; | ||
|
||
nativeResponse.assets.forEach(asset => { | ||
if (asset.title && asset.title.text) { | ||
bid['native'].title = asset.title.text; | ||
} | ||
|
||
if (asset.img && asset.img.url) { | ||
bid['native'].image = asset.img.url; | ||
} | ||
|
||
if (asset.data && asset.data.label === 'DESC' && asset.data.value) { | ||
bid['native'].body = asset.data.value; | ||
} | ||
|
||
if (asset.data && asset.data.label === 'SPONSORED' && asset.data.value) { | ||
bid['native'].sponsoredBy = asset.data.value; | ||
} | ||
}); | ||
} | ||
|
||
Object.keys(bidRequests) | ||
.map(bidId => bidRequests[bidId].placementCode) | ||
.forEach(placementCode => { | ||
utils.logMessage(`creating no_bid bid for: ${placementCode}`); | ||
bidmanager.addBidResponse(placementCode, bidfactory.createBid(STATUS.NO_BID)); | ||
bid.width = serverResponseOneItem.width; | ||
bid.height = serverResponseOneItem.height; | ||
utils.logMessage(`submitting bid[${serverResponseOneItem.bidId}]: ${JSON.stringify(bid)}`); | ||
bids.push(bid); | ||
}); | ||
}; | ||
|
||
return { | ||
callBids: _callBids | ||
}; | ||
} else { | ||
utils.logMessage(`empty bid response`); | ||
} | ||
return bids; | ||
}, | ||
getUserSyncs: function (syncOptions) { | ||
if (syncOptions.iframeEnabled) { | ||
return [{ | ||
type: 'iframe', | ||
url: '//cdn.adxcg.net/pb-sync.html' | ||
}]; | ||
} | ||
} | ||
}; | ||
|
||
adaptermanager.registerBidAdapter(new AdxcgAdapter(), 'adxcg', { | ||
supportedMediaTypes: ['video', 'native'] | ||
}); | ||
|
||
module.exports = AdxcgAdapter; | ||
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,50 @@ | ||
# Overview | ||
|
||
**Module Name**: Adxcg Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: info@adxcg.com | ||
|
||
# Description | ||
|
||
Module that connects to an Adxcg.com zone to fetch bids. | ||
|
||
# Test Parameters | ||
``` | ||
`` | ||
var adUnits = [{ | ||
code: 'banner-ad-div', | ||
sizes: [[300, 250]], | ||
bids: [{ | ||
bidder: 'adxcg', | ||
params: { | ||
adzoneid: '1' | ||
} | ||
}] | ||
},{ | ||
code: 'native-ad-div', | ||
sizes: [[300, 250], [1, 1]], | ||
nativeParams: { | ||
title: { required: true, len: 75 }, | ||
image: { required: true }, | ||
body: { len: 200 }, | ||
sponsoredBy: { len: 20 } | ||
}, | ||
bids: [{ | ||
bidder: 'adxcg', | ||
params: { | ||
adzoneid: '2379' | ||
} | ||
} | ||
}] | ||
},{ | ||
code: 'video', | ||
sizes: [[640, 480]], | ||
bids: [{ | ||
bidder: 'adxcg', | ||
params: { | ||
adzoneid: '20' | ||
} | ||
} | ||
}] | ||
}]; | ||
``` |
Oops, something went wrong.