Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request prebid#68 in AOLP_ADS_JS/prebid.js from feature/Pr…
Browse files Browse the repository at this point in the history
…ebid-official-0.17.0 to release/1.12.0

* commit 'bce975978c2c088d301d120b949d38080ca9d314':
  Add changelog entry.
  Prebid Release 0.17.0
  remove hb_pb targeting key for deal bids with no cpm (prebid#881)
  Fix for bug prebid#866 (prebid#867)
  Allow changing of 'ga' global variable (prebid#832)
  emit auction end event before bidsBackHandler callback (prebid#884)
  Add Widespace adapter (prebid#846)
  prevent rubicon adapter from registering two bids on exceptions (prebid#854)
  Code Refactoring - Upgrading end point. (prebid#826)
  Ignore test html pages (prebid#878)
  Detect browser width instead of the screen width (prebid#837)
  New aardvark adapter with support for aliasing (prebid#875)
  Add Fidelity adapter (prebid#862)
  Adkernel adapter aliasing (prebid#857)
  0.16.1-pre
  • Loading branch information
vzhukovsky committed Feb 22, 2017
2 parents ac34b02 + bce9759 commit 0758d4d
Show file tree
Hide file tree
Showing 28 changed files with 1,332 additions and 475 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ build
# Test Files
test/app
gpt.html
gpt-mlane.html
gpt-each-bidder3.html

# Selenium files
bin
selenium*.log

# Dev File

integrationExamples/gpt/gpt.html
integrationExamples/gpt/*-test.html
integrationExamples/implementations/
src/adapters/analytics/libraries

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
AOL Prebid 1.12.0
----------------
Updated to Prebid 0.17.0

AOL Prebid 1.11.0
----------------
Added functionality of cookie syncing upon bid response.
Expand Down
2 changes: 2 additions & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"appnexusAst",
"conversant",
"districtmDMX",
"fidelity",
"getintent",
"gumgum",
"hiromedia",
Expand All @@ -37,6 +38,7 @@
"centro",
"roxot",
"vertoz",
"widespace",
{
"appnexus": {
"alias": "brealtime"
Expand Down
9 changes: 8 additions & 1 deletion integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
var adUnits = [
{
code: 'div-gpt-ad-12345678-0',
sizes: [[300, 250], [300, 600]],
sizes: [[300, 250], [300, 300], [300, 600]],
bids: [
// 1 ad unit can be targeted by multiple bids.
{
Expand Down Expand Up @@ -224,6 +224,13 @@
zoneId : '30164',
host : 'cpm.metaadserving.com'
}
},
{
bidder: 'widespace',
params: {
sid: '7b6589bf-95c8-4656-90b9-af9737bb9ad3',
cur: 'EUR'
}
}
]
}, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prebid.js",
"version": "0.16.0",
"version": "0.17.0",
"description": "Header Bidding Management Library",
"main": "src/prebid.js",
"scripts": {
Expand Down
216 changes: 128 additions & 88 deletions src/adapters/aardvark.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,144 @@
var utils = require('../utils.js');
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader');


/**
/*
* Adapter for requesting bids from RTK Aardvark
* To request an RTK Aardvark Header bidding account
* or for additional integration support please contact sales@rtk.io
*/

var AardvarkAdapter = function AardvarkAdapter() {

function _callBids(params) {
var rtkBids = params.bids || [];

_requestBids(rtkBids);
}

function _requestBids(bidReqs) {
let ref;
try {
ref = window.top.location.host;
}
catch (err) {
ref = "thor.rtk.io";

}
var ai = "";
var shortcodes = [];

//build bid URL for RTK
utils._each(bidReqs, function (bid) {
ai = utils.getBidIdParameter('ai', bid.params);
var sc = utils.getBidIdParameter('sc', bid.params);
shortcodes.push(sc);
});

var scURL = "";

if (shortcodes.length > 1) {
scURL = shortcodes.join("_");
} else {
scURL = shortcodes[0];
}

var scriptUrl = '//thor.rtk.io/' + ai + "/" + scURL + "/aardvark/?jsonp=window.$$PREBID_GLOBAL$$.aardvarkResponse&rtkreferer=" + ref;
adloader.loadScript(scriptUrl);
}

//expose the callback to the global object:
window.$$PREBID_GLOBAL$$.aardvarkResponse = function (rtkResponseObj) {

//Get all initial Aardvark Bid Objects
var bidsObj = $$PREBID_GLOBAL$$._bidsRequested.filter(function (bidder) {
return bidder.bidderCode === 'aardvark';
})[0];

var returnedBidIDs = {};

if (rtkResponseObj.length > 0) {
rtkResponseObj.forEach(function (bid) {

if (!bid.error) {
var currentBid = bidsObj.bids.filter(function (r) {
return r.params.sc === bid.id;
})[0];
if (currentBid) {
var bidResponse = bidfactory.createBid(1, currentBid);
bidResponse.bidderCode = "aardvark";
bidResponse.cpm = bid.cpm;
bidResponse.ad = bid.adm;
bidResponse.ad += utils.createTrackPixelHtml(decodeURIComponent(bid.nurl));
bidResponse.width = currentBid.sizes[0][0];
bidResponse.height = currentBid.sizes[0][1];
returnedBidIDs[bid.id] = currentBid.placementCode;
bidmanager.addBidResponse(currentBid.placementCode, bidResponse);
var utils = require('../utils.js');
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader.js');
var adapter = require('./adapter.js');
var constants = require('../constants.json');

var AARDVARK_CALLBACK_NAME = 'aardvarkResponse',
AARDVARK_REQUESTS_MAP = 'aardvarkRequests',
AARDVARK_BIDDER_CODE = 'aardvark',
DEFAULT_REFERRER = 'thor.rtk.io',
DEFAULT_ENDPOINT = 'thor.rtk.io',

endpoint = DEFAULT_ENDPOINT,

requestBids = function(bidderCode, callbackName, bidReqs) {
var ref = utils.getTopWindowLocation(),
ai = '',
scs = [],
bidIds = [];

ref = ref ? ref.host : DEFAULT_REFERRER;

for (var i = 0, l = bidReqs.length, bid, _ai, _sc, _endpoint; i < l; i += 1) {
bid = bidReqs[i];
_ai = utils.getBidIdParameter('ai', bid.params);
_sc = utils.getBidIdParameter('sc', bid.params);
if (!_ai || !_ai.length || !_sc || !_sc.length)
continue;

_endpoint = utils.getBidIdParameter('host', bid.params);
if (_endpoint)
endpoint = _endpoint;

if (!ai.length)
ai = _ai;
if (_sc)
scs.push(_sc);

bidIds.push(_sc + "=" + bid.bidId);

// Create the bidIdsMap for easier mapping back later
$$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][bid.bidId] = bid;
}

if (!ai.length || !scs.length)
return utils.logWarn("Bad bid request params given for adapter $" + bidderCode + " (" + AARDVARK_BIDDER_CODE + ")");

adloader.loadScript([
'//' + endpoint + '/', ai, '/', scs.join('_'),
'/aardvark/?jsonp=$$PREBID_GLOBAL$$.', callbackName,
'&rtkreferer=', ref, '&', bidIds.join('&')
].join(''));
},



registerBidResponse = function(bidderCode, rawBidResponse) {
if (rawBidResponse.error)
return utils.logWarn("Aardvark bid received with an error, ignoring... [" + rawBidResponse.error + "]");

if (!rawBidResponse.cid)
return utils.logWarn("Aardvark bid received without a callback id, ignoring...");

var bidObj = $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][rawBidResponse.cid];
if (!bidObj)
return utils.logWarn("Aardvark request not found: " + rawBidResponse.cid);

if (bidObj.params.sc !== rawBidResponse.id)
return utils.logWarn("Aardvark bid received with a non matching shortcode " + rawBidResponse.id + " instead of " + bidObj.params.sc);

var bidResponse = bidfactory.createBid(constants.STATUS.GOOD, bidObj);
bidResponse.bidderCode = bidObj.bidder;
bidResponse.cpm = rawBidResponse.cpm;
bidResponse.ad = rawBidResponse.adm + utils.createTrackPixelHtml(decodeURIComponent(rawBidResponse.nurl));
bidResponse.width = bidObj.sizes[0][0];
bidResponse.height = bidObj.sizes[0][1];

bidmanager.addBidResponse(bidObj.placementCode, bidResponse);
$$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][rawBidResponse.cid].responded = true;
},



registerAardvarkCallback = function(bidderCode, callbackName) {
$$PREBID_GLOBAL$$[callbackName] = function(rtkResponseObj) {

rtkResponseObj.forEach(function(bidResponse) {
registerBidResponse(bidderCode, bidResponse);
});

for (var bidRequestId in $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode])
if ($$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode].hasOwnProperty(bidRequestId)) {
var bidRequest = $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode][bidRequestId];
if (!bidRequest.responded) {
var bidResponse = bidfactory.createBid(constants.STATUS.NO_BID, bidRequest);
bidResponse.bidderCode = bidRequest.bidder;
bidmanager.addBidResponse(bidRequest.placementCode, bidResponse);
}
}
};
},



AardvarkAdapter = function() {
var baseAdapter = adapter.createNew(AARDVARK_BIDDER_CODE);

$$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP] = $$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP] || {};

baseAdapter.callBids = function (params) {
var bidderCode = baseAdapter.getBidderCode(),
callbackName = AARDVARK_CALLBACK_NAME;

}
if (bidderCode !== AARDVARK_BIDDER_CODE)
callbackName = [AARDVARK_CALLBACK_NAME, bidderCode].join('_');

});
$$PREBID_GLOBAL$$[AARDVARK_REQUESTS_MAP][bidderCode] = {};

}
registerAardvarkCallback(bidderCode, callbackName);

//All bids are back - lets add a bid response for anything that did not receive a bid.
let difference = bidsObj.bids.filter(x => Object.keys(returnedBidIDs).indexOf(x.params.sc) === -1);
return requestBids(bidderCode, callbackName, params.bids || []);
};

difference.forEach(function (bidRequest) {
var bidResponse = bidfactory.createBid(2, bidRequest);
bidResponse.bidderCode = "aardvark";
bidmanager.addBidResponse(bidRequest.placementCode, bidResponse);
});
return {
callBids: baseAdapter.callBids,
setBidderCode: baseAdapter.setBidderCode,
createNew: exports.createNew
};
};


}; // aardvarkResponse

return {
callBids: _callBids
};
exports.createNew = function() {
return new AardvarkAdapter();
};

module.exports = AardvarkAdapter;
module.exports = AardvarkAdapter;
Loading

0 comments on commit 0758d4d

Please sign in to comment.