-
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
Fidelity Media Adapter update. Prebid v1.0 #1719
Changes from 2 commits
43d2ca9
563d8e1
58012ac
32904c4
aeb7b13
b009b16
9204c35
c1ef347
3a901ff
7ad9f4d
6497042
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 |
---|---|---|
@@ -1,102 +1,85 @@ | ||
var utils = require('src/utils.js'); | ||
var bidfactory = require('src/bidfactory.js'); | ||
var bidmanager = require('src/bidmanager.js'); | ||
var adloader = require('src/adloader'); | ||
var STATUS = require('src/constants').STATUS; | ||
var adaptermanager = require('src/adaptermanager'); | ||
import * as utils from 'src/utils'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'fidelity'; | ||
const BIDDER_SERVER = 'x.fidelity-media.com'; | ||
export const spec = { | ||
code: BIDDER_CODE, | ||
isBidRequestValid: function(bid) { | ||
return !!(bid && bid.params && bid.params.zoneid); | ||
}, | ||
buildRequests: function(validBidRequests, bidderRequest) { | ||
return validBidRequests.map(bidRequest => { | ||
var server = bidRequest.params.server || BIDDER_SERVER; | ||
|
||
var FidelityAdapter = function FidelityAdapter() { | ||
var FIDELITY_BIDDER_NAME = 'fidelity'; | ||
var FIDELITY_SERVER_NAME = 'x.fidelity-media.com'; | ||
const payload = { | ||
from: 'hb', | ||
v: '1.0', | ||
requestid: bidRequest.bidderRequestId, | ||
impid: bidRequest.bidId, | ||
zoneid: bidRequest.params.zoneid, | ||
floor: parseFloat(bidRequest.params.floor) > 0 ? bidRequest.params.floor : 0, | ||
charset: document.charSet || document.characterSet, | ||
defloc: utils.getTopWindowUrl(), | ||
altloc: window.location.href, | ||
subid: 'hb', | ||
flashver: getFlashVersion(), | ||
tmax: bidderRequest.timeout, | ||
}; | ||
if (document.referrer) { | ||
payload.referrer = document.referrer; | ||
} | ||
|
||
function _callBids(params) { | ||
var bids = params.bids || []; | ||
bids.forEach(function (currentBid) { | ||
var server = currentBid.params.server || FIDELITY_SERVER_NAME; | ||
var m3_u = window.location.protocol + '//' + server + '/delivery/hb.php?'; | ||
m3_u += 'callback=window.$$PREBID_GLOBAL$$.fidelityResponse'; | ||
m3_u += '&requestid=' + utils.getUniqueIdentifierStr(); | ||
m3_u += '&impid=' + currentBid.bidId; | ||
m3_u += '&zoneid=' + currentBid.params.zoneid; | ||
m3_u += '&cb=' + Math.floor(Math.random() * 99999999999); | ||
m3_u += document.charset ? '&charset=' + document.charset : (document.characterSet ? '&charset=' + document.characterSet : ''); | ||
|
||
var loc; | ||
try { | ||
loc = window.top !== window ? document.referrer : window.location.href; | ||
} catch (e) { | ||
loc = document.referrer; | ||
} | ||
loc = currentBid.params.loc || loc; | ||
m3_u += '&loc=' + encodeURIComponent(loc); | ||
|
||
var subid = currentBid.params.subid || 'hb'; | ||
m3_u += '&subid=' + subid; | ||
if (document.referrer) m3_u += '&referer=' + encodeURIComponent(document.referrer); | ||
if (currentBid.params.click) m3_u += '&ct0=' + encodeURIComponent(currentBid.params.click); | ||
m3_u += '&flashver=' + encodeURIComponent(getFlashVersion()); | ||
|
||
adloader.loadScript(m3_u); | ||
return { | ||
method: 'GET', | ||
url: '//' + server + '/delivery/hb.php', | ||
data: payload | ||
}; | ||
}); | ||
} | ||
}, | ||
interpretResponse: function(serverResponse) { | ||
const bidResponses = []; | ||
if (serverResponse && serverResponse.seatbid) { | ||
serverResponse.seatbid.forEach(seatBid => seatBid.bid.forEach(bid => { | ||
const bidResponse = { | ||
bidderCode: spec.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. Hey, I made some last minute changes to adapter aliasing, and our docs are out of date... but could you remove this Thanks 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. Also add 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, we'll do both. I'll upload new code ASAP. 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. @dbemiller @jaiminpanchal27 These updates are done, take a look at result. |
||
requestId: bid.impid, | ||
cpm: bid.price, | ||
width: bid.width, | ||
height: bid.height, | ||
ad: bid.adm, | ||
netRevenue: bid.netRevenue, | ||
currency: bid.cur, | ||
}; | ||
|
||
function getFlashVersion() { | ||
var plugins, plugin, result; | ||
|
||
if (navigator.plugins && navigator.plugins.length > 0) { | ||
plugins = navigator.plugins; | ||
for (var i = 0; i < plugins.length && !result; i++) { | ||
plugin = plugins[i]; | ||
if (plugin.name.indexOf('Shockwave Flash') > -1) { | ||
result = plugin.description.split('Shockwave Flash ')[1]; | ||
} | ||
} | ||
bidResponses.push(bidResponse); | ||
})); | ||
} | ||
return result || ''; | ||
} | ||
|
||
function addBlankBidResponses(placementsWithBidsBack) { | ||
var allFidelityBidRequests = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === FIDELITY_BIDDER_NAME); | ||
|
||
if (allFidelityBidRequests && allFidelityBidRequests.bids) { | ||
utils._each(allFidelityBidRequests.bids, function (fidelityBid) { | ||
if (!utils.contains(placementsWithBidsBack, fidelityBid.placementCode)) { | ||
// Add a no-bid response for this placement. | ||
var bid = bidfactory.createBid(STATUS.NO_BID, fidelityBid); | ||
bid.bidderCode = FIDELITY_BIDDER_NAME; | ||
bidmanager.addBidResponse(fidelityBid.placementCode, bid); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
$$PREBID_GLOBAL$$.fidelityResponse = function(responseObj) { | ||
if (!responseObj || !responseObj.seatbid || responseObj.seatbid.length === 0 || !responseObj.seatbid[0].bid || responseObj.seatbid[0].bid.length === 0) { | ||
addBlankBidResponses([]); | ||
return; | ||
return bidResponses; | ||
}, | ||
getUserSyncs: function getUserSyncs(syncOptions) { | ||
if (syncOptions.iframeEnabled) { | ||
return [{ | ||
type: 'iframe', | ||
url: '//' + BIDDER_SERVER + '/delivery/matches.php?type=iframe', | ||
}]; | ||
} | ||
} | ||
} | ||
|
||
function getFlashVersion() { | ||
var plugins, plugin, result; | ||
|
||
var bid = responseObj.seatbid[0].bid[0]; | ||
var status = bid.adm ? STATUS.GOOD : STATUS.NO_BID; | ||
var requestObj = utils.getBidRequest(bid.impid); | ||
|
||
var bidResponse = bidfactory.createBid(status); | ||
bidResponse.bidderCode = FIDELITY_BIDDER_NAME; | ||
if (status === STATUS.GOOD) { | ||
bidResponse.cpm = parseFloat(bid.price); | ||
bidResponse.ad = bid.adm; | ||
bidResponse.width = parseInt(bid.width); | ||
bidResponse.height = parseInt(bid.height); | ||
if (navigator.plugins && navigator.plugins.length > 0) { | ||
plugins = navigator.plugins; | ||
for (var i = 0; i < plugins.length && !result; i++) { | ||
plugin = plugins[i]; | ||
if (plugin.name.indexOf('Shockwave Flash') > -1) { | ||
result = plugin.description.split('Shockwave Flash ')[1]; | ||
} | ||
} | ||
var placementCode = requestObj && requestObj.placementCode; | ||
bidmanager.addBidResponse(placementCode, bidResponse); | ||
}; | ||
|
||
return { | ||
callBids: _callBids | ||
}; | ||
}; | ||
|
||
adaptermanager.registerBidAdapter(new FidelityAdapter(), 'fidelity'); | ||
|
||
module.exports = FidelityAdapter; | ||
} | ||
return result || ''; | ||
} | ||
|
||
registerBidder(spec); |
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.
Need to add required field
ttl
: Time-to-Live - how long (in seconds) Prebid can use this bidThere 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.
Ok, thanks for review. I'll add .md and update adapter by the end of today hopefully.
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.
@jaiminpanchal27 All done. Changes were made, checks passed.