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

Feature/custom namespacing #409

Merged
merged 8 commits into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"before": true,
"after": true,
"exports": true,
"pbjs": true,
"$$PREBID_GLOBAL$$": true,
"pbjsTestOnly": true,
"assert": false,
"expect": false,
Expand Down
8 changes: 4 additions & 4 deletions integrationExamples/gpt/creative_rendering.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!-- #1 deprecated method - use preferred method below instead-->
<script>
try{ window.top.pbjs.renderAd(document, '%%PATTERN:hb_adid%%'); } catch(e) {/*ignore*/}
try{ window.top.$$PREBID_GLOBAL$$.renderAd(document, '%%PATTERN:hb_adid%%'); } catch(e) {/*ignore*/}
</script>

<!-- #2 preferred method for showing ad - handles cases when pbjs is not in the top window -->
<!-- #2 preferred method for showing ad - handles cases when $$PREBID_GLOBAL$$ is not in the top window -->
<script>
var w = window;
for (i = 0; i < 10; i++) {
w = w.parent;
if (w.pbjs) {
if (w.$$PREBID_GLOBAL$$) {
try {
w.pbjs.renderAd(document, '%%PATTERN:hb_adid%%');
w.$$PREBID_GLOBAL$$.renderAd(document, '%%PATTERN:hb_adid%%');
break;
} catch (e) {
continue;
Expand Down
26 changes: 13 additions & 13 deletions integrationExamples/gpt/gpt_aliasingBidder.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
googletag.pubads().disableInitialLoad();
});

/* pbjs.initAdserver will be called either when all bids are back, or
/* $$PREBID_GLOBAL$$.initAdserver will be called either when all bids are back, or
when the timeout is reached.
*/
function initAdserver() {
if (pbjs.initAdserverSet) return;
if ($$PREBID_GLOBAL$$.initAdserverSet) return;

googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
pbjs.initAdserverSet = true;
$$PREBID_GLOBAL$$.initAdserverSet = true;
}

// Load GPT when timeout is reached.
setTimeout(initAdserver, PREBID_TIMEOUT);

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var $$PREBID_GLOBAL$$ = $$PREBID_GLOBAL$$ || {};
$$PREBID_GLOBAL$$.que = $$PREBID_GLOBAL$$.que || [];

// Load the Prebid Javascript Library Async. We recommend loading it immediately after
// the initAdserver() and setTimeout functions.
Expand All @@ -54,7 +54,7 @@
node.parentNode.insertBefore(gads, node);
})();

pbjs.que.push(function () {
$$PREBID_GLOBAL$$.que.push(function () {
var adUnits = [
{
code: 'div-gpt-ad-12345678-0',
Expand Down Expand Up @@ -83,17 +83,17 @@
];

//add the adUnits
pbjs.addAdUnits(adUnits);
$$PREBID_GLOBAL$$.addAdUnits(adUnits);

/* Alias Bidders (existingBidderCode, newBidderCode) <------ New Feature
aliased bidders will use the existing adapter and require the same params as the existing adapter. The only change is the bidderCode is updated.
*/
pbjs.aliasBidder('appnexus', 'brealtime')
$$PREBID_GLOBAL$$.aliasBidder('appnexus', 'brealtime')

/* Request bids for the added ad units. If adUnits or adUnitCodes are
not specified, the function will request bids for all added ad units.
*/
pbjs.requestBids({
$$PREBID_GLOBAL$$.requestBids({

/* The bidsBack function will be called when either timeout is
reached, or when all bids come back, whichever happens sooner.
Expand Down Expand Up @@ -177,8 +177,8 @@ <h2>Prebid.js Test</h2>

ga('create', 'XXXXXX', 'auto');
//Send data from prebid.js automatically
pbjs.que.push(function () {
pbjs.enableAnalytics({
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.enableAnalytics({
provider: 'ga',
options: {
global: 'ga', // <string> name of GA global. Default is 'ga'
Expand Down
30 changes: 15 additions & 15 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
googletag.pubads().disableInitialLoad();
});

/* pbjs.initAdserver will be called either when all bids are back, or
/* $$PREBID_GLOBAL$$.initAdserver will be called either when all bids are back, or
when the timeout is reached.
*/
function initAdserver() {
if (pbjs.initAdserverSet) return;
if ($$PREBID_GLOBAL$$.initAdserverSet) return;

googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
});
googletag.pubads().refresh();
});
pbjs.initAdserverSet = true;
$$PREBID_GLOBAL$$.initAdserverSet = true;
}

// Load GPT when timeout is reached.
setTimeout(initAdserver, PREBID_TIMEOUT);

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var $$PREBID_GLOBAL$$ = $$PREBID_GLOBAL$$ || {};
$$PREBID_GLOBAL$$.que = $$PREBID_GLOBAL$$.que || [];

// Load the Prebid Javascript Library Async. We recommend loading it immediately after
// the initAdserver() and setTimeout functions.
Expand All @@ -55,12 +55,12 @@
node.parentNode.insertBefore(gads, node);
})();

pbjs.que.push(function () {
$$PREBID_GLOBAL$$.que.push(function () {

/* 1. Register bidder tag Ids

Registers the bidder tags for your ad units. Once the prebid.js
library loads, it reads the pbjs.adUnits object and sends out
library loads, it reads the $$PREBID_GLOBAL$$.adUnits object and sends out
bid requests. Find the complete reference on bidders at
http://prebid.org/bidders.html.

Expand Down Expand Up @@ -287,17 +287,17 @@
];

//add the adUnits
pbjs.addAdUnits(adUnits);
$$PREBID_GLOBAL$$.addAdUnits(adUnits);

//register a callback handler
pbjs.addCallback('adUnitBidsBack', function (adUnitCode) {
$$PREBID_GLOBAL$$.addCallback('adUnitBidsBack', function (adUnitCode) {
console.debug('ad unit bids back for:', adUnitCode);
});

/* Request bids for the added ad units. If adUnits or adUnitCodes are
not specified, the function will request bids for all added ad units.
*/
pbjs.requestBids({
$$PREBID_GLOBAL$$.requestBids({

/* The bidsBack function will be called when either timeout is
reached, or when all bids come back, whichever happens sooner.
Expand Down Expand Up @@ -337,7 +337,7 @@

*/

pbjs.bidderSettings = {
$$PREBID_GLOBAL$$.bidderSettings = {
standard: {
adserverTargeting: [
{
Expand Down Expand Up @@ -439,8 +439,8 @@ <h2>Prebid.js Test</h2>
ga('create', 'XXXXXX', 'auto');

//Send data from prebid.js automatically
pbjs.que.push(function () {
pbjs.enableAnalytics({
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.enableAnalytics({
provider: 'ga',
options: {
global: 'ga', // <string> name of GA global. Default is 'ga'
Expand Down
38 changes: 19 additions & 19 deletions integrationExamples/gpt/pbjs_partial_refresh_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
googletag.pubads().disableInitialLoad();
});

/* pbjs.initAdserver will be called either when all bids are back, or
/* $$PREBID_GLOBAL$$.initAdserver will be called either when all bids are back, or
when the timeout is reached.
*/
function initAdserver() {
if (pbjs.initAdserverSet) return;
if ($$PREBID_GLOBAL$$.initAdserverSet) return;

googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
pbjs.initAdserverSet = true;
$$PREBID_GLOBAL$$.initAdserverSet = true;
}

// Load GPT when timeout is reached.
setTimeout(initAdserver, PREBID_TIMEOUT);

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var $$PREBID_GLOBAL$$ = $$PREBID_GLOBAL$$ || {};
$$PREBID_GLOBAL$$.que = $$PREBID_GLOBAL$$.que || [];

// Load the Prebid Javascript Library Async. We recommend loading it immediately after
// the initAdserver() and setTimeout functions.
Expand All @@ -43,12 +43,12 @@
target.insertBefore(pbs, target.firstChild);
})();

pbjs.que.push(function () {
$$PREBID_GLOBAL$$.que.push(function () {

/* 1. Register bidder tag Ids

Registers the bidder tags for your ad units. Once the prebid.js
library loads, it reads the pbjs.adUnits object and sends out
library loads, it reads the $$PREBID_GLOBAL$$.adUnits object and sends out
bid requests. Find the complete reference on bidders at
http://prebid.org/bidders.html.

Expand Down Expand Up @@ -137,17 +137,17 @@
];

//add the adUnits
pbjs.addAdUnits(adUnits);
$$PREBID_GLOBAL$$.addAdUnits(adUnits);

//register a callback handler
pbjs.addCallback('adUnitBidsBack', function (adUnitCode) {
$$PREBID_GLOBAL$$.addCallback('adUnitBidsBack', function (adUnitCode) {
console.log('ad unit bids back for : ' + adUnitCode);
});

/* Request bids for the added ad units. If adUnits or adUnitCodes are
not specified, the function will request bids for all added ad units.
*/
pbjs.requestBids({
$$PREBID_GLOBAL$$.requestBids({

/* The bidsBack function will be called when either timeout is
reached, or when all bids come back, whichever happens sooner.
Expand Down Expand Up @@ -187,7 +187,7 @@

*/

pbjs.bidderSettings = {
$$PREBID_GLOBAL$$.bidderSettings = {
standard: {
adserverTargeting: [
{
Expand Down Expand Up @@ -230,25 +230,25 @@
});

function refreshBid1() {
pbjs.que.push(function () {
pbjs.requestBids({
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.requestBids({
timeout: PREBID_TIMEOUT,
adUnitCodes: ['/9968336/header-bid-tag-0'],
bidsBackHandler: function () {
pbjs.setTargetingForGPTAsync(['/9968336/header-bid-tag-0']);
$$PREBID_GLOBAL$$.setTargetingForGPTAsync(['/9968336/header-bid-tag-0']);
googletag.pubads().refresh([rightSlot]);
}
});
});
}

function refreshBid2() {
pbjs.que.push(function () {
pbjs.requestBids({
$$PREBID_GLOBAL$$.que.push(function () {
$$PREBID_GLOBAL$$.requestBids({
timeout: PREBID_TIMEOUT,
adUnitCodes: ['/9968336/header-bid-tag1'],
bidsBackHandler: function () {
pbjs.setTargetingForGPTAsync(['/9968336/header-bid-tag1']);
$$PREBID_GLOBAL$$.setTargetingForGPTAsync(['/9968336/header-bid-tag1']);
googletag.pubads().refresh([topSlot]);
}
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "git",
"url": "https://github.com/prebid/Prebid.js.git"
},
"globalVarName": "pbjs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: please soft tabs (spaces)

"analytics": [],
"author": "the prebid.js contributors",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.callBids = ({ adUnits, cbTimeout }) => {
timeout: cbTimeout
};
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);
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/aardvark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions src/adapters/adform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('&'));
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/admedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/appnexus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -142,7 +142,7 @@ AppNexusAdapter = function AppNexusAdapter() {
}

//expose the callback to the global object:
pbjs.handleAnCB = function (jptResponseObj) {
$$PREBID_GLOBAL$$.handleAnCB = function (jptResponseObj) {

var bidCode;

Expand Down
Loading