From f4f7e24d8bc604fa2e5d367b18d1476b84f8bc92 Mon Sep 17 00:00:00 2001 From: Ned Stankus Date: Tue, 14 Jun 2016 10:45:53 -0700 Subject: [PATCH 1/5] Adding logic to replace $$PREBID_GLOBAL$$ with custom name. Replacing all references to 'pbjs' with '$$PREBID_GLOBAL$$'. --- .jshintrc | 2 +- package.json | 1 + src/adaptermanager.js | 2 +- src/adapters/aardvark.js | 6 +- src/adapters/adform.js | 4 +- src/adapters/appnexus.js | 4 +- src/adapters/brightcom.js | 6 +- src/adapters/nginad.js | 6 +- src/adapters/pubmatic.js | 4 +- src/adapters/rubicon.js | 2 +- src/adapters/sovrn.js | 6 +- src/adapters/springserve.js | 6 +- src/adapters/triplelift.js | 6 +- src/adapters/wideorbit.js | 6 +- src/adapters/yieldbot.js | 2 +- src/bidmanager.js | 30 +++--- src/prebid.js | 210 ++++++++++++++++++------------------ src/utils.js | 10 +- webpack.conf.js | 16 ++- 19 files changed, 172 insertions(+), 157 deletions(-) diff --git a/.jshintrc b/.jshintrc index 11b31057327..a2331cc9b8b 100644 --- a/.jshintrc +++ b/.jshintrc @@ -21,7 +21,7 @@ "before": true, "after": true, "exports": true, - "pbjs": true, + "$$PREBID_GLOBAL$$": true, "pbjsTestOnly": true, "assert": false, "expect": false, diff --git a/package.json b/package.json index d3f1da1a039..9d9505428c5 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "type": "git", "url": "https://github.com/prebid/Prebid.js.git" }, + "globalVarName": "pbjs", "adapters": [ "aardvark", "adequant", diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 0243ec11c00..8ab7e6c61e6 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -38,7 +38,7 @@ exports.callBids = ({ adUnits }) => { start: new Date().getTime() }; utils.logMessage(`CALLING BIDDER ======= ${bidderCode}`); - pbjs._bidsRequested.push(bidderRequest); + $$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest); events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidderRequest); if (bidderRequest.bids && bidderRequest.bids.length) { adapter.callBids(bidderRequest); diff --git a/src/adapters/aardvark.js b/src/adapters/aardvark.js index 3fde05edb27..7eca17ae863 100644 --- a/src/adapters/aardvark.js +++ b/src/adapters/aardvark.js @@ -45,15 +45,15 @@ var AardvarkAdapter = function AardvarkAdapter() { scURL = shortcodes[0]; } - var scriptUrl = '//thor.rtk.io/' + ai + "/" + scURL + "/aardvark/?jsonp=window.pbjs.aardvarkResponse&rtkreferer=" + ref; + 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.pbjs.aardvarkResponse = function (rtkResponseObj) { + window.$$PREBID_GLOBAL$$.aardvarkResponse = function (rtkResponseObj) { //Get all initial Aardvark Bid Objects - var bidsObj = pbjs._bidsRequested.filter(function (bidder) { + var bidsObj = $$PREBID_GLOBAL$$._bidsRequested.filter(function (bidder) { return bidder.bidderCode === 'aardvark'; })[0]; diff --git a/src/adapters/adform.js b/src/adapters/adform.js index 001d084ab32..5261b526c70 100644 --- a/src/adapters/adform.js +++ b/src/adapters/adform.js @@ -31,8 +31,8 @@ function AdformAdapter() { request.unshift('//adx.adform.net/adx/?rp=4'); } - pbjs[callbackName] = handleCallback(bids); - request.push('callback=pbjs.' + callbackName); + $$PREBID_GLOBAL$$[callbackName] = handleCallback(bids); + request.push('callback=$$PREBID_GLOBAL$$.' + callbackName); adloader.loadScript(request.join('&')); } diff --git a/src/adapters/appnexus.js b/src/adapters/appnexus.js index 23b37f86840..1886e5f3c21 100644 --- a/src/adapters/appnexus.js +++ b/src/adapters/appnexus.js @@ -48,7 +48,7 @@ AppNexusAdapter = function AppNexusAdapter() { var jptCall = 'http' + (document.location.protocol === 'https:' ? 's://secure.adnxs.com/jpt?' : '://ib.adnxs.com/jpt?'); - jptCall = utils.tryAppendQueryString(jptCall, 'callback', 'pbjs.handleAnCB'); + jptCall = utils.tryAppendQueryString(jptCall, 'callback', '$$PREBID_GLOBAL$$.handleAnCB'); jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); jptCall = utils.tryAppendQueryString(jptCall, 'psa', '0'); jptCall = utils.tryAppendQueryString(jptCall, 'id', placementId); @@ -143,7 +143,7 @@ AppNexusAdapter = function AppNexusAdapter() { } //expose the callback to the global object: - pbjs.handleAnCB = function (jptResponseObj) { + $$PREBID_GLOBAL$$.handleAnCB = function (jptResponseObj) { var bidCode; diff --git a/src/adapters/brightcom.js b/src/adapters/brightcom.js index 72ba7a4a4ca..0e8efe1c678 100644 --- a/src/adapters/brightcom.js +++ b/src/adapters/brightcom.js @@ -16,7 +16,7 @@ var BrightcomAdapter = function BrightcomAdapter() { var brightcomBidderCode = 'brightcom'; // Define the callback function - var brightcomCallbackFunction = 'window.pbjs=window.pbjs||window.parent.pbjs||window.top.pbjs;window.pbjs.brightcomResponse'; + var brightcomCallbackFunction = 'window.$$PREBID_GLOBAL$$=window.$$PREBID_GLOBAL$$||window.parent.$$PREBID_GLOBAL$$||window.top.$$PREBID_GLOBAL$$;window.$$PREBID_GLOBAL$$.brightcomResponse'; // Manage the requested and received ad units' codes, to know which are invalid (didn't return) var reqAdUnitsCode = [], @@ -121,7 +121,7 @@ var BrightcomAdapter = function BrightcomAdapter() { } //expose the callback to the global object: - pbjs.brightcomResponse = function(brightcomResponseObj) { + $$PREBID_GLOBAL$$.brightcomResponse = function(brightcomResponseObj) { var bid = {}; @@ -136,7 +136,7 @@ var BrightcomAdapter = function BrightcomAdapter() { brightcomResponseObj.seatbid[0].bid.forEach( function(curBid) { // Get the bid request data - var bidRequest = pbjs._bidsRequested.find(bidSet => bidSet.bidderCode === 'brightcom').bids[0]; // this assumes a single request only + var bidRequest = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'brightcom').bids[0]; // this assumes a single request only // Make sure the bid exists if (bidRequest) { diff --git a/src/adapters/nginad.js b/src/adapters/nginad.js index 40bfe875654..aca29da1472 100644 --- a/src/adapters/nginad.js +++ b/src/adapters/nginad.js @@ -101,7 +101,7 @@ var NginAdAdapter = function NginAdAdapter() { } }; - var scriptUrl = window.location.protocol + '//' + rtbServerDomain + '/bid/rtb?callback=window.pbjs.nginadResponse' + + var scriptUrl = window.location.protocol + '//' + rtbServerDomain + '/bid/rtb?callback=window.$$PREBID_GLOBAL$$.nginadResponse' + '&br=' + encodeURIComponent(JSON.stringify(nginadBidReq)); adloader.loadScript(scriptUrl, null); @@ -120,7 +120,7 @@ var NginAdAdapter = function NginAdAdapter() { } //expose the callback to the global object: - pbjs.nginadResponse = function(nginadResponseObj) { + $$PREBID_GLOBAL$$.nginadResponse = function(nginadResponseObj) { var bid = {}; var key; @@ -142,7 +142,7 @@ var NginAdAdapter = function NginAdAdapter() { var id = nginadBid.impid; // try to fetch the bid request we sent NginAd - var bidObj = pbjs._bidsRequested.find(bidSet => bidSet.bidderCode === 'nginad').bids + var bidObj = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'nginad').bids .find(bid => bid.bidId === id); if (!bidObj) { return handleErrorResponse(nginadBid, defaultPlacementForBadBid); diff --git a/src/adapters/pubmatic.js b/src/adapters/pubmatic.js index 4ae81941f72..cd1ebeed9e7 100644 --- a/src/adapters/pubmatic.js +++ b/src/adapters/pubmatic.js @@ -64,7 +64,7 @@ var PubmaticAdapter = function PubmaticAdapter() { content += ''; content += ''; - content += 'window.parent.pbjs.handlePubmaticCallback({progKeyValueMap: progKeyValueMap,' + + content += 'window.parent.$$PREBID_GLOBAL$$.handlePubmaticCallback({progKeyValueMap: progKeyValueMap,' + ' bidDetailsMap: bidDetailsMap})'; content += ''; content += ''; @@ -73,7 +73,7 @@ var PubmaticAdapter = function PubmaticAdapter() { return content; } - pbjs.handlePubmaticCallback = function (response) { + $$PREBID_GLOBAL$$.handlePubmaticCallback = function (response) { var i; var adUnit; var adUnitInfo; diff --git a/src/adapters/rubicon.js b/src/adapters/rubicon.js index 17968e0c597..0c4f4edc2b4 100644 --- a/src/adapters/rubicon.js +++ b/src/adapters/rubicon.js @@ -297,7 +297,7 @@ var RubiconAdapter = function RubiconAdapter() { _bidsReady(slots); }; - window.rubicontag.setIntegration('pbjs'); + window.rubicontag.setIntegration('$$PREBID_GLOBAL$$'); window.rubicontag.run(callback, parameters); }); } diff --git a/src/adapters/sovrn.js b/src/adapters/sovrn.js index b1e38615f74..1892ad7b42d 100644 --- a/src/adapters/sovrn.js +++ b/src/adapters/sovrn.js @@ -69,7 +69,7 @@ var SovrnAdapter = function SovrnAdapter() { } }; - var scriptUrl = '//' + sovrnUrl + '?callback=window.pbjs.sovrnResponse' + + var scriptUrl = '//' + sovrnUrl + '?callback=window.$$PREBID_GLOBAL$$.sovrnResponse' + '&src=' + CONSTANTS.REPO_AND_VERSION + '&br=' + encodeURIComponent(JSON.stringify(sovrnBidReq)); adloader.loadScript(scriptUrl, null); @@ -91,7 +91,7 @@ var SovrnAdapter = function SovrnAdapter() { } //expose the callback to the global object: - pbjs.sovrnResponse = function (sovrnResponseObj) { + $$PREBID_GLOBAL$$.sovrnResponse = function (sovrnResponseObj) { // valid object? if (sovrnResponseObj && sovrnResponseObj.id) { // valid object w/ bid responses? @@ -105,7 +105,7 @@ var SovrnAdapter = function SovrnAdapter() { var bid = {}; // try to fetch the bid request we sent Sovrn - var bidObj = pbjs._bidsRequested.find(bidSet => bidSet.bidderCode === 'sovrn').bids + var bidObj = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'sovrn').bids .find(bid => bid.bidId === id); if (bidObj) { diff --git a/src/adapters/springserve.js b/src/adapters/springserve.js index 9babe694e36..2aa146b3129 100644 --- a/src/adapters/springserve.js +++ b/src/adapters/springserve.js @@ -48,7 +48,7 @@ SpringServeAdapter = function SpringServeAdapter() { spCall += '&domain='; spCall += domain; - spCall += '&callback=pbjs.handleSpringServeCB'; + spCall += '&callback=$$PREBID_GLOBAL$$.handleSpringServeCB'; return spCall; } @@ -62,13 +62,13 @@ SpringServeAdapter = function SpringServeAdapter() { } } - pbjs.handleSpringServeCB = function (responseObj) { + $$PREBID_GLOBAL$$.handleSpringServeCB = function (responseObj) { if (responseObj && responseObj.seatbid && responseObj.seatbid.length > 0 && responseObj.seatbid[0].bid[0] !== undefined) { //look up the request attributs stored in the bidmanager var responseBid = responseObj.seatbid[0].bid[0]; //var requestObj = bidmanager.getPlacementIdByCBIdentifer(responseBid.impid); - var requestBids = pbjs._bidsRequested.find(bidSet => bidSet.bidderCode === 'springserve').bids + var requestBids = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'springserve').bids .filter(bid => bid.params && bid.params.impId === +responseBid.impid); var bid = bidfactory.createBid(1); var placementCode; diff --git a/src/adapters/triplelift.js b/src/adapters/triplelift.js index e0083a95e16..f612d103397 100644 --- a/src/adapters/triplelift.js +++ b/src/adapters/triplelift.js @@ -36,7 +36,7 @@ var TripleLiftAdapter = function TripleLiftAdapter() { var tlURI = '//tlx.3lift.com/header/auction?'; var tlCall = document.location.protocol + tlURI; - tlCall = utils.tryAppendQueryString(tlCall, 'callback', 'pbjs.TLCB'); + tlCall = utils.tryAppendQueryString(tlCall, 'callback', '$$PREBID_GLOBAL$$.TLCB'); tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid'); tlCall = utils.tryAppendQueryString(tlCall, 'lib', '0.5.0'); tlCall = utils.tryAppendQueryString(tlCall, 'callback_id', callbackId); @@ -70,10 +70,10 @@ var TripleLiftAdapter = function TripleLiftAdapter() { //expose the callback to the global object: - pbjs.TLCB = function(tlResponseObj) { + $$PREBID_GLOBAL$$.TLCB = function(tlResponseObj) { if (tlResponseObj && tlResponseObj.callback_id) { //var bidObj = bidmanager.pbCallbackMap[tlResponseObj.callback_id], - var bidObj = pbjs._bidsRequested.find(bidSet => bidSet.bidderRequestId === tlResponseObj.callback_id).bids.reduce((a, b) => b); + var bidObj = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderRequestId === tlResponseObj.callback_id).bids.reduce((a, b) => b); var placementCode = bidObj.placementCode; // @if NODE_ENV='debug' diff --git a/src/adapters/wideorbit.js b/src/adapters/wideorbit.js index e8431cab7bf..2366b04b60a 100644 --- a/src/adapters/wideorbit.js +++ b/src/adapters/wideorbit.js @@ -4,7 +4,7 @@ var bidfactory = require('../bidfactory.js'), adloader = require('../adloader'); var WideOrbitAdapter = function WideOrbitAdapter() { - var pageImpression = 'JSAdservingMP.ashx?pc={pc}&pbId={pbId}&clk=&exm=&jsv=1.0&tsv=1.0&cts={cts}&arp=0&fl=0&vitp=&vit=&jscb=window.pbjs.handleWideOrbitCallback&url=&fp=&oid=&exr=&mraid=&apid=&apbndl=&mpp=0&uid=&cb={cb}&hb=1', + var pageImpression = 'JSAdservingMP.ashx?pc={pc}&pbId={pbId}&clk=&exm=&jsv=1.0&tsv=1.0&cts={cts}&arp=0&fl=0&vitp=&vit=&jscb=window.$$PREBID_GLOBAL$$.handleWideOrbitCallback&url=&fp=&oid=&exr=&mraid=&apid=&apbndl=&mpp=0&uid=&cb={cb}&hb=1', pageRepeatCommonParam = '&gid{o}={gid}&pp{o}=&clk{o}=&rpos{o}={rpos}&ecpm{o}={ecpm}&ntv{o}=&ntl{o}=&adsid{o}=', pageRepeatParamId = '&pId{o}={pId}&rank{o}={rank}', pageRepeatParamNamed = '&wsName{o}={wsName}&wName{o}={wName}&rank{o}={rank}&bfDim{o}={width}x{height}&subp{o}={subp}', @@ -178,8 +178,8 @@ var WideOrbitAdapter = function WideOrbitAdapter() { return adCode; } - window.pbjs = window.pbjs || {}; - window.pbjs.handleWideOrbitCallback = function (response) { + window.$$PREBID_GLOBAL$$ = window.$$PREBID_GLOBAL$$ || {}; + window.$$PREBID_GLOBAL$$.handleWideOrbitCallback = function (response) { var bidResponse, bidObject; diff --git a/src/adapters/yieldbot.js b/src/adapters/yieldbot.js index 88c290d6ddb..00e3dcf20c3 100644 --- a/src/adapters/yieldbot.js +++ b/src/adapters/yieldbot.js @@ -124,7 +124,7 @@ var YieldbotAdapter = function YieldbotAdapter() { var placementCode; var adapterConfig; - adapterConfig = pbjs._bidsRequested + adapterConfig = $$PREBID_GLOBAL$$._bidsRequested .find(bidderRequest => bidderRequest.bidderCode === 'yieldbot').bids .find(bid => bid.bidId === v) || {}; slot = adapterConfig.params.slot || ''; diff --git a/src/bidmanager.js b/src/bidmanager.js index dcc6627faeb..836e7352768 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -21,10 +21,10 @@ const _hgPriceCap = 20.00; * @return {array} [description] */ exports.getTimedOutBidders = function () { - return pbjs._bidsRequested + return $$PREBID_GLOBAL$$._bidsRequested .map(getBidderCode) .filter(uniques) - .filter(bidder => pbjs._bidsReceived + .filter(bidder => $$PREBID_GLOBAL$$._bidsReceived .map(getBidders) .filter(uniques) .indexOf(bidder) < 0); @@ -41,8 +41,8 @@ function getBidders(bid) { } function bidsBackAdUnit(adUnitCode) { - const requested = pbjs.adUnits.find(unit => unit.code === adUnitCode).bids.length; - const received = pbjs._bidsReceived.filter(bid => bid.adUnitCode === adUnitCode).length; + const requested = $$PREBID_GLOBAL$$.adUnits.find(unit => unit.code === adUnitCode).bids.length; + const received = $$PREBID_GLOBAL$$._bidsReceived.filter(bid => bid.adUnitCode === adUnitCode).length; return requested === received; } @@ -51,8 +51,8 @@ function add(a, b) { } function bidsBackAll() { - const requested = pbjs._bidsRequested.map(bidSet => bidSet.bids.length).reduce(add); - const received = pbjs._bidsReceived.length; + const requested = $$PREBID_GLOBAL$$._bidsRequested.map(bidSet => bidSet.bids.length).reduce(add); + const received = $$PREBID_GLOBAL$$._bidsReceived.length; return requested === received; } @@ -61,7 +61,7 @@ exports.bidsBackAll = function() { }; function getBidSetForBidder(bidder) { - return pbjs._bidsRequested.find(bidSet => bidSet.bidderCode === bidder); + return $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === bidder); } /* @@ -104,7 +104,7 @@ exports.addBidResponse = function (adUnitCode, bid) { bid.adserverTargeting = keyValues; } - pbjs._bidsReceived.push(bid); + $$PREBID_GLOBAL$$._bidsReceived.push(bid); } if (bidsBackAdUnit(bid.adUnitCode)) { @@ -115,7 +115,7 @@ exports.addBidResponse = function (adUnitCode, bid) { this.executeCallback(); } - if (bid.timeToRespond > pbjs.bidderTimeout) { + if (bid.timeToRespond > $$PREBID_GLOBAL$$.bidderTimeout) { events.emit(CONSTANTS.EVENTS.BID_TIMEOUT, this.getTimedOutBidders()); this.executeCallback(); @@ -124,7 +124,7 @@ exports.addBidResponse = function (adUnitCode, bid) { function getKeyValueTargetingPairs(bidderCode, custBidObj) { var keyValues = {}; - var bidder_settings = pbjs.bidderSettings || {}; + var bidder_settings = $$PREBID_GLOBAL$$.bidderSettings || {}; //1) set the keys from "standard" setting or from prebid defaults if (custBidObj && bidder_settings) { @@ -242,7 +242,7 @@ exports.executeCallback = function () { externalOneTimeCallback = null; } - pbjs.clearAuction(); + $$PREBID_GLOBAL$$.clearAuction(); }; function triggerAdUnitCallbacks(adUnitCode) { @@ -256,7 +256,7 @@ function processCallbacks(callbackQueue) { if (utils.isArray(callbackQueue)) { for (i = 0; i < callbackQueue.length; i++) { var func = callbackQueue[i]; - func.call(pbjs, pbjs._bidsReceived.reduce(groupByPlacement, {})); + func.call($$PREBID_GLOBAL$$, $$PREBID_GLOBAL$$._bidsReceived.reduce(groupByPlacement, {})); } } } @@ -311,10 +311,10 @@ events.on(CONSTANTS.EVENTS.BID_ADJUSTMENT, function (bid) { function adjustBids(bid) { var code = bid.bidderCode; var bidPriceAdjusted = bid.cpm; - if (code && pbjs.bidderSettings && pbjs.bidderSettings[code]) { - if (typeof pbjs.bidderSettings[code].bidCpmAdjustment === objectType_function) { + if (code && $$PREBID_GLOBAL$$.bidderSettings && $$PREBID_GLOBAL$$.bidderSettings[code]) { + if (typeof $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment === objectType_function) { try { - bidPriceAdjusted = pbjs.bidderSettings[code].bidCpmAdjustment.call(null, bid.cpm); + bidPriceAdjusted = $$PREBID_GLOBAL$$.bidderSettings[code].bidCpmAdjustment.call(null, bid.cpm); } catch (e) { utils.logError('Error during bid adjustment', 'bidmanager.js', e); diff --git a/src/prebid.js b/src/prebid.js index 7f1e5b32acb..50bb785ba80 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -1,12 +1,12 @@ -/** @module pbjs */ +/** @module $$PREBID_GLOBAL$$ */ import { flatten, uniques, getKeys, isGptPubadsDefined, getHighestCpm } from './utils'; import 'polyfill'; -// if pbjs already exists in global document scope, use it, if not, create the object -window.pbjs = (window.pbjs || {}); -window.pbjs.que = window.pbjs.que || []; -var pbjs = window.pbjs; +// if $$PREBID_GLOBAL$$ already exists in global document scope, use it, if not, create the object +window.$$PREBID_GLOBAL$$ = (window.$$PREBID_GLOBAL$$ || {}); +window.$$PREBID_GLOBAL$$.que = window.$$PREBID_GLOBAL$$.que || []; +var $$PREBID_GLOBAL$$ = window.$$PREBID_GLOBAL$$; var CONSTANTS = require('./constants.json'); var utils = require('./utils.js'); var bidmanager = require('./bidmanager.js'); @@ -35,29 +35,29 @@ var eventValidators = { /* Public vars */ -pbjs._bidsRequested = []; -pbjs._bidsReceived = []; -pbjs._adsReceived = []; +$$PREBID_GLOBAL$$._bidsRequested = []; +$$PREBID_GLOBAL$$._bidsReceived = []; +$$PREBID_GLOBAL$$._adsReceived = []; //default timeout for all bids -pbjs.bidderTimeout = pbjs.bidderTimeout || 2000; -pbjs.logging = pbjs.logging || false; +$$PREBID_GLOBAL$$.bidderTimeout = $$PREBID_GLOBAL$$.bidderTimeout || 2000; +$$PREBID_GLOBAL$$.logging = $$PREBID_GLOBAL$$.logging || false; //let the world know we are loaded -pbjs.libLoaded = true; +$$PREBID_GLOBAL$$.libLoaded = true; //version auto generated from build utils.logInfo('Prebid.js v$prebid.version$ loaded'); //create adUnit array -pbjs.adUnits = pbjs.adUnits || []; +$$PREBID_GLOBAL$$.adUnits = $$PREBID_GLOBAL$$.adUnits || []; /** * Command queue that functions will execute once prebid.js is loaded * @param {function} cmd Annoymous function to execute - * @alias module:pbjs.que.push + * @alias module:$$PREBID_GLOBAL$$.que.push */ -pbjs.que.push = function (cmd) { +$$PREBID_GLOBAL$$.que.push = function (cmd) { if (typeof cmd === objectType_function) { try { cmd.call(); @@ -65,16 +65,16 @@ pbjs.que.push = function (cmd) { utils.logError('Error processing command :' + e.message); } } else { - utils.logError('Commands written into pbjs.que.push must wrapped in a function'); + utils.logError('Commands written into $$PREBID_GLOBAL$$.que.push must wrapped in a function'); } }; function processQue() { - for (var i = 0; i < pbjs.que.length; i++) { - if (typeof pbjs.que[i].called === objectType_undefined) { + for (var i = 0; i < $$PREBID_GLOBAL$$.que.length; i++) { + if (typeof $$PREBID_GLOBAL$$.que[i].called === objectType_undefined) { try { - pbjs.que[i].call(); - pbjs.que[i].called = true; + $$PREBID_GLOBAL$$.que[i].call(); + $$PREBID_GLOBAL$$.que[i].called = true; } catch (e) { utils.logError('Error processing command :', 'prebid.js', e); @@ -92,7 +92,7 @@ function timeOutBidders() { } function checkDefinedPlacement(id) { - var placementCodes = pbjs._bidsRequested.map(bidSet => bidSet.bids.map(bid => bid.placementCode)) + var placementCodes = $$PREBID_GLOBAL$$._bidsRequested.map(bidSet => bidSet.bids.map(bid => bid.placementCode)) .reduce(flatten) .filter(uniques); @@ -143,9 +143,9 @@ function getWinningBidTargeting() { })(); } - let winners = pbjs._bidsReceived.map(bid => bid.adUnitCode) + let winners = $$PREBID_GLOBAL$$._bidsReceived.map(bid => bid.adUnitCode) .filter(uniques) - .map(adUnitCode => pbjs._bidsReceived + .map(adUnitCode => $$PREBID_GLOBAL$$._bidsReceived .filter(bid => bid.adUnitCode === adUnitCode ? bid : null) .reduce(getHighestCpm, { @@ -177,7 +177,7 @@ function getWinningBidTargeting() { } function getDealTargeting() { - const dealTargeting = pbjs._bidsReceived.filter(bid => bid.dealId).map(bid => { + const dealTargeting = $$PREBID_GLOBAL$$._bidsReceived.filter(bid => bid.dealId).map(bid => { const dealKey = `hb_deal_${bid.bidderCode}`; return { [bid.adUnitCode]: CONSTANTS.TARGETING_KEYS.map(key => { @@ -195,7 +195,7 @@ function getDealTargeting() { function getBidLandscapeTargeting() { const standardKeys = CONSTANTS.TARGETING_KEYS; - return pbjs._bidsReceived.map(bid => { + return $$PREBID_GLOBAL$$._bidsReceived.map(bid => { if (bid.adserverTargeting) { return { [bid.adUnitCode]: standardKeys.map(key => { @@ -224,15 +224,15 @@ function getAllTargeting() { /** * This function returns the query string targeting parameters available at this moment for a given ad unit. Note that some bidder's response may not have been received if you call this function too quickly after the requests are sent. * @param {string} [adunitCode] adUnitCode to get the bid responses for - * @alias module:pbjs.getAdserverTargetingForAdUnitCodeStr + * @alias module:$$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr * @return {array} returnObj return bids array */ -pbjs.getAdserverTargetingForAdUnitCodeStr = function (adunitCode) { - utils.logInfo('Invoking pbjs.getAdserverTargetingForAdUnitCodeStr', arguments); +$$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr = function (adunitCode) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr', arguments); // call to retrieve bids array if (adunitCode) { - var res = pbjs.getAdserverTargetingForAdUnitCode(adunitCode); + var res = $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCode(adunitCode); return utils.transformAdServerTargetingObj(res); } else { utils.logMessage('Need to call getAdserverTargetingForAdUnitCodeStr with adunitCode'); @@ -244,8 +244,8 @@ pbjs.getAdserverTargetingForAdUnitCodeStr = function (adunitCode) { * @param adUnitCode {string} adUnitCode to get the bid responses for * @returns {object} returnObj return bids */ -pbjs.getAdserverTargetingForAdUnitCode = function (adUnitCode) { - utils.logInfo('Invoking pbjs.getAdserverTargetingForAdUnitCode', arguments); +$$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCode = function (adUnitCode) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCode', arguments); return getAllTargeting().filter(targeting => getKeys(targeting)[0] === adUnitCode) .map(targeting => { @@ -268,11 +268,11 @@ pbjs.getAdserverTargetingForAdUnitCode = function (adUnitCode) { /** * returns all ad server targeting for all ad units * @return {object} Map of adUnitCodes and targeting values [] - * @alias module:pbjs.getAdserverTargeting + * @alias module:$$PREBID_GLOBAL$$.getAdserverTargeting */ -pbjs.getAdserverTargeting = function () { - utils.logInfo('Invoking pbjs.getAdserverTargeting', arguments); +$$PREBID_GLOBAL$$.getAdserverTargeting = function () { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargeting', arguments); return getAllTargeting() .map(targeting => { return { @@ -293,15 +293,15 @@ pbjs.getAdserverTargeting = function () { /** * This function returns the bid responses at the given moment. - * @alias module:pbjs.getBidResponses + * @alias module:$$PREBID_GLOBAL$$.getBidResponses * @return {object} map | object that contains the bidResponses */ -pbjs.getBidResponses = function () { - utils.logInfo('Invoking pbjs.getBidResponses', arguments); +$$PREBID_GLOBAL$$.getBidResponses = function () { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getBidResponses', arguments); - return pbjs._bidsReceived.map(bid => bid.adUnitCode) - .filter(uniques).map(adUnitCode => pbjs._bidsReceived + return $$PREBID_GLOBAL$$._bidsReceived.map(bid => bid.adUnitCode) + .filter(uniques).map(adUnitCode => $$PREBID_GLOBAL$$._bidsReceived .filter(bid => bid.adUnitCode === adUnitCode)) .map(bids => { return { @@ -314,12 +314,12 @@ pbjs.getBidResponses = function () { /** * Returns bidResponses for the specified adUnitCode * @param {String} adUnitCode adUnitCode - * @alias module:pbjs.getBidResponsesForAdUnitCode + * @alias module:$$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode * @return {Object} bidResponse object */ -pbjs.getBidResponsesForAdUnitCode = function (adUnitCode) { - const bids = pbjs._bidsReceived.filter(bid => bid.adUnitCode === adUnitCode); +$$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode = function (adUnitCode) { + const bids = $$PREBID_GLOBAL$$._bidsReceived.filter(bid => bid.adUnitCode === adUnitCode); return { bids: bids }; @@ -327,10 +327,10 @@ pbjs.getBidResponsesForAdUnitCode = function (adUnitCode) { /** * Set query string targeting on all GPT ad units. - * @alias module:pbjs.setTargetingForGPTAsync + * @alias module:$$PREBID_GLOBAL$$.setTargetingForGPTAsync */ -pbjs.setTargetingForGPTAsync = function () { - utils.logInfo('Invoking pbjs.setTargetingForGPTAsync', arguments); +$$PREBID_GLOBAL$$.setTargetingForGPTAsync = function () { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.setTargetingForGPTAsync', arguments); if (!isGptPubadsDefined()) { utils.logError('window.googletag is not defined on the page'); return; @@ -341,11 +341,11 @@ pbjs.setTargetingForGPTAsync = function () { /** * Returns a bool if all the bids have returned or timed out - * @alias module:pbjs.allBidsAvailable + * @alias module:$$PREBID_GLOBAL$$.allBidsAvailable * @return {bool} all bids available */ -pbjs.allBidsAvailable = function () { - utils.logInfo('Invoking pbjs.allBidsAvailable', arguments); +$$PREBID_GLOBAL$$.allBidsAvailable = function () { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.allBidsAvailable', arguments); return bidmanager.bidsBackAll(); }; @@ -353,15 +353,15 @@ pbjs.allBidsAvailable = function () { * This function will render the ad (based on params) in the given iframe document passed through. Note that doc SHOULD NOT be the parent document page as we can't doc.write() asynchrounsly * @param {object} doc document * @param {string} id bid id to locate the ad - * @alias module:pbjs.renderAd + * @alias module:$$PREBID_GLOBAL$$.renderAd */ -pbjs.renderAd = function (doc, id) { - utils.logInfo('Invoking pbjs.renderAd', arguments); +$$PREBID_GLOBAL$$.renderAd = function (doc, id) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.renderAd', arguments); utils.logMessage('Calling renderAd with adId :' + id); if (doc && id) { try { //lookup ad by ad Id - var adObject = pbjs._bidsReceived.find(bid => bid.adId === id); + var adObject = $$PREBID_GLOBAL$$._bidsReceived.find(bid => bid.adId === id); if (adObject) { //emit 'bid won' event here events.emit(BID_WON, adObject); @@ -408,22 +408,22 @@ pbjs.renderAd = function (doc, id) { }; /** - * Remove adUnit from the pbjs configuration + * Remove adUnit from the $$PREBID_GLOBAL$$ configuration * @param {String} adUnitCode the adUnitCode to remove - * @alias module:pbjs.removeAdUnit + * @alias module:$$PREBID_GLOBAL$$.removeAdUnit */ -pbjs.removeAdUnit = function (adUnitCode) { - utils.logInfo('Invoking pbjs.removeAdUnit', arguments); +$$PREBID_GLOBAL$$.removeAdUnit = function (adUnitCode) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.removeAdUnit', arguments); if (adUnitCode) { - for (var i = 0; i < pbjs.adUnits.length; i++) { - if (pbjs.adUnits[i].code === adUnitCode) { - pbjs.adUnits.splice(i, 1); + for (var i = 0; i < $$PREBID_GLOBAL$$.adUnits.length; i++) { + if ($$PREBID_GLOBAL$$.adUnits[i].code === adUnitCode) { + $$PREBID_GLOBAL$$.adUnits.splice(i, 1); } } } }; -pbjs.clearAuction = function() { +$$PREBID_GLOBAL$$.clearAuction = function() { auctionRunning = false; utils.logMessage('Prebid auction cleared'); }; @@ -435,22 +435,22 @@ pbjs.clearAuction = function() { * @param adUnits * @param adUnitCodes */ -pbjs.requestBids = function ({ bidsBackHandler, timeout, adUnits, adUnitCodes }) { +$$PREBID_GLOBAL$$.requestBids = function ({ bidsBackHandler, timeout, adUnits, adUnitCodes }) { if (auctionRunning) { - utils.logError('Prebid Error: `pbjs.requestBids` was called while a previous auction was' + + utils.logError('Prebid Error: `$$PREBID_GLOBAL$$.requestBids` was called while a previous auction was' + ' still running. Resubmit this request.'); return; } else { auctionRunning = true; - pbjs._bidsRequested = []; - pbjs._bidsReceived = []; + $$PREBID_GLOBAL$$._bidsRequested = []; + $$PREBID_GLOBAL$$._bidsReceived = []; resetPresetTargeting(); } - const cbTimeout = timeout || pbjs.bidderTimeout; + const cbTimeout = timeout || $$PREBID_GLOBAL$$.bidderTimeout; - // use adUnits provided or from pbjs global - adUnits = adUnits || pbjs.adUnits; + // use adUnits provided or from $$PREBID_GLOBAL$$ global + adUnits = adUnits || $$PREBID_GLOBAL$$.adUnits; // if specific adUnitCodes filter adUnits for those codes if (adUnitCodes && adUnitCodes.length) { @@ -461,7 +461,7 @@ pbjs.requestBids = function ({ bidsBackHandler, timeout, adUnits, adUnitCodes }) bidmanager.addOneTimeCallback(bidsBackHandler); } - utils.logInfo('Invoking pbjs.requestBids', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments); if (!adUnits || adUnits.length === 0) { utils.logMessage('No adUnits configured. No bids requested.'); @@ -478,15 +478,15 @@ pbjs.requestBids = function ({ bidsBackHandler, timeout, adUnits, adUnitCodes }) * * Add adunit(s) * @param {Array|String} adUnitArr Array of adUnits or single adUnit Object. - * @alias module:pbjs.addAdUnits + * @alias module:$$PREBID_GLOBAL$$.addAdUnits */ -pbjs.addAdUnits = function (adUnitArr) { - utils.logInfo('Invoking pbjs.addAdUnits', arguments); +$$PREBID_GLOBAL$$.addAdUnits = function (adUnitArr) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.addAdUnits', arguments); if (utils.isArray(adUnitArr)) { //append array to existing - pbjs.adUnits.push.apply(pbjs.adUnits, adUnitArr); + $$PREBID_GLOBAL$$.adUnits.push.apply($$PREBID_GLOBAL$$.adUnits, adUnitArr); } else if (typeof adUnitArr === objectType_object) { - pbjs.adUnits.push(adUnitArr); + $$PREBID_GLOBAL$$.adUnits.push(adUnitArr); } }; @@ -505,8 +505,8 @@ pbjs.addAdUnits = function (adUnitArr) { * * Currently `bidWon` is the only event that accepts an `id` parameter. */ -pbjs.onEvent = function (event, handler, id) { - utils.logInfo('Invoking pbjs.onEvent', arguments); +$$PREBID_GLOBAL$$.onEvent = function (event, handler, id) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.onEvent', arguments); if (!utils.isFn(handler)) { utils.logError('The event handler provided is not a function and was not set on event "' + event + '".'); return; @@ -523,10 +523,10 @@ pbjs.onEvent = function (event, handler, id) { /** * @param {String} event the name of the event * @param {Function} handler a callback to remove from the event - * @param {String} id an identifier in the context of the event (see `pbjs.onEvent`) + * @param {String} id an identifier in the context of the event (see `$$PREBID_GLOBAL$$.onEvent`) */ -pbjs.offEvent = function (event, handler, id) { - utils.logInfo('Invoking pbjs.offEvent', arguments); +$$PREBID_GLOBAL$$.offEvent = function (event, handler, id) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.offEvent', arguments); if (id && !eventValidators[event].call(null, id)) { return; } @@ -538,11 +538,11 @@ pbjs.offEvent = function (event, handler, id) { * Add a callback event * @param {String} eventStr event to attach callback to Options: "allRequestedBidsBack" | "adUnitBidsBack" * @param {Function} func function to execute. Paramaters passed into the function: (bidResObj), [adUnitCode]); - * @alias module:pbjs.addCallback + * @alias module:$$PREBID_GLOBAL$$.addCallback * @returns {String} id for callback */ -pbjs.addCallback = function (eventStr, func) { - utils.logInfo('Invoking pbjs.addCallback', arguments); +$$PREBID_GLOBAL$$.addCallback = function (eventStr, func) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.addCallback', arguments); var id = null; if (!eventStr || !func || typeof func !== objectType_function) { utils.logError('error registering callback. Check method signature'); @@ -557,10 +557,10 @@ pbjs.addCallback = function (eventStr, func) { /** * Remove a callback event * //@param {string} cbId id of the callback to remove - * @alias module:pbjs.removeCallback + * @alias module:$$PREBID_GLOBAL$$.removeCallback * @returns {String} id for callback */ -pbjs.removeCallback = function (/* cbId */) { +$$PREBID_GLOBAL$$.removeCallback = function (/* cbId */) { //todo return null; }; @@ -571,8 +571,8 @@ pbjs.removeCallback = function (/* cbId */) { * @param {[type]} bidderCode [description] * @return {[type]} [description] */ -pbjs.registerBidAdapter = function (bidderAdaptor, bidderCode) { - utils.logInfo('Invoking pbjs.registerBidAdapter', arguments); +$$PREBID_GLOBAL$$.registerBidAdapter = function (bidderAdaptor, bidderCode) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.registerBidAdapter', arguments); try { adaptermanager.registerBidAdapter(bidderAdaptor(), bidderCode); } @@ -581,17 +581,17 @@ pbjs.registerBidAdapter = function (bidderAdaptor, bidderCode) { } }; -pbjs.bidsAvailableForAdapter = function (bidderCode) { - utils.logInfo('Invoking pbjs.bidsAvailableForAdapter', arguments); +$$PREBID_GLOBAL$$.bidsAvailableForAdapter = function (bidderCode) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.bidsAvailableForAdapter', arguments); - pbjs._bidsRequested.find(bidderRequest => bidderRequest.bidderCode === bidderCode).bids + $$PREBID_GLOBAL$$._bidsRequested.find(bidderRequest => bidderRequest.bidderCode === bidderCode).bids .map(bid => { return Object.assign(bid, bidfactory.createBid(1), { bidderCode, adUnitCode: bid.placementCode }); }) - .map(bid => pbjs._bidsReceived.push(bid)); + .map(bid => $$PREBID_GLOBAL$$._bidsReceived.push(bid)); }; /** @@ -599,8 +599,8 @@ pbjs.bidsAvailableForAdapter = function (bidderCode) { * @param {[type]} statusCode [description] * @return {[type]} [description] */ -pbjs.createBid = function (statusCode) { - utils.logInfo('Invoking pbjs.createBid', arguments); +$$PREBID_GLOBAL$$.createBid = function (statusCode) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.createBid', arguments); return bidfactory.createBid(statusCode); }; @@ -609,8 +609,8 @@ pbjs.createBid = function (statusCode) { * @param {[type]} adUnitCode [description] * @param {[type]} bid [description] */ -pbjs.addBidResponse = function (adUnitCode, bid) { - utils.logInfo('Invoking pbjs.addBidResponse', arguments); +$$PREBID_GLOBAL$$.addBidResponse = function (adUnitCode, bid) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.addBidResponse', arguments); bidmanager.addBidResponse(adUnitCode, bid); }; @@ -620,8 +620,8 @@ pbjs.addBidResponse = function (adUnitCode, bid) { * @param {Function} callback [description] * @return {[type]} [description] */ -pbjs.loadScript = function (tagSrc, callback, useCache) { - utils.logInfo('Invoking pbjs.loadScript', arguments); +$$PREBID_GLOBAL$$.loadScript = function (tagSrc, callback, useCache) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.loadScript', arguments); adloader.loadScript(tagSrc, callback, useCache); }; @@ -629,10 +629,10 @@ pbjs.loadScript = function (tagSrc, callback, useCache) { * Will enable sendinga prebid.js to data provider specified * @param {object} options object {provider : 'string', options : {}} */ -pbjs.enableAnalytics = function (options) { - utils.logInfo('Invoking pbjs.enableAnalytics', arguments); +$$PREBID_GLOBAL$$.enableAnalytics = function (options) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.enableAnalytics', arguments); if (!options) { - utils.logError('pbjs.enableAnalytics should be called with option {}', 'prebid.js'); + utils.logError('$$PREBID_GLOBAL$$.enableAnalytics should be called with option {}', 'prebid.js'); return; } @@ -652,22 +652,22 @@ pbjs.enableAnalytics = function (options) { /** * This will tell analytics that all bids received after are "timed out" */ -pbjs.sendTimeoutEvent = function () { - utils.logInfo('Invoking pbjs.sendTimeoutEvent', arguments); +$$PREBID_GLOBAL$$.sendTimeoutEvent = function () { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.sendTimeoutEvent', arguments); timeOutBidders(); }; -pbjs.aliasBidder = function (bidderCode, alias) { - utils.logInfo('Invoking pbjs.aliasBidder', arguments); +$$PREBID_GLOBAL$$.aliasBidder = function (bidderCode, alias) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.aliasBidder', arguments); if (bidderCode && alias) { adaptermanager.aliasBidAdapter(bidderCode, alias); } else { - utils.logError('bidderCode and alias must be passed as arguments', 'pbjs.aliasBidder'); + utils.logError('bidderCode and alias must be passed as arguments', '$$PREBID_GLOBAL$$.aliasBidder'); } }; -pbjs.setPriceGranularity = function (granularity) { - utils.logInfo('Invoking pbjs.setPriceGranularity', arguments); +$$PREBID_GLOBAL$$.setPriceGranularity = function (granularity) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.setPriceGranularity', arguments); if (!granularity) { utils.logError('Prebid Error: no value passed to `setPriceGranularity()`'); } else { @@ -675,7 +675,7 @@ pbjs.setPriceGranularity = function (granularity) { } }; -pbjs.enableSendAllBids = function () { +$$PREBID_GLOBAL$$.enableSendAllBids = function () { pb_sendAllBids = true; }; diff --git a/src/utils.js b/src/utils.js index d2a682de425..c9ba7ccf957 100644 --- a/src/utils.js +++ b/src/utils.js @@ -209,12 +209,12 @@ var errLogFn = (function (hasLogger) { }(hasConsoleLogger())); var debugTurnedOn = function () { - if (pbjs.logging === false && _loggingChecked === false) { - pbjs.logging = getParameterByName(CONSTANTS.DEBUG_MODE).toUpperCase() === 'TRUE'; + if ($$PREBID_GLOBAL$$.logging === false && _loggingChecked === false) { + $$PREBID_GLOBAL$$.logging = getParameterByName(CONSTANTS.DEBUG_MODE).toUpperCase() === 'TRUE'; _loggingChecked = true; } - return !!pbjs.logging; + return !!$$PREBID_GLOBAL$$.logging; }; exports.debugTurnedOn = debugTurnedOn; @@ -465,7 +465,7 @@ export function flatten(a, b) { } export function getBidRequest(id) { - return pbjs._bidsRequested.map(bidSet => bidSet.bids.find(bid => bid.bidId === id)).find(bid => bid); + return $$PREBID_GLOBAL$$._bidsRequested.map(bidSet => bidSet.bids.find(bid => bid.bidId === id)).find(bid => bid); } export function getKeys(obj) { @@ -478,7 +478,7 @@ export function getValue(obj, key) { export function getBidderCodes() { // this could memoize adUnits - return pbjs.adUnits.map(unit => unit.bids.map(bid => bid.bidder) + return $$PREBID_GLOBAL$$.adUnits.map(unit => unit.bids.map(bid => bid.bidder) .reduce(flatten, [])).reduce(flatten).filter(uniques); } diff --git a/webpack.conf.js b/webpack.conf.js index 999c33cd0cc..c976fda5582 100644 --- a/webpack.conf.js +++ b/webpack.conf.js @@ -44,7 +44,21 @@ module.exports = { } ] }) - } + }, + { + test: /\.js$/, + include: /(src|test)/, + loader: StringReplacePlugin.replace({ + replacements: [ + { + pattern: /\$\$PREBID_GLOBAL\$\$/g, + replacement: function (match, p1, offset, string) { + return prebid.globalVarName; + } + } + ] + }) + } ] }, plugins: [ From be14fc63f8db44bb271fb3cdf7e11c9ec50608eb Mon Sep 17 00:00:00 2001 From: Ned Stankus Date: Tue, 14 Jun 2016 11:13:01 -0700 Subject: [PATCH 2/5] Adding $$PREBID_GLOBAL$$ to integrationExamples. Adding integrationExamples to what gets string-replaced. --- .../gpt/creative_rendering.html | 8 +- .../gpt/gpt_aliasingBidder.html | 26 ++-- integrationExamples/gpt/pbjs_example_gpt.html | 30 ++-- .../gpt/pbjs_partial_refresh_gpt.html | 38 ++--- test/helpers/pbjs-test-only.js | 4 +- test/spec/adUnits_spec.js | 8 +- test/spec/adapters/wideorbit_spec.js | 16 +-- test/spec/aliasBidder_spec.js | 4 +- test/spec/api_spec.js | 64 ++++----- test/spec/bidmanager_spec.js | 26 ++-- test/spec/unit/pbjs_api_spec.js | 132 +++++++++--------- webpack.conf.js | 2 +- 12 files changed, 179 insertions(+), 179 deletions(-) diff --git a/integrationExamples/gpt/creative_rendering.html b/integrationExamples/gpt/creative_rendering.html index 7b972b86400..aef8b7f1654 100644 --- a/integrationExamples/gpt/creative_rendering.html +++ b/integrationExamples/gpt/creative_rendering.html @@ -1,16 +1,16 @@ - + "; - pbjs.renderAd(doc, bidId); + $$PREBID_GLOBAL$$.renderAd(doc, bidId); assert.ok(doc.write.calledWith(adResponse.ad), 'ad was written to doc'); assert.ok(doc.close.called, 'close method called'); }); it('should place the url inside an iframe on the doc', function () { adResponse.adUrl = "http://server.example.com/ad/ad.js"; - pbjs.renderAd(doc, bidId); + $$PREBID_GLOBAL$$.renderAd(doc, bidId); var iframe = '' assert.ok(doc.write.calledWith(iframe), 'url was written to iframe in doc'); }); it('should log an error when no ad or url', function () { - pbjs.renderAd(doc, bidId); + $$PREBID_GLOBAL$$.renderAd(doc, bidId); var error = 'Error trying to write ad. No ad for bid response id: ' + bidId; assert.ok(spyLogError.calledWith(error), 'expected error was logged'); }); @@ -268,7 +268,7 @@ describe('Unit: Prebid Module', function () { var error = { message: 'doc write error' }; doc.write = sinon.stub().throws(error); - pbjs.renderAd(doc, bidId); + $$PREBID_GLOBAL$$.renderAd(doc, bidId); var errorMessage = 'Error trying to write ad Id :' + bidId + ' to the page:' + error.message; assert.ok(spyLogError.calledWith(errorMessage), 'expected error was logged'); @@ -276,7 +276,7 @@ describe('Unit: Prebid Module', function () { it('should log an error when ad not found', function () { var fakeId = 99; - pbjs.renderAd(doc, fakeId); + $$PREBID_GLOBAL$$.renderAd(doc, fakeId); var error = 'Error trying to write ad. Cannot find ad by given id : ' + fakeId; assert.ok(spyLogError.calledWith(error), 'expected error was logged'); }); @@ -288,7 +288,7 @@ describe('Unit: Prebid Module', function () { var requestObj = { bidsBackHandler: function bidsBackHandlerCallback() {} }; - pbjs.requestBids(requestObj); + $$PREBID_GLOBAL$$.requestBids(requestObj); assert.ok(spyAddOneTimeCallBack.calledWith(requestObj.bidsBackHandler), 'called bidmanager.addOneTimeCallback'); bidmanager.addOneTimeCallback.restore(); @@ -297,14 +297,14 @@ describe('Unit: Prebid Module', function () { it('should log message when adUnits not configured', () => { const logMessageSpy = sinon.spy(utils, 'logMessage'); - const adUnitsBackup = pbjs.adUnits; + const adUnitsBackup = $$PREBID_GLOBAL$$.adUnits; - pbjs.adUnits = []; - pbjs.requestBids({}); + $$PREBID_GLOBAL$$.adUnits = []; + $$PREBID_GLOBAL$$.requestBids({}); assert.ok(logMessageSpy.calledWith('No adUnits configured. No bids requested.'), 'expected message was logged'); utils.logMessage.restore(); - pbjs.adUnits = adUnitsBackup; + $$PREBID_GLOBAL$$.adUnits = adUnitsBackup; resetAuction(); }); @@ -316,7 +316,7 @@ describe('Unit: Prebid Module', function () { timeout: 2000 }; - pbjs.requestBids(requestObj); + $$PREBID_GLOBAL$$.requestBids(requestObj); clock.tick(requestObj.timeout - 1); assert.ok(spyExecuteCallback.notCalled, 'bidmanager.executeCallback not called'); @@ -331,7 +331,7 @@ describe('Unit: Prebid Module', function () { it('should call callBids function on adaptermanager', () => { var spyCallBids = sinon.spy(adaptermanager, 'callBids'); - pbjs.requestBids({}); + $$PREBID_GLOBAL$$.requestBids({}); assert.ok(spyCallBids.called, 'called adaptermanager.callBids'); adaptermanager.callBids.restore(); resetAuction(); @@ -342,7 +342,7 @@ describe('Unit: Prebid Module', function () { it('should log an error when handler is not a function', () => { var spyLogError = sinon.spy(utils, 'logError'); var event = 'testEvent'; - pbjs.onEvent(event); + $$PREBID_GLOBAL$$.onEvent(event); assert.ok(spyLogError.calledWith('The event handler provided is not a function and was not set on event "' + event + '".'), 'expected error was logged'); utils.logError.restore(); @@ -351,7 +351,7 @@ describe('Unit: Prebid Module', function () { it('should log an error when id provided is not valid for event', () => { var spyLogError = sinon.spy(utils, 'logError'); var event = 'bidWon'; - pbjs.onEvent(event, Function, 'testId'); + $$PREBID_GLOBAL$$.onEvent(event, Function, 'testId'); assert.ok(spyLogError.calledWith('The id provided is not valid for event "' + event + '" and no handler was set.'), 'expected error was logged'); utils.logError.restore(); @@ -359,7 +359,7 @@ describe('Unit: Prebid Module', function () { it('should call events.on with valid parameters', () => { var spyEventsOn = sinon.spy(events, 'on'); - pbjs.onEvent('bidWon', Function); + $$PREBID_GLOBAL$$.onEvent('bidWon', Function); assert.ok(spyEventsOn.calledWith('bidWon', Function)); events.on.restore(); }); @@ -368,14 +368,14 @@ describe('Unit: Prebid Module', function () { describe('offEvent', () => { it('should return when id provided is not valid for event', () => { var spyEventsOff = sinon.spy(events, 'off'); - pbjs.offEvent('bidWon', Function, 'testId'); + $$PREBID_GLOBAL$$.offEvent('bidWon', Function, 'testId'); assert.ok(spyEventsOff.notCalled); events.off.restore(); }); it('should call events.off with valid parameters', () => { var spyEventsOff = sinon.spy(events, 'off'); - pbjs.offEvent('bidWon', Function); + $$PREBID_GLOBAL$$.offEvent('bidWon', Function); assert.ok(spyEventsOff.calledWith('bidWon', Function)); events.off.restore(); }); @@ -384,7 +384,7 @@ describe('Unit: Prebid Module', function () { describe('addCallback', () => { it('should log error and return null id when error registering callback', () => { var spyLogError = sinon.spy(utils, 'logError'); - var id = pbjs.addCallback('event', 'fakeFunction'); + var id = $$PREBID_GLOBAL$$.addCallback('event', 'fakeFunction'); assert.equal(id, null, 'id returned was null'); assert.ok(spyLogError.calledWith('error registering callback. Check method signature'), 'expected error was logged'); @@ -393,7 +393,7 @@ describe('Unit: Prebid Module', function () { it('should add callback to bidmanager', () => { var spyAddCallback = sinon.spy(bidmanager, 'addCallback'); - var id = pbjs.addCallback('event', Function); + var id = $$PREBID_GLOBAL$$.addCallback('event', Function); assert.ok(spyAddCallback.calledWith(id, Function, 'event'), 'called bidmanager.addCallback'); bidmanager.addCallback.restore(); }); @@ -401,7 +401,7 @@ describe('Unit: Prebid Module', function () { describe('removeCallback', () => { it('should return null', () => { - const id = pbjs.removeCallback(); + const id = $$PREBID_GLOBAL$$.removeCallback(); assert.equal(id, null); }); }); @@ -409,7 +409,7 @@ describe('Unit: Prebid Module', function () { describe('registerBidAdapter', () => { it('should register bidAdaptor with adaptermanager', () => { var registerBidAdapterSpy = sinon.spy(adaptermanager, 'registerBidAdapter'); - pbjs.registerBidAdapter(Function, 'biddercode'); + $$PREBID_GLOBAL$$.registerBidAdapter(Function, 'biddercode'); assert.ok(registerBidAdapterSpy.called, 'called adaptermanager.registerBidAdapter'); adaptermanager.registerBidAdapter.restore(); }); @@ -419,7 +419,7 @@ describe('Unit: Prebid Module', function () { var errorObject = {message: 'bidderAdaptor error'}; var bidderAdaptor = sinon.stub().throws(errorObject); - pbjs.registerBidAdapter(bidderAdaptor, 'biddercode'); + $$PREBID_GLOBAL$$.registerBidAdapter(bidderAdaptor, 'biddercode'); var errorMessage = 'Error registering bidder adapter : ' + errorObject.message; assert.ok(spyLogError.calledWith(errorMessage), 'expected error was caught'); @@ -430,9 +430,9 @@ describe('Unit: Prebid Module', function () { describe('bidsAvailableForAdapter', () => { it('should update requested bid with status set to available', () => { const bidderCode = 'appnexus'; - pbjs.bidsAvailableForAdapter(bidderCode); + $$PREBID_GLOBAL$$.bidsAvailableForAdapter(bidderCode); - const requestedBids = pbjs._bidsRequested.find(bid => bid.bidderCode === bidderCode); + const requestedBids = $$PREBID_GLOBAL$$._bidsRequested.find(bid => bid.bidderCode === bidderCode); requestedBids.bids.forEach(bid => { assert.equal(bid.bidderCode, bidderCode, 'bidderCode was set'); assert.equal(bid.statusMessage, 'Bid available', 'bid set as available'); @@ -443,11 +443,11 @@ describe('Unit: Prebid Module', function () { describe('createBid', () => { it('should return a bid object', () => { const statusCode = 1; - const bid = pbjs.createBid(statusCode); + const bid = $$PREBID_GLOBAL$$.createBid(statusCode); assert.isObject(bid, 'bid is an object'); assert.equal(bid.getStatusCode(), statusCode, 'bid has correct status'); - const defaultStatusBid = pbjs.createBid(); + const defaultStatusBid = $$PREBID_GLOBAL$$.createBid(); assert.isObject(defaultStatusBid, 'bid is an object'); assert.equal(defaultStatusBid.getStatusCode(), 0, 'bid has correct status'); }); @@ -457,9 +457,9 @@ describe('Unit: Prebid Module', function () { it('should call bidmanager.addBidResponse', () => { const addBidResponseStub = sinon.stub(bidmanager, 'addBidResponse'); const adUnitCode = 'testcode'; - const bid = pbjs.createBid(0); + const bid = $$PREBID_GLOBAL$$.createBid(0); - pbjs.addBidResponse(adUnitCode, bid); + $$PREBID_GLOBAL$$.addBidResponse(adUnitCode, bid); assert.ok(addBidResponseStub.calledWith(adUnitCode, bid), 'called bidmanager.addBidResponse'); bidmanager.addBidResponse.restore(); }); @@ -472,7 +472,7 @@ describe('Unit: Prebid Module', function () { const callback = Function; const useCache = false; - pbjs.loadScript(tagSrc, callback, useCache); + $$PREBID_GLOBAL$$.loadScript(tagSrc, callback, useCache); assert.ok(loadScriptSpy.calledWith(tagSrc, callback, useCache), 'called adloader.loadScript'); adloader.loadScript.restore(); }); @@ -490,8 +490,8 @@ describe('Unit: Prebid Module', function () { }); it('should log error when not passed options', () => { - const error = 'pbjs.enableAnalytics should be called with option {}'; - pbjs.enableAnalytics(); + const error = '$$PREBID_GLOBAL$$.enableAnalytics should be called with option {}'; + $$PREBID_GLOBAL$$.enableAnalytics(); assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); }); @@ -499,11 +499,11 @@ describe('Unit: Prebid Module', function () { const enableAnalyticsSpy = sinon.spy(ga, 'enableAnalytics'); let options = {'provider': 'ga'}; - pbjs.enableAnalytics(options); + $$PREBID_GLOBAL$$.enableAnalytics(options); assert.ok(enableAnalyticsSpy.calledWith({}), 'ga.enableAnalytics called with empty options object'); options['options'] = 'testoptions'; - pbjs.enableAnalytics(options); + $$PREBID_GLOBAL$$.enableAnalytics(options); assert.ok(enableAnalyticsSpy.calledWith(options.options), 'ga.enableAnalytics called with provided options'); ga.enableAnalytics.restore(); @@ -514,14 +514,14 @@ describe('Unit: Prebid Module', function () { const enableAnalyticsStub = sinon.stub(ga, 'enableAnalytics').throws(error); const options = {'provider': 'ga'}; - pbjs.enableAnalytics(options); + $$PREBID_GLOBAL$$.enableAnalytics(options); assert.ok(logErrorSpy.calledWith(error.message), 'expected error was caught'); ga.enableAnalytics.restore(); }); it('should return null for other providers', () => { const options = {'provider': 'other_provider'}; - const returnValue = pbjs.enableAnalytics(options); + const returnValue = $$PREBID_GLOBAL$$.enableAnalytics(options); assert.equal(returnValue, null, 'expected return value'); }); }); @@ -529,7 +529,7 @@ describe('Unit: Prebid Module', function () { describe('sendTimeoutEvent', () => { it('should emit BID_TIMEOUT for timed out bids', () => { const eventsEmitSpy = sinon.spy(events, 'emit'); - pbjs.sendTimeoutEvent(); + $$PREBID_GLOBAL$$.sendTimeoutEvent(); assert.ok(eventsEmitSpy.calledWith(CONSTANTS.EVENTS.BID_TIMEOUT), 'emitted events BID_TIMEOUT'); events.emit.restore(); }); @@ -541,7 +541,7 @@ describe('Unit: Prebid Module', function () { const bidderCode = 'testcode'; const alias = 'testalias'; - pbjs.aliasBidder(bidderCode, alias); + $$PREBID_GLOBAL$$.aliasBidder(bidderCode, alias); assert.ok(aliasBidAdapterSpy.calledWith(bidderCode, alias), 'called adaptermanager.aliasBidAdapterSpy'); adaptermanager.aliasBidAdapter.restore(); }); @@ -550,7 +550,7 @@ describe('Unit: Prebid Module', function () { const logErrorSpy = sinon.spy(utils, 'logError'); const error = 'bidderCode and alias must be passed as arguments'; - pbjs.aliasBidder(); + $$PREBID_GLOBAL$$.aliasBidder(); assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); utils.logError.restore(); }); @@ -561,7 +561,7 @@ describe('Unit: Prebid Module', function () { const logErrorSpy = sinon.spy(utils, 'logError'); const error = 'Prebid Error: no value passed to `setPriceGranularity()`'; - pbjs.setPriceGranularity(); + $$PREBID_GLOBAL$$.setPriceGranularity(); assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); utils.logError.restore(); }); @@ -570,7 +570,7 @@ describe('Unit: Prebid Module', function () { const setPriceGranularitySpy = sinon.spy(bidmanager, 'setPriceGranularity'); const granularity = 'low'; - pbjs.setPriceGranularity(granularity); + $$PREBID_GLOBAL$$.setPriceGranularity(granularity); assert.ok(setPriceGranularitySpy.called, 'called bidmanager.setPriceGranularity'); bidmanager.setPriceGranularity.restore(); }); diff --git a/webpack.conf.js b/webpack.conf.js index c976fda5582..4ce9e48c226 100644 --- a/webpack.conf.js +++ b/webpack.conf.js @@ -47,7 +47,7 @@ module.exports = { }, { test: /\.js$/, - include: /(src|test)/, + include: /(src|test|integrationExamples)/, loader: StringReplacePlugin.replace({ replacements: [ { From 61c2b957d8df0c0a858aaeff8f468109dcd6b0d0 Mon Sep 17 00:00:00 2001 From: Ned Stankus Date: Wed, 29 Jun 2016 10:24:40 -0600 Subject: [PATCH 3/5] Adding namespacing to new files. Some cleanup after merge. --- src/adapters/admedia.js | 2 +- src/adapters/kruxlink.js | 6 +++--- src/adapters/sekindo.js | 4 ++-- src/prebid.js | 10 +++++----- test/spec/unit/pbjs_api_spec.js | 18 +++++++++--------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/adapters/admedia.js b/src/adapters/admedia.js index b62633e807c..e3178a528df 100644 --- a/src/adapters/admedia.js +++ b/src/adapters/admedia.js @@ -70,7 +70,7 @@ var AdmediaAdapter = function AdmediaAdapter() { } //expose the callback to global object - pbjs.admediaHandler = function(response){ + $$PREBID_GLOBAL$$.admediaHandler = function(response){ var bidObject = {}; var callback_id = response.callback_id; var placementCode = ''; diff --git a/src/adapters/kruxlink.js b/src/adapters/kruxlink.js index 547f502478f..d29fa589e71 100644 --- a/src/adapters/kruxlink.js +++ b/src/adapters/kruxlink.js @@ -20,9 +20,9 @@ function _makeBidResponse(placementCode, bid) { function _makeCallback(id, placements) { var callback = '_kruxlink_' + id; - pbjs[callback] = function(response) { + $$PREBID_GLOBAL$$[callback] = function(response) { // Clean up our callback - delete pbjs[callback]; + delete $$PREBID_GLOBAL$$[callback]; // Add in the bid respones for (var i = 0; i < response.seatbid.length; i++) { @@ -42,7 +42,7 @@ function _makeCallback(id, placements) { } }; - return 'pbjs.' + callback; + return '$$PREBID_GLOBAL$$.' + callback; } function _callBids(params) { diff --git a/src/adapters/sekindo.js b/src/adapters/sekindo.js index b2e199ce71e..c0241b5cefb 100755 --- a/src/adapters/sekindo.js +++ b/src/adapters/sekindo.js @@ -26,7 +26,7 @@ SekindoAdapter = function SekindoAdapter() { } } - pbjs.sekindoCB = function(callbackId, response) { + $$PREBID_GLOBAL$$.sekindoCB = function(callbackId, response) { var bidObj = getBidRequest(callbackId); if (typeof (response) !== 'undefined' && typeof (response.cpm) !== 'undefined') { var bid = []; @@ -80,7 +80,7 @@ SekindoAdapter = function SekindoAdapter() { scriptSrc = utils.tryAppendQueryString(scriptSrc, 'pubUrl', pubUrl); scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbcb', callbackId); scriptSrc = utils.tryAppendQueryString(scriptSrc, 'dcpmflr', bidfloor); - scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbto', pbjs.bidderTimeout); + scriptSrc = utils.tryAppendQueryString(scriptSrc, 'hbto', $$PREBID_GLOBAL$$.bidderTimeout); scriptSrc = utils.tryAppendQueryString(scriptSrc, 'protocol', protocol); var html = ''; diff --git a/src/prebid.js b/src/prebid.js index 0569ad7f6b7..30549a611ae 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -199,7 +199,7 @@ function getDealTargeting() { * Get custom targeting keys for bids that have `alwaysUseBid=true`. */ function getAlwaysUseBidTargeting() { - return pbjs._bidsReceived.map(bid => { + return $$PREBID_GLOBAL$$._bidsReceived.map(bid => { if (bid.alwaysUseBid) { const standardKeys = CONSTANTS.TARGETING_KEYS; return { @@ -240,7 +240,7 @@ function getAllTargeting() { var targeting = getDealTargeting() .concat(getWinningBidTargeting()) .concat(getAlwaysUseBidTargeting()) - .concat(pbjs._sendAllBids ? getBidLandscapeTargeting() : []); + .concat($$PREBID_GLOBAL$$._sendAllBids ? getBidLandscapeTargeting() : []); //store a reference of the targeting keys targeting.map(adUnitCode => { @@ -484,8 +484,8 @@ $$PREBID_GLOBAL$$.requestBids = function ({ bidsBackHandler, timeout, adUnits, a return; } else { auctionRunning = true; - $$PREBID_GLOBAL$$._bidsRequested = []; - $$PREBID_GLOBAL$$._bidsReceived = []; + $$PREBID_GLOBAL$$._bidsRequested = []; + $$PREBID_GLOBAL$$._bidsReceived = []; } const cbTimeout = timeout || $$PREBID_GLOBAL$$.bidderTimeout; @@ -717,7 +717,7 @@ $$PREBID_GLOBAL$$.setPriceGranularity = function (granularity) { }; $$PREBID_GLOBAL$$.enableSendAllBids = function () { - $$PREBID_GLOBAL$$._sendAllBids = true; + $$PREBID_GLOBAL$$._sendAllBids = true; }; processQue(); diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 844060a6f6b..392b266c9d3 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -134,7 +134,7 @@ describe('Unit: Prebid Module', function () { }); it('should return correct targeting with default settings', () => { - var targeting = pbjs.getAdserverTargeting(); + var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(); var expected = { "/19968336/header-bid-tag-0": { "foobar": "300x250", @@ -155,8 +155,8 @@ describe('Unit: Prebid Module', function () { }); it('should return correct targeting with bid landscape targeting on', () => { - pbjs.enableSendAllBids(); - var targeting = pbjs.getAdserverTargeting(); + $$PREBID_GLOBAL$$.enableSendAllBids(); + var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(); var expected = getAdServerTargeting(); assert.deepEqual(targeting, expected); }); @@ -164,16 +164,16 @@ describe('Unit: Prebid Module', function () { it("should include a losing bid's custom ad targeting key when the bid has `alwaysUseBid` set to `true`", () => { // Let's make sure we're getting the expected losing bid. - assert.equal(pbjs._bidsReceived[0]['bidderCode'], 'triplelift'); - assert.equal(pbjs._bidsReceived[0]['cpm'], 0.112256); + assert.equal($$PREBID_GLOBAL$$._bidsReceived[0]['bidderCode'], 'triplelift'); + assert.equal($$PREBID_GLOBAL$$._bidsReceived[0]['cpm'], 0.112256); // Modify the losing bid to have `alwaysUseBid=true` and a custom `adserverTargeting` key. - pbjs._bidsReceived[0]['alwaysUseBid'] = true; - pbjs._bidsReceived[0]['adserverTargeting'] = { + $$PREBID_GLOBAL$$._bidsReceived[0]['alwaysUseBid'] = true; + $$PREBID_GLOBAL$$._bidsReceived[0]['adserverTargeting'] = { 'always_use_me': 'abc', }; - var targeting = pbjs.getAdserverTargeting(); + var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(); // Ensure targeting for both ad placements includes the custom key. assert.equal( @@ -288,7 +288,7 @@ describe('Unit: Prebid Module', function () { var slots = createSlotArray(); window.googletag.pubads().setSlots(slots); - pbjs.setTargetingForGPTAsync(config.adUnitCodes); + $$PREBID_GLOBAL$$.setTargetingForGPTAsync(config.adUnitCodes); var expected = [ [ From ca6b3fbb34ac8b560a4321634cad5836e3024d6d Mon Sep 17 00:00:00 2001 From: Ned Stankus Date: Wed, 6 Jul 2016 09:15:17 -0600 Subject: [PATCH 4/5] Replacing pbjs references in tests. --- test/fixtures/fixtures.js | 2 +- test/spec/unit/pbjs_api_spec.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/fixtures/fixtures.js b/test/fixtures/fixtures.js index f2a8577bbcf..e49875cbdd4 100644 --- a/test/fixtures/fixtures.js +++ b/test/fixtures/fixtures.js @@ -1053,7 +1053,7 @@ export function getAdUnits() { ] }; -// Ad server targeting when `pbjs.enableSendAllBids()` is called. +// Ad server targeting when `$$PREBID_GLOBAL$$.enableSendAllBids()` is called. export function getAdServerTargeting() { return { "/19968336/header-bid-tag-0": { diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 77002eb2a82..bea00225171 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -637,8 +637,8 @@ describe('Unit: Prebid Module', function () { // }); // // it('should log error when not passed options', () => { - // const error = 'pbjs.enableAnalytics should be called with option {}'; - // pbjs.enableAnalytics(); + // const error = '$$PREBID_GLOBAL$$.enableAnalytics should be called with option {}'; + // $$PREBID_GLOBAL$$.enableAnalytics(); // assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); // }); // @@ -646,11 +646,11 @@ describe('Unit: Prebid Module', function () { // const enableAnalyticsSpy = sinon.spy(ga, 'enableAnalytics'); // // let options = {'provider': 'ga'}; - // pbjs.enableAnalytics(options); + // $$PREBID_GLOBAL$$.enableAnalytics(options); // assert.ok(enableAnalyticsSpy.calledWith({}), 'ga.enableAnalytics called with empty options object'); // // options['options'] = 'testoptions'; - // pbjs.enableAnalytics(options); + // $$PREBID_GLOBAL$$.enableAnalytics(options); // assert.ok(enableAnalyticsSpy.calledWith(options.options), 'ga.enableAnalytics called with provided options'); // // ga.enableAnalytics.restore(); @@ -661,14 +661,14 @@ describe('Unit: Prebid Module', function () { // const enableAnalyticsStub = sinon.stub(ga, 'enableAnalytics').throws(error); // const options = {'provider': 'ga'}; // - // pbjs.enableAnalytics(options); + // $$PREBID_GLOBAL$$.enableAnalytics(options); // assert.ok(logErrorSpy.calledWith(error.message), 'expected error was caught'); // ga.enableAnalytics.restore(); // }); // // it('should return null for other providers', () => { // const options = {'provider': 'other_provider'}; - // const returnValue = pbjs.enableAnalytics(options); + // const returnValue = $$PREBID_GLOBAL$$.enableAnalytics(options); // assert.equal(returnValue, null, 'expected return value'); // }); //}); From b1f24be82dd3e2315a01c75a40beab4a46cad554 Mon Sep 17 00:00:00 2001 From: Ned Stankus Date: Wed, 6 Jul 2016 15:40:27 -0600 Subject: [PATCH 5/5] Whitespace cleanup. --- package.json | 2 +- webpack.conf.js | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index cf8cc8905ef..1179bb157b2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/prebid/Prebid.js.git" }, - "globalVarName": "pbjs", + "globalVarName": "pbjs", "analytics": [], "author": "the prebid.js contributors", "license": "Apache-2.0", diff --git a/webpack.conf.js b/webpack.conf.js index 1949b934b02..b5a13147490 100644 --- a/webpack.conf.js +++ b/webpack.conf.js @@ -50,20 +50,20 @@ module.exports = { ] }) }, - { - test: /\.js$/, - include: /(src|test|integrationExamples)/, - loader: StringReplacePlugin.replace({ - replacements: [ - { - pattern: /\$\$PREBID_GLOBAL\$\$/g, - replacement: function (match, p1, offset, string) { - return prebid.globalVarName; - } - } - ] - }) - } + { + test: /\.js$/, + include: /(src|test|integrationExamples)/, + loader: StringReplacePlugin.replace({ + replacements: [ + { + pattern: /\$\$PREBID_GLOBAL\$\$/g, + replacement: function (match, p1, offset, string) { + return prebid.globalVarName; + } + } + ] + }) + } ] }, plugins: [