-
Notifications
You must be signed in to change notification settings - Fork 0
FreakOut Bid Adapter: add new bid adapter #1
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
e6568ba
041ff26
4929394
9a21efa
aa3059e
f376f06
408a63e
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,178 @@ | ||
import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
import {tryAppendQueryString, isEmpty} from '../src/utils.js'; | ||
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; | ||
import {config} from '../src/config.js'; | ||
|
||
const BIDDER_CODE = 'freakout'; | ||
const ENDPOINT = 'https://ad.rfp.fout.jp/ad'; | ||
const ADAPTER_VERSION = '1.0.0'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER, VIDEO, NATIVE], | ||
|
||
/** | ||
* Determines whether 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.adspot_id); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {BidRequest[]} validBidRequests - an array of bids | ||
* @param {*} bidderRequest | ||
* @return {ServerRequest[]} Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
const serverRequests = []; | ||
|
||
let endpointUrl = config.getConfig(`${BIDDER_CODE}.endpoint_url`); | ||
|
||
for (let i = 0; i < validBidRequests.length; i++) { | ||
const req = validBidRequests[i]; | ||
|
||
let query = ''; | ||
query = tryAppendQueryString(query, 'adspot_id', req.params.adspot_id); | ||
query = tryAppendQueryString(query, 'ad_type', req.params.ad_type); | ||
query = tryAppendQueryString(query, 'media_url', bidderRequest.refererInfo.referer); | ||
query = tryAppendQueryString(query, 'hb', 'prebidjs'); | ||
query = tryAppendQueryString(query, 'pb_ver', '$prebid.version$'); | ||
query = tryAppendQueryString(query, 'pb_adapter_ver', ADAPTER_VERSION); | ||
query = tryAppendQueryString(query, 'pb_tid', req.transactionId); | ||
query = tryAppendQueryString(query, 'pb_bid', req.bidId); | ||
query = tryAppendQueryString(query, 'cur', getCurrency()); | ||
query = tryAppendQueryString(query, 'sizes', getSizes(req)); | ||
|
||
serverRequests.push({ | ||
method: 'GET', | ||
url: endpointUrl || ENDPOINT, | ||
data: query, | ||
adspotId: req.params.adspot_id | ||
}); | ||
} | ||
|
||
return serverRequests; | ||
}, | ||
|
||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @param {ServerRequest} serverRequest | ||
* @return {Array<Object>} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, serverRequest) { | ||
const body = serverResponse.body; | ||
if (isEmpty(body)) { | ||
return []; | ||
} | ||
|
||
const adspotId = serverRequest.adspotId; | ||
|
||
const ad = body.items[0]; | ||
const creative = makeCreative(adspotId, body); | ||
|
||
const bid = { | ||
requestId: ad.pb_bid, | ||
cpm: Number(ad.cpm), | ||
currency: ad.cur, | ||
width: Number(ad.creative_width), | ||
height: Number(ad.creative_height), | ||
ad: creative, | ||
ttl: Number(ad.ttl) || 300, | ||
creativeId: ad.creative_id, | ||
netRevenue: true, | ||
}; | ||
if (ad.vast_xml) { | ||
bid.vastXml = ad.vast_xml; | ||
} | ||
|
||
return [bid]; | ||
}, | ||
|
||
/** | ||
* Register the user sync pixels which should be dropped after the auction. | ||
* | ||
* @param {SyncOptions} syncOptions Which user syncs are allowed? | ||
* @param {ServerResponse[]} serverResponses List of server's responses. | ||
* @return {UserSync[]} The user syncs which should be dropped. | ||
*/ | ||
getUserSyncs: function (syncOptions, serverResponses) { | ||
const syncs = []; | ||
|
||
if (serverResponses.length === 0) { | ||
return syncs; | ||
} | ||
|
||
serverResponses.forEach(res => { | ||
const body = res.body; | ||
if (syncOptions.pixelEnabled && Array.isArray(body.sync_urls)) { | ||
body.sync_urls.forEach(url => { | ||
syncs.push({ | ||
type: 'image', | ||
url: url | ||
}) | ||
}); | ||
} | ||
if (syncOptions.iframeEnabled && Array.isArray(body.sync_iframe_urls)) { | ||
body.sync_iframe_urls.forEach(url => { | ||
syncs.push({ | ||
type: 'iframe', | ||
url: url | ||
}) | ||
}); | ||
} | ||
}); | ||
|
||
return syncs; | ||
} | ||
}; | ||
|
||
/** | ||
* @param {BidRequest} req | ||
* @return {string|null} | ||
*/ | ||
function getSizes(req) { | ||
/** @type {string[][]|undefined} */ | ||
const sizes = req.sizes; | ||
if (!sizes || sizes.length < 1) return null; | ||
return sizes.filter(x => x.length === 2) | ||
.map(x => `${x[0]}x${x[1]}`) | ||
.join(','); | ||
} | ||
|
||
/** | ||
* @return {string} USD or JPY | ||
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. [MEMO]
|
||
*/ | ||
function getCurrency() { | ||
if (config.getConfig('currency.adServerCurrency') && | ||
config.getConfig('currency.adServerCurrency').toUpperCase() === 'USD') { | ||
return 'USD'; | ||
} | ||
return 'JPY'; | ||
} | ||
|
||
/** | ||
* @param {string} adspotId | ||
* @param {*} body | ||
*/ | ||
function makeCreative(adspotId, body) { | ||
return `<div><ins data-rfp-display-adspot-id="${adspotId}"></ins></div>` + | ||
`<script id="rfp-ad-response-${adspotId}" type="application/json">${safeJSONString(JSON.stringify(body))}</script>` + | ||
`<script src="https://js.rfp.fout.jp/rfp-display.js"></script>` + | ||
`<script>RFP.Display.Default.lazyLoading(document.querySelector("[data-rfp-display-adspot-id=${adspotId}]").parentElement, {offline:true})</script>`; | ||
} | ||
|
||
function safeJSONString(s) { | ||
return s.replace(/&/g, '\\u0026') | ||
.replace(/>/g, '\\u003e') | ||
.replace(/</g, '\\u003c') | ||
.replace(/'/g, '\\u0027'); | ||
} | ||
|
||
registerBidder(spec); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: FreakOut Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Connects to FreakOut exchange for bids. | ||
|
||
FreakOut bid adapter supports Banner. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
// Banner adUnit | ||
{ | ||
code: 'test-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [ | ||
[300, 250], | ||
[320, 50], | ||
[320, 100] | ||
] | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'freakout', | ||
params: { | ||
adspot_id: 'NDgxOjUx' | ||
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. [IMO]
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. 4929394 にてドキュメントとテスト用のファイルに追加しました。 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. 引き続きLGTMです 👍 |
||
} | ||
}] | ||
} | ||
]; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import {spec} from 'modules/freakoutBidAdapter.js'; | ||
import {newBidder} from 'src/adapters/bidderFactory.js'; | ||
import prebid from '../../../package.json'; | ||
|
||
const ENDPOINT = 'https://ad.rfp.fout.jp/ad'; | ||
const ADAPTER_VERSION = '1.0.0'; | ||
|
||
describe('FreakOutAdapter', function () { | ||
const adapter = newBidder(spec); | ||
|
||
describe('inherited functions', function () { | ||
it('exists and is a function', function () { | ||
expect(adapter.callBids).to.exist.and.to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('isBidRequestValid', function () { | ||
let bid = { | ||
bidder: 'freakout', | ||
params: { | ||
adspot_id: 'ABCD1234' | ||
} | ||
}; | ||
|
||
it('should return true when required params found', function () { | ||
expect(spec.isBidRequestValid(bid)).to.be.true; | ||
}); | ||
|
||
it('should return false when required params are not passed', function () { | ||
let bid = Object.assign({}, bid); | ||
delete bid.params; | ||
bid.params = {}; | ||
expect(spec.isBidRequestValid(bid)).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
const bidRequests = [ | ||
{ | ||
bidder: 'freakout', | ||
params: { | ||
adspot_id: 'ABCD1234' | ||
}, | ||
adUnitCode: 'adunit-code', | ||
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. [q]
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.
|
||
sizes: [ | ||
[300, 250], | ||
[320, 50], | ||
[320, 100], | ||
], | ||
bidId: '2b84475b5b636e', | ||
bidderRequestId: '1f4001782ac16c', | ||
auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', | ||
transactionId: '791e9d84-af92-4903-94da-24c7426d9d0c' | ||
}, | ||
]; | ||
|
||
it('sends bid request to ENDPOINT via GET', function () { | ||
const bidderRequest = { | ||
refererInfo: { | ||
referer: 'https://example.com', | ||
}, | ||
}; | ||
|
||
const requests = spec.buildRequests(bidRequests, bidderRequest); | ||
expect(requests[0].url).to.equal(ENDPOINT); | ||
expect(requests[0].method).to.equal('GET'); | ||
expect(requests[0].data).to.equal(`adspot_id=ABCD1234&media_url=https%3A%2F%2Fexample.com&hb=prebidjs&pb_ver=${prebid.version}&pb_adapter_ver=${ADAPTER_VERSION}&pb_tid=791e9d84-af92-4903-94da-24c7426d9d0c&pb_bid=2b84475b5b636e&cur=JPY&sizes=300x250%2C320x50%2C320x100&`); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
const bidderRequests = [ | ||
{ | ||
bidder: 'freakout', | ||
params: { | ||
adspot_id: 'ABCD1234', | ||
}, | ||
adUnitCode: 'adunit-code', | ||
sizes: [ | ||
[300, 250], | ||
[320, 50], | ||
[320, 100], | ||
], | ||
bidId: '2b84475b5b636e', | ||
bidderRequestId: '1f4001782ac16c', | ||
auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', | ||
transactionId: '791e9d84-af92-4903-94da-24c7426d9d0c', | ||
} | ||
]; | ||
|
||
it('should get correct banner bid response', function () { | ||
const response = { | ||
sync_urls: [ | ||
'https://sync.example.com/1.html', | ||
'https://sync.example.com/2.html', | ||
], | ||
sync_iframe_urls: [ | ||
'https://sync.example.com/3.html', | ||
'https://sync.example.com/4.html', | ||
], | ||
items: [ | ||
{ | ||
creative_id: 'creative-1', | ||
creative_html: '<div></div>', | ||
creative_width: '300', | ||
creative_height: '250', | ||
ttl: 200, | ||
cpm: 30, | ||
cur: 'JPY', | ||
pb_bid: '2b84475b5b636e', | ||
}, | ||
], | ||
}; | ||
|
||
const expectedResponse = { | ||
// ad: '<div></div>', | ||
cpm: 30, | ||
creativeId: 'creative-1', | ||
currency: 'JPY', | ||
height: 250, | ||
netRevenue: true, | ||
requestId: '2b84475b5b636e', | ||
ttl: 200, | ||
width: 300, | ||
}; | ||
|
||
const result = spec.interpretResponse({body: response}, bidderRequests); | ||
expect(result).to.have.lengthOf(1); | ||
expect(result[0]).to.include(expectedResponse); | ||
expect(result[0].ad).to.be.a('string'); | ||
}); | ||
|
||
it('handles no bid responses', function () { | ||
const response = ''; | ||
|
||
const result = spec.interpretResponse({body: response}, bidderRequests); | ||
expect(result).to.have.lengthOf(0); | ||
}); | ||
}); | ||
|
||
describe('getUserSyncs', function () { | ||
const bidResponse = { | ||
body: { | ||
sync_urls: [ | ||
'https://sync1.example.com', | ||
'https://sync2.example.com', | ||
], | ||
sync_iframe_urls: [ | ||
'https://sync3.example.com', | ||
'https://sync4.example.com', | ||
], | ||
}, | ||
}; | ||
|
||
it('should return pixel syncs', function () { | ||
const syncs = spec.getUserSyncs({pixelEnabled: true, iframeEnabled: true}, [bidResponse]); | ||
expect(syncs).to.deep.equal([ | ||
{ | ||
type: 'image', | ||
url: 'https://sync1.example.com', | ||
}, | ||
{ | ||
type: 'image', | ||
url: 'https://sync2.example.com', | ||
}, | ||
{ | ||
type: 'iframe', | ||
url: 'https://sync3.example.com', | ||
}, | ||
{ | ||
type: 'iframe', | ||
url: 'https://sync4.example.com', | ||
}, | ||
]); | ||
}); | ||
}) | ||
}); |
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.
[q]
sync_script_urls
の対応は不要なのでしょうか?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.
script urlを挿入してのSyncはサポートされていないため行っていません。
参考: Registering User Syncs