-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
7xbid adapter #4328
7xbid adapter #4328
Changes from all 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 |
---|---|---|
@@ -0,0 +1,157 @@ | ||
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; | ||
} | ||
var g = (typeof (geparams) !== 'undefined' && typeof (geparams) == 'object' && geparams) ? geparams : {}; | ||
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, | ||
'adtk': _encodeURIComponent(g.lat ? '0' : '1'), | ||
'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({ | ||
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. There was a push to have all adapters support SRA (Single Request Architecture). I am unsure if this is till a requirement for new / existing adapters, so I have contacted the rest of the Prebid.org team and asked. I will get back to you as soon as I get an answer, but wanted to give you a heads up! 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. Ok got an answer and we will not require it. That change would have comms ahead of time and we would make it known to all adapters which need to be updated well ahead of time! |
||
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 | ||
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. Guessing you trust that your ad server will only respond with native if the request was native, so no check needed for the bidRequest being native 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. only native bid response has |
||
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); |
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' | ||
} | ||
}, | ||
], | ||
} | ||
]; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import {expect} from 'chai'; | ||
import {spec, _getUrlVars} from 'modules/7xbidBidAdapter'; | ||
import * as utils from 'src/utils'; | ||
import {config} from 'src/config'; | ||
|
||
const BASE_URI = '//bidder.7xbid.com/api/v1/prebid/banner' | ||
const NATIVE_BASE_URI = '//bidder.7xbid.com/api/v1/prebid/native' | ||
|
||
describe('7xbid adapter', function() { | ||
let bidRequests; | ||
let nativeBidRequests; | ||
|
||
beforeEach(function() { | ||
bidRequests = [ | ||
{ | ||
bidder: '7xbid', | ||
params: { | ||
placementId: 1425292, | ||
currency: 'USD' | ||
} | ||
} | ||
] | ||
|
||
nativeBidRequests = [ | ||
{ | ||
bidder: '7xbid', | ||
params: { | ||
placementId: 1429695, | ||
currency: 'USD' | ||
}, | ||
nativeParams: { | ||
title: { | ||
required: true, | ||
len: 80 | ||
}, | ||
image: { | ||
required: true, | ||
sizes: [150, 50] | ||
}, | ||
sponsoredBy: { | ||
required: true | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
describe('isBidRequestValid', function () { | ||
it('valid bid case', function () { | ||
let validBid = { | ||
bidder: '7xbid', | ||
params: { | ||
placementId: 1425292, | ||
currency: 'USD' | ||
} | ||
} | ||
let isValid = spec.isBidRequestValid(validBid); | ||
expect(isValid).to.equal(true); | ||
}); | ||
|
||
it('invalid bid case: placementId is not passed', function() { | ||
let validBid = { | ||
bidder: '7xbid', | ||
params: { | ||
} | ||
} | ||
let isValid = spec.isBidRequestValid(validBid); | ||
expect(isValid).to.equal(false); | ||
}) | ||
|
||
it('invalid bid case: currency is not support', function() { | ||
let validBid = { | ||
bidder: '7xbid', | ||
params: { | ||
placementId: 1108295, | ||
currency: 'AUD' | ||
} | ||
} | ||
let isValid = spec.isBidRequestValid(validBid); | ||
expect(isValid).to.equal(false); | ||
}) | ||
}) | ||
|
||
describe('buildRequests', function () { | ||
it('sends bid request to ENDPOINT via GET', function () { | ||
const request = spec.buildRequests(bidRequests)[0]; | ||
expect(request.url).to.equal(BASE_URI); | ||
expect(request.method).to.equal('GET'); | ||
}); | ||
|
||
it('sends native bid request to ENDPOINT via GET', function () { | ||
const request = spec.buildRequests(nativeBidRequests)[0]; | ||
expect(request.url).to.equal(NATIVE_BASE_URI); | ||
expect(request.method).to.equal('GET'); | ||
}); | ||
|
||
it('buildRequests function should not modify original bidRequests object', function () { | ||
let originalBidRequests = utils.deepClone(bidRequests); | ||
let request = spec.buildRequests(bidRequests); | ||
expect(bidRequests).to.deep.equal(originalBidRequests); | ||
}); | ||
|
||
it('buildRequests function should not modify original nativeBidRequests object', function () { | ||
let originalBidRequests = utils.deepClone(nativeBidRequests); | ||
let request = spec.buildRequests(nativeBidRequests); | ||
expect(nativeBidRequests).to.deep.equal(originalBidRequests); | ||
}); | ||
|
||
it('Request params check', function() { | ||
let request = spec.buildRequests(bidRequests)[0]; | ||
const data = _getUrlVars(request.data) | ||
expect(parseInt(data.placementid)).to.exist.and.to.equal(bidRequests[0].params.placementId); | ||
expect(data.cur).to.exist.and.to.equal(bidRequests[0].params.currency); | ||
}) | ||
|
||
it('Native request params check', function() { | ||
let request = spec.buildRequests(nativeBidRequests)[0]; | ||
const data = _getUrlVars(request.data) | ||
expect(parseInt(data.placementid)).to.exist.and.to.equal(nativeBidRequests[0].params.placementId); | ||
expect(data.cur).to.exist.and.to.equal(nativeBidRequests[0].params.currency); | ||
}) | ||
}) | ||
|
||
describe('interpretResponse', function () { | ||
let response = { | ||
1425292: | ||
{ | ||
'creativeId': '<!-- CREATIVE ID -->', | ||
'cur': 'USD', | ||
'price': 0.0920, | ||
'width': 300, | ||
'height': 250, | ||
'requestid': '2e42361a6172bf', | ||
'adm': '<!-- ADS TAG -->' | ||
} | ||
} | ||
|
||
it('should get correct bid response', function () { | ||
let expectedResponse = [ | ||
{ | ||
'requestId': '2e42361a6172bf', | ||
'cpm': 0.0920, | ||
'width': 300, | ||
'height': 250, | ||
'netRevenue': true, | ||
'currency': 'USD', | ||
'creativeId': '<!-- CREATIVE ID -->', | ||
'ttl': 700, | ||
'ad': '<!-- ADS TAG -->' | ||
} | ||
]; | ||
let request = spec.buildRequests(bidRequests)[0]; | ||
let result = spec.interpretResponse({body: response}, request); | ||
expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); | ||
expect(result[0].cpm).to.not.equal(null); | ||
expect(result[0].creativeId).to.not.equal(null); | ||
expect(result[0].ad).to.not.equal(null); | ||
expect(result[0].currency).to.equal('USD'); | ||
expect(result[0].netRevenue).to.equal(true); | ||
}); | ||
}) | ||
}) |
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.
Where is
geparams
coming from?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.
sorry we dont need this anymore, I will make other PR to remove this