-
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
Platform.io Bidder Adapter update. Prebid v1.0. #1705
Merged
Merged
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2cc71fb
Add PlatformioBidAdapter
varashellov 6801ca1
Update platformioBidAdapter.js
varashellov 9bdcd7e
Add files via upload
varashellov 06c04ce
Update hello_world.html
varashellov 3e11a2a
Update platformioBidAdapter.js
varashellov e3d049e
Update platformioBidAdapter_spec.js
varashellov c09d8ae
Update hello_world.html
varashellov e0be49c
Update platformioBidAdapter_spec.js
varashellov eedbd3e
Update platformioBidAdapter.js
varashellov faa9963
Update hello_world.html
varashellov 946d081
Add files via upload
varashellov 69b4f57
Update platformioBidAdapter
varashellov 659562a
Update platformioBidAdapter
varashellov 66a3f7f
Update platformioBidAdapter
varashellov 225b798
Merge pull request #1 from varashellov/varashellov-patch-1
varashellov cd21b96
Add files via upload
varashellov e426d54
Add files via upload
varashellov 4ac6786
Add files via upload
varashellov 6cc3ec1
Merge branch 'master' into master
varashellov ccdfd49
Update platformioBidAdapter.js
varashellov 3947c83
Update platformioBidAdapter_spec.js
varashellov 6451e5b
Update platformioBidAdapter_spec.js
varashellov 9282871
Update platformioBidAdapter_spec.js
varashellov 7b60d11
Update platformioBidAdapter.js
varashellov 1124da8
Update platformioBidAdapter.js
varashellov 176c633
Update platformioBidAdapter_spec.js
varashellov 96245d6
Add files via upload
varashellov 380be34
Add files via upload
varashellov ffcfb29
Add files via upload
varashellov 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 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,63 +1,125 @@ | ||
var bidfactory = require('src/bidfactory.js'); | ||
var bidmanager = require('src/bidmanager.js'); | ||
var adloader = require('src/adloader.js'); | ||
var utils = require('src/utils.js'); | ||
var CONSTANTS = require('src/constants.json'); | ||
var adaptermanager = require('src/adaptermanager'); | ||
|
||
var PlatformIOAdapter = function PlatformIOAdapter() { | ||
function _callBids(params) { | ||
var bidURL; | ||
var bids = params.bids || []; | ||
var requestURL = window.location.protocol + '//js.adx1.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; | ||
import {logError, getTopWindowLocation} from 'src/utils'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
|
||
for (var i = 0; i < bids.length; i++) { | ||
var requestParams = {}; | ||
var bid = bids[i]; | ||
export const spec = { | ||
|
||
requestParams.pub_id = bid.params.pubId; | ||
requestParams.site_id = bid.params.siteId; | ||
requestParams.placement_id = bid.placementCode; | ||
code: 'platformio', | ||
|
||
var parseSized = utils.parseSizesInput(bid.sizes); | ||
var arrSize = parseSized[0].split('x'); | ||
|
||
requestParams.width = arrSize[0]; | ||
requestParams.height = arrSize[1]; | ||
requestParams.callback = '$$PREBID_GLOBAL$$._doPlatformIOCallback'; | ||
requestParams.callback_uid = bid.bidId; | ||
bidURL = requestURL + utils.parseQueryStringParameters(requestParams); | ||
|
||
utils.logMessage('PlatformIO.prebid, Bid ID: ' + bid.bidId + ', Pub ID: ' + bid.params.pubId); | ||
adloader.loadScript(bidURL); | ||
} | ||
isBidRequestValid: bid => ( | ||
!!(bid && bid.params && bid.params.pubId && bid.params.siteId) | ||
), | ||
buildRequests: bidRequests => { | ||
const request = { | ||
id: bidRequests[0].bidderRequestId, | ||
at: 2, | ||
imp: bidRequests.map(slot => impression(slot)), | ||
site: site(bidRequests), | ||
device: device(), | ||
}; | ||
return { | ||
method: 'POST', | ||
url: '//piohbdisp.hb.adx1.com/', | ||
data: JSON.stringify(request), | ||
}; | ||
}, | ||
interpretResponse: (response, request) => ( | ||
bidResponseAvailable(request, response) | ||
), | ||
}; | ||
function bidResponseAvailable(bidRequest, bidResponse) { | ||
const idToImpMap = {}; | ||
const idToBidMap = {}; | ||
const ortbRequest = parse(bidRequest.data); | ||
ortbRequest.imp.forEach(imp => { | ||
idToImpMap[imp.id] = imp; | ||
}); | ||
if (bidResponse) { | ||
bidResponse.seatbid.forEach(seatBid => seatBid.bid.forEach(bid => { | ||
idToBidMap[bid.impid] = bid; | ||
})); | ||
} | ||
|
||
$$PREBID_GLOBAL$$._doPlatformIOCallback = function (response) { | ||
var bidObject; | ||
var bidRequest; | ||
var callbackID; | ||
callbackID = response.callback_uid; | ||
bidRequest = utils.getBidRequest(callbackID); | ||
if (response.cpm > 0) { | ||
bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidRequest); | ||
bidObject.bidderCode = 'platformio'; | ||
bidObject.cpm = response.cpm; | ||
bidObject.ad = response.tag; | ||
bidObject.width = response.width; | ||
bidObject.height = response.height; | ||
} else { | ||
bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); | ||
bidObject.bidderCode = 'platformio'; | ||
utils.logMessage('No Bid response from Platformio request: ' + callbackID); | ||
const bids = []; | ||
Object.keys(idToImpMap).forEach(id => { | ||
if (idToBidMap[id]) { | ||
const bid = { | ||
requestId: id, | ||
cpm: idToBidMap[id].price, | ||
creative_id: id, | ||
creativeId: id, | ||
adId: id, | ||
}; | ||
bid.ad = idToBidMap[id].adm; | ||
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_IMP_ID(%7D|\})/gi, idToBidMap[id].impid); | ||
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_AD_ID(%7D|\})/gi, idToBidMap[id].adid); | ||
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_PRICE(%7D|\})/gi, idToBidMap[id].price); | ||
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_CURRENCY(%7D|\})/gi, bidResponse.cur); | ||
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_BID_ID(%7D|\})/gi, bidResponse.bidid); | ||
bid.width = idToImpMap[id].banner.w; | ||
bid.height = idToImpMap[id].banner.h; | ||
bids.push(bid); | ||
} | ||
bidmanager.addBidResponse(bidRequest.placementCode, bidObject); | ||
}); | ||
return bids; | ||
} | ||
function impression(slot) { | ||
return { | ||
id: slot.bidId, | ||
banner: banner(slot), | ||
bidfloor: '0.000001', | ||
tagid: slot.params.placementId.toString(), | ||
}; | ||
|
||
} | ||
function banner(slot) { | ||
const size = slot.params.size.toUpperCase().split('X'); | ||
const width = parseInt(size[0]); | ||
const height = parseInt(size[1]); | ||
return { | ||
callBids: _callBids | ||
w: width, | ||
h: height, | ||
}; | ||
}; | ||
adaptermanager.registerBidAdapter(new PlatformIOAdapter(), 'platformio'); | ||
} | ||
function site(bidderRequest) { | ||
const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0'; | ||
const siteId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.siteId : '0'; | ||
const appParams = bidderRequest[0].params.app; | ||
if (!appParams) { | ||
return { | ||
publisher: { | ||
id: pubId.toString(), | ||
domain: getTopWindowLocation().hostname, | ||
}, | ||
id: siteId.toString(), | ||
ref: referrer(), | ||
page: getTopWindowLocation().href, | ||
} | ||
} | ||
return null; | ||
} | ||
function referrer() { | ||
try { | ||
return window.top.document.referrer; | ||
} catch (e) { | ||
return document.referrer; | ||
} | ||
} | ||
function device() { | ||
return { | ||
ua: navigator.userAgent, | ||
language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), | ||
w: (window.screen.width || window.innerWidth), | ||
h: (window.screen.height || window.innerHeigh), | ||
}; | ||
} | ||
function parse(rawResponse) { | ||
try { | ||
if (rawResponse) { | ||
return JSON.parse(rawResponse); | ||
} | ||
} catch (ex) { | ||
logError('platformio.parse', 'ERROR', ex); | ||
} | ||
return null; | ||
} | ||
|
||
module.exports = PlatformIOAdapter; | ||
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,27 @@ | ||
# Overview | ||
|
||
**Module Name**: Platform.io Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: sk@ultralab.by | ||
|
||
# Description | ||
|
||
Connects to Platform.io demand source to fetch bids. | ||
Please use ```platformio``` as the bidder code. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
code: 'banner-ad-div', | ||
sizes: [[300, 250]], | ||
bids: [{ | ||
bidder: 'platformio', | ||
params: { | ||
pubId: '28082', | ||
siteId: '26047', | ||
placementId: '123', | ||
size: '250X250' | ||
} | ||
}] | ||
}]; | ||
``` |
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.
Preferable to start files with content rather than a blank line, line can be removed