-
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
Merged
dbemiller
merged 11 commits into
prebid:master
from
onaydenov:prebid-1.0-fidelityadapterupdate
Oct 26, 2017
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
43d2ca9
Fidelity Media Adapter update. Prebid v1.0.
onaydenov 563d8e1
Fidelity Media Adapter update. Prebid v1.0.
onaydenov 58012ac
Fidelity Media fmxSSP Adapter update. Prebid v1.0
onaydenov 32904c4
Fidelity Media. Prebid v 1.0 Add tmax
onaydenov aeb7b13
Fidelity Media. Prebid v 1.0. ttl
onaydenov b009b16
Fidelity Media. Prebid v 1.0. spec
onaydenov 9204c35
Less bidderCode, add creativeId
onaydenov c1ef347
Adapter v.1, less bidderCode, add creativeId
onaydenov 3a901ff
Prebid v1. InterpretResponse. Spec.
onaydenov 7ad9f4d
InterpretResponse
onaydenov 6497042
InterpretResponse
onaydenov 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,102 +1,86 @@ | ||
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 = { | ||
requestId: bid.impid, | ||
creativeId: bid.impid, | ||
cpm: bid.price, | ||
width: bid.width, | ||
height: bid.height, | ||
ad: bid.adm, | ||
netRevenue: bid.netRevenue, | ||
currency: bid.cur, | ||
ttl: bid.ttl, | ||
}; | ||
|
||
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); |
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,26 @@ | ||
# Overview | ||
|
||
**Module Name**: Fidelity Media fmxSSP Bidder Adapter | ||
**Module Type**: Bidder Adapter | ||
**Maintainer**: [email protected] | ||
|
||
# Description | ||
|
||
Connects to Fidelity Media fmxSSP demand source to fetch bids. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
code: 'banner-ad-div', | ||
sizes: [[300, 250]], | ||
bids: [{ | ||
bidder: 'fidelity', | ||
params: { | ||
zoneid: '27248', | ||
floor: 0.005, | ||
server: 'x.fidelity-media.com' | ||
} | ||
}] | ||
}]; | ||
``` |
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.
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.