Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/prebid/Prebid.js into pre…
Browse files Browse the repository at this point in the history
…built

* 'master' of https://github.com/prebid/Prebid.js:
  inclusion of popular Nordic ad sizes to default size list (prebid#1168)
  pre release version bump
  Prebid 0.23.1 Release
  Add trafficSourceCode + test (prebid#1184)
  Clear cookie sync to prevent multiple calls (prebid#1181)
  change s2s adapter to filter out units with empty sizes array (prebid#1179)
  Sharethrough: Change to using a closure for the callback from ajax to preserve bidObj (prebid#1108)
  check array length when mapping sizes (prebid#1180)
  Bugfix/encoding url (prebid#1178)
  • Loading branch information
Mat Brown committed May 12, 2017
2 parents 2f7895c + 0eba2bc commit 1ef97b1
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 87 deletions.
1 change: 1 addition & 0 deletions src/adapters/appnexus.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ AppNexusAdapter = function AppNexusAdapter() {
}

jptCall = utils.tryAppendQueryString(jptCall, 'code', inventoryCode);
jptCall = utils.tryAppendQueryString(jptCall, 'traffic_source_code', (utils.getBidIdParameter('trafficSourceCode', bid.params)));

//sizes takes a bit more logic
var sizeQueryString = '';
Expand Down
7 changes: 6 additions & 1 deletion src/adapters/prebidServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function PrebidServer() {
timeout_millis : config.timeout,
url: utils.getTopWindowUrl(),
prebid_version : '$prebid.version$',
ad_units : bidRequest.ad_units
ad_units : bidRequest.ad_units.filter(hasSizes)
};

const payload = JSON.stringify(requestJson);
Expand All @@ -41,6 +41,11 @@ function PrebidServer() {
});
};

// at this point ad units should have a size array either directly or mapped so filter for that
function hasSizes(unit) {
return unit.sizes && unit.sizes.length;
}

/* Notify Prebid of bid responses so bids can get in the auction */
function handleResponse(response) {
let result;
Expand Down
96 changes: 48 additions & 48 deletions src/adapters/rhythmone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var bidmanager = require('../bidmanager.js'),
CONSTANTS = require('../constants.json');

import {ajax as ajax} from '../ajax';

module.exports = function(bidManager, global, loader){

var version = "0.9.0.0",
Expand All @@ -15,24 +15,24 @@ module.exports = function(bidManager, global, loader){
loadStart,
configuredPlacements = [],
fat = /(^v|(\.0)+$)/gi;

if(typeof global === "undefined")
global = window;

if(typeof bidManager === "undefined")
bidManager = bidmanager;

if(typeof loader === "undefined")
loader = ajax;

function applyMacros(txt, values){
return txt.replace(/\{([^\}]+)\}/g, function(match){
var v = values[match.replace(/[\{\}]/g, "").toLowerCase()];
if(typeof v !== "undefined") return v;
return match;
});
}

function load(bidParams, url, callback){
loader(url, function(responseText, response){
if(response.status === 200)
Expand All @@ -49,7 +49,7 @@ module.exports = function(bidManager, global, loader){
t = "application/x-shockwave-flash",
x = global.ActiveXObject;

if(p &&
if(p &&
p["Shockwave Flash"] &&
m &&
m[t] &&
Expand All @@ -63,28 +63,28 @@ module.exports = function(bidManager, global, loader){

return false;
}

var bidderCode = "rhythmone";

function attempt(valueFunction, defaultValue){
try{
return valueFunction();
}catch(ex){}
return defaultValue;
}

function logToConsole(txt){
if(debug)
console.log(txt);
}

function getBidParameters(bids){
for(var i=0;i<bids.length;i++)
if(typeof bids[i].params === "object" && bids[i].params.placementId)
return bids[i].params;
return null;
}

function noBids(params){
for(var i=0; i<params.bids.length; i++){
if(params.bids[i].success !== 1){
Expand All @@ -95,26 +95,26 @@ module.exports = function(bidManager, global, loader){
}
}
}

function getRMPURL(bidParams, bids){
var endpoint = "//tag.1rx.io/rmp/{placementId}/0/{path}?z={zone}",
query = [];

if(typeof bidParams.endpoint === "string")
endpoint = bidParams.endpoint;

if(typeof bidParams.zone === "string")
defaultZone = bidParams.zone;

if(typeof bidParams.path === "string")
defaultPath = bidParams.path;

if(bidParams.debug === true)
debug = true;

if(bidParams.trace === true)
query.push("trace=true");

endpoint = applyMacros(endpoint, {
placementid:bidParams.placementId,
zone: defaultZone,
Expand Down Expand Up @@ -146,24 +146,24 @@ module.exports = function(bidManager, global, loader){
p("tz", (new Date()).getTimezoneOffset());
p("dtype", ((/(ios|ipod|ipad|iphone|android)/i).test(global.navigator.userAgent) ? 1 : ((/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(global.navigator.userAgent) ? 3 : 2)));
p("flash", (flashInstalled() ? 1 : 0));

var heights = [],
widths = [],
floors = [],
mediaTypes = [],
i=0;

configuredPlacements = [];

p("hbv", global.$$PREBID_GLOBAL$$.version.replace(fat,"")+","+version.replace(fat,""));

for(; i<bids.length; i++){

var th = [], tw = [];

if(bids[i].sizes.length > 0 && typeof bids[i].sizes[0] === "number")
bids[i].sizes = [bids[i].sizes];

for(var j = 0; j<bids[i].sizes.length; j++){
tw.push(bids[i].sizes[j][0]);
th.push(bids[i].sizes[j][1]);
Expand All @@ -174,18 +174,18 @@ module.exports = function(bidManager, global, loader){
mediaTypes.push(((/video/i).test(bids[i].mediaType) ? "v" : "d"));
floors.push(0);
}

p("imp", configuredPlacements);
p("w", widths);
p("h", heights);
p("floor", floors);
p("t", mediaTypes);

endpoint += "&"+query.join("&");

return endpoint;
}

function sendAuditBeacon(placementId){
var data = {
doc_version : 1,
Expand All @@ -196,41 +196,41 @@ module.exports = function(bidManager, global, loader){
q = [],
u = "//hbevents.1rx.io/audit?",
i = new Image();

if(ao && ao.length > 0){
data.ancestor_origins = ao[ao.length-1];
}
}

data.popped = window.opener!==null?1:0;
data.framed = window.top===window?0:1;

try{
data.url = window.top.document.location.href.toString();
}catch(ex){
data.url = window.document.location.href.toString();
}

var prebid_instance = global.$$PREBID_GLOBAL$$;

data.prebid_version = prebid_instance.version.replace(fat,"");
data.response_ms = (new Date()).getTime() - loadStart;
data.placement_codes = configuredPlacements.join(",");
data.bidder_version = version;
data.prebid_timeout = prebid_instance.cbTimeout || prebid_instance.bidderTimeout;

for(var k in data){
q.push(encodeURIComponent(k)+"="+encodeURIComponent((typeof data[k] === "object" ? JSON.stringify(data[k]) : data[k])));
}
}

q.sort();
i.src = u+q.join("&");
}

this.callBids = function(params){

var slotMap = {},
bidParams = getBidParameters(params.bids);

debug = (bidParams !== null && bidParams.debug === true);

if(bidParams === null){
Expand All @@ -240,7 +240,7 @@ module.exports = function(bidManager, global, loader){

for(var i = 0; i<params.bids.length; i++)
slotMap[params.bids[i].placementCode] = params.bids[i];

loadStart = (new Date()).getTime();
load(bidParams, getRMPURL(bidParams, params.bids), function(code, msg, txt){

Expand All @@ -255,32 +255,32 @@ module.exports = function(bidManager, global, loader){
try{
var result = JSON.parse(txt),
registerBid = function(bid){

slotMap[bid.impid].success = 1;

var pbResponse = bidfactory.createBid(CONSTANTS.STATUS.GOOD),
placementCode = slotMap[bid.impid].placementCode;

placementCodes[placementCode] = false;

pbResponse.bidderCode = bidderCode;
pbResponse.cpm = parseFloat(bid.price);
pbResponse.width = bid.w;
pbResponse.height = bid.h;

if((/video/i).test(slotMap[bid.impid].mediaType)){
pbResponse.mediaType = "video";
pbResponse.vastUrl = bid.nurl;
pbResponse.descriptionUrl = bid.nurl;
}
else
pbResponse.ad = bid.adm;

logToConsole("registering bid "+placementCode+" "+JSON.stringify(pbResponse));

bidManager.addBidResponse(placementCode, pbResponse);
};

for(i=0; result.seatbid && i<result.seatbid.length; i++)
for(var j=0; result.seatbid[i].bid && j<result.seatbid[i].bid.length; j++){
registerBid(result.seatbid[i].bid[j]);
Expand All @@ -292,7 +292,7 @@ module.exports = function(bidManager, global, loader){
// if no bids are successful, inform prebid
noBids(params);
});

logToConsole("version: "+version);
};
};
};
10 changes: 10 additions & 0 deletions src/adapters/rubicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ var sizeMap = {
15:'300x250',
16:'336x280',
19:'300x100',
31:'980x120',
32:'250x360',
33:'180x500',
35:'980x150',
37:'468x400',
38:'930x180',
43:'320x50',
44:'300x50',
48:'300x300',
Expand All @@ -41,11 +47,15 @@ var sizeMap = {
68:'1800x1000',
72:'320x320',
73:'320x160',
78:'980x240',
79:'980x300',
80:'980x400',
83:'480x300',
94:'970x310',
96:'970x210',
101:'480x320',
102:'768x1024',
103:'480x280',
113:'1000x300',
117:'320x100',
125:'800x250',
Expand Down
23 changes: 11 additions & 12 deletions src/adapters/sharethrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var bidfactory = require('../bidfactory.js');
var ajax = require('../ajax.js').ajax;

const STR_BIDDER_CODE = "sharethrough";
const STR_VERSION = "1.1.0";
const STR_VERSION = "1.2.0";

var SharethroughAdapter = function SharethroughAdapter() {

Expand All @@ -22,10 +22,16 @@ var SharethroughAdapter = function SharethroughAdapter() {
const bidRequest = bids[i];
str.placementCodeSet[bidRequest.placementCode] = bidRequest;
const scriptUrl = _buildSharethroughCall(bidRequest);
str.ajax(scriptUrl, $$PREBID_GLOBAL$$.strcallback, undefined, {withCredentials: true});
str.ajax(scriptUrl, _createCallback(bidRequest), undefined, {withCredentials: true});
}
}

function _createCallback(bidRequest) {
return (bidResponse) => {
_strcallback(bidRequest, bidResponse);
};
}

function _buildSharethroughCall(bid) {
const pkey = utils.getBidIdParameter('pkey', bid.params);

Expand All @@ -39,17 +45,10 @@ var SharethroughAdapter = function SharethroughAdapter() {
return url;
}

$$PREBID_GLOBAL$$.strcallback = function(bidResponse) {
function _strcallback(bidObj, bidResponse) {
try {
bidResponse = JSON.parse(bidResponse);
} catch (e) {
utils.logError(e);
return;
}

const bidId = bidResponse.bidId;
const bidObj = utils.getBidRequest(bidId);
try {
const bidId = bidResponse.bidId;
const bid = bidfactory.createBid(1, bidObj);
bid.bidderCode = STR_BIDDER_CODE;
bid.cpm = bidResponse.creatives[0].cpm;
Expand Down Expand Up @@ -84,7 +83,7 @@ var SharethroughAdapter = function SharethroughAdapter() {
} catch (e) {
_handleInvalidBid(bidObj);
}
};
}

function _handleInvalidBid(bidObj) {
const bid = bidfactory.createBid(2, bidObj);
Expand Down
Loading

0 comments on commit 1ef97b1

Please sign in to comment.