-
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.
Merge branch 'master' of github.com:prebid/Prebid.js
- Loading branch information
Showing
77 changed files
with
4,089 additions
and
556 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
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 * as utils from '../src/utils'; | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = '7xbid'; | ||
const BIDDER_ALIAS = '7xb'; | ||
const ENDPOINT_BANNER = '//bidder.7xbid.com/api/v1/prebid/banner'; | ||
const ENDPOINT_NATIVE = '//bidder.7xbid.com/api/v1/prebid/native'; | ||
const COOKIE_SYNC_URL = '//bidder.7xbid.com/api/v1/cookie/gen'; | ||
const SUPPORTED_MEDIA_TYPES = ['banner', 'native']; | ||
const SUPPORTED_CURRENCIES = ['USD', 'JPY']; | ||
const DEFAULT_CURRENCY = 'JPY'; | ||
const NET_REVENUE = true; | ||
|
||
const _encodeURIComponent = function(a) { | ||
let b = window.encodeURIComponent(a); | ||
b = b.replace(/'/g, '%27'); | ||
return b; | ||
} | ||
|
||
export const _getUrlVars = function(url) { | ||
var hash; | ||
var myJson = {}; | ||
var hashes = url.slice(url.indexOf('?') + 1).split('&'); | ||
for (var i = 0; i < hashes.length; i++) { | ||
hash = hashes[i].split('='); | ||
myJson[hash[0]] = hash[1]; | ||
} | ||
return myJson; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: [BIDDER_ALIAS], // short code | ||
supportedMediaTypes: SUPPORTED_MEDIA_TYPES, | ||
isBidRequestValid: function(bid) { | ||
if (!(bid.params.placementId)) { | ||
return false; | ||
} | ||
|
||
if (bid.params.hasOwnProperty('currency') && | ||
SUPPORTED_CURRENCIES.indexOf(bid.params.currency) === -1) { | ||
utils.logInfo('Invalid currency type, we support only JPY and USD!') | ||
return false; | ||
} | ||
|
||
return true; | ||
}, | ||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {validBidRequests[]} - an array of bids | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function(validBidRequests, bidderRequest) { | ||
let serverRequests = []; | ||
var refererInfo; | ||
if (bidderRequest && bidderRequest.refererInfo) { | ||
refererInfo = bidderRequest.refererInfo; | ||
} | ||
validBidRequests.forEach((bid, i) => { | ||
let endpoint = ENDPOINT_BANNER | ||
let data = { | ||
'placementid': bid.params.placementId, | ||
'cur': bid.params.hasOwnProperty('currency') ? bid.params.currency : DEFAULT_CURRENCY, | ||
'ua': navigator.userAgent, | ||
'loc': utils.getTopWindowUrl(), | ||
'topframe': (window.parent === window.self) ? 1 : 0, | ||
'sw': screen && screen.width, | ||
'sh': screen && screen.height, | ||
'cb': Math.floor(Math.random() * 99999999999), | ||
'tpaf': 1, | ||
'cks': 1, | ||
'requestid': bid.bidId | ||
}; | ||
|
||
if (bid.hasOwnProperty('nativeParams')) { | ||
endpoint = ENDPOINT_NATIVE | ||
data.tkf = 1 // return url tracker | ||
data.ad_track = '1' | ||
data.apiv = '1.1.0' | ||
} | ||
|
||
if (refererInfo && refererInfo.referer) { | ||
data.referer = refererInfo.referer; | ||
} else { | ||
data.referer = ''; | ||
} | ||
|
||
serverRequests.push({ | ||
method: 'GET', | ||
url: endpoint, | ||
data: utils.parseQueryStringParameters(data) | ||
}) | ||
}) | ||
|
||
return serverRequests; | ||
}, | ||
interpretResponse: function(serverResponse, request) { | ||
const data = _getUrlVars(request.data) | ||
const successBid = serverResponse.body || {}; | ||
let bidResponses = []; | ||
if (successBid.hasOwnProperty(data.placementid)) { | ||
let bid = successBid[data.placementid] | ||
let bidResponse = { | ||
requestId: bid.requestid, | ||
cpm: bid.price, | ||
creativeId: bid.creativeId, | ||
currency: bid.cur, | ||
netRevenue: NET_REVENUE, | ||
ttl: 700 | ||
}; | ||
|
||
if (bid.hasOwnProperty('title')) { // it is native ad response | ||
bidResponse.mediaType = 'native' | ||
bidResponse.native = { | ||
title: bid.title, | ||
body: bid.description, | ||
cta: bid.cta, | ||
sponsoredBy: bid.advertiser, | ||
clickUrl: _encodeURIComponent(bid.landingURL), | ||
impressionTrackers: bid.trackings, | ||
} | ||
if (bid.screenshots) { | ||
bidResponse.native.image = { | ||
url: bid.screenshots.url, | ||
height: bid.screenshots.height, | ||
width: bid.screenshots.width, | ||
} | ||
} | ||
if (bid.icon) { | ||
bidResponse.native.icon = { | ||
url: bid.icon.url, | ||
height: bid.icon.height, | ||
width: bid.icon.width, | ||
} | ||
} | ||
} else { | ||
bidResponse.ad = bid.adm | ||
bidResponse.width = bid.width | ||
bidResponse.height = bid.height | ||
} | ||
|
||
bidResponses.push(bidResponse); | ||
} | ||
|
||
return bidResponses; | ||
}, | ||
getUserSyncs: function(syncOptions, serverResponses) { | ||
return [{ | ||
type: 'image', | ||
url: COOKIE_SYNC_URL | ||
}]; | ||
} | ||
} | ||
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,60 @@ | ||
# Overview | ||
|
||
Module Name: 7xbid Bid Adapter | ||
|
||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Module that connects to 7xbid's demand sources | ||
|
||
# Test Parameters | ||
```javascript | ||
var adUnits = [ | ||
{ | ||
code: 'test', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250], [300,600]], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: '7xbid', | ||
params: { | ||
placementId: 1425292, | ||
currency: 'USD' | ||
|
||
} | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'test', | ||
mediaTypes: { | ||
native: { | ||
title: { | ||
required: true, | ||
len: 80 | ||
}, | ||
image: { | ||
required: true, | ||
sizes: [150, 50] | ||
}, | ||
sponsoredBy: { | ||
required: true | ||
} | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: '7xbid', | ||
params: { | ||
placementId: 1429695, | ||
currency: 'USD' | ||
} | ||
}, | ||
], | ||
} | ||
]; | ||
``` |
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,93 @@ | ||
import * as utils from '../src/utils'; | ||
import {config} from '../src/config'; | ||
import {registerBidder} from '../src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'ablida'; | ||
const ENDPOINT_URL = 'https://bidder.ablida.net/prebid'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {BidRequest} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: function (bid) { | ||
return !!(bid.params.placementId); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @return Array Info describing the request to the server. | ||
* @param validBidRequests | ||
* @param bidderRequest | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
if (validBidRequests.length === 0) { | ||
return []; | ||
} | ||
return validBidRequests.map(bidRequest => { | ||
const sizes = utils.parseSizesInput(bidRequest.sizes)[0]; | ||
const size = sizes.split('x'); | ||
const jaySupported = 'atob' in window && 'currentScript' in document; | ||
const device = getDevice(); | ||
const payload = { | ||
placementId: bidRequest.params.placementId, | ||
width: size[0], | ||
height: size[1], | ||
bidId: bidRequest.bidId, | ||
categories: bidRequest.params.categories, | ||
referer: bidderRequest.refererInfo.referer, | ||
jaySupported: jaySupported, | ||
device: device | ||
}; | ||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: payload | ||
}; | ||
}); | ||
}, | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @param bidRequest | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
const bidResponses = []; | ||
const response = serverResponse.body; | ||
|
||
response.forEach(function(bid) { | ||
bid.ttl = config.getConfig('_bidderTimeout'); | ||
bidResponses.push(bid); | ||
}); | ||
return bidResponses; | ||
}, | ||
}; | ||
|
||
function getDevice() { | ||
const ua = navigator.userAgent; | ||
const topWindow = window.top; | ||
if ((/(ipad|xoom|sch-i800|playbook|silk|tablet|kindle)|(android(?!.*mobi))/i).test(ua)) { | ||
return 'tablet'; | ||
} | ||
if ((/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(ua)) { | ||
return 'connectedtv'; | ||
} | ||
if ((/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Windows\sCE|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/i).test(ua)) { | ||
return 'smartphone'; | ||
} | ||
const width = topWindow.innerWidth || topWindow.document.documentElement.clientWidth || topWindow.document.body.clientWidth; | ||
if (width > 320) { | ||
return 'desktop'; | ||
} | ||
return 'other'; | ||
} | ||
|
||
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,32 @@ | ||
# Overview | ||
|
||
**Module Name**: Ablida Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: [email protected] | ||
|
||
# Description | ||
|
||
Module that connects to Ablida's bidder for bids. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'ad-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'ablida', | ||
params: { | ||
placementId: 'mediumrectangle-demo', | ||
categories: ['automotive', 'news-and-politics'] // optional: categories of page | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
Oops, something went wrong.