Skip to content
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
merged 11 commits into from
Oct 26, 2017
172 changes: 78 additions & 94 deletions modules/fidelityBidAdapter.js
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 => {
Copy link
Collaborator

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 bid

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

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);
26 changes: 26 additions & 0 deletions modules/fidelityBidAdapter.md
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**: on@fidelity-media.com

# 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'
}
}]
}];

```
Loading