forked from prebid/Prebid.js
-
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
Open
jhoshina
wants to merge
7
commits into
master
Choose a base branch
from
add-freakout-bid-adapter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e6568ba
Add new FreakOut bid adapter
jhoshina 041ff26
Merge remote-tracking branch 'origin/master' into add-freakout-bid-ad…
jhoshina 4929394
Add parameter ad_type
jhoshina 9a21efa
Merge remote-tracking branch 'origin/master' into add-freakout-bid-ad…
jhoshina aa3059e
tryAppendQueryString fix import path
jhoshina f376f06
Use ortb2Imp.ext.tid instead of transactionId
jhoshina 408a63e
Fix test
jhoshina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,179 @@ | ||
| import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
| import {isEmpty} from '../src/utils.js'; | ||
| import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; | ||
| import {config} from '../src/config.js'; | ||
| import {tryAppendQueryString} from '../libraries/urlUtils/urlUtils.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.ortb2Imp?.ext?.tid); | ||
| 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); | ||
This file contains hidden or 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,39 @@ | ||
| # Overview | ||
|
|
||
| ``` | ||
| Module Name: FreakOut Bid Adapter | ||
| Module Type: Bidder Adapter | ||
| Maintainer: rfp-tech@fout.jp | ||
| ``` | ||
|
|
||
| # 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', | ||
| ad_type: 14 | ||
| } | ||
| }] | ||
| } | ||
| ]; | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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