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

CORE: allow to disable setting the pbjs global variable #9568

Merged
merged 12 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
'import'
],
globals: {
'$$PREBID_GLOBAL$$': false,
'BROWSERSTACK_USERNAME': false,
'BROWSERSTACK_KEY': false,
'FEATURES': 'readonly',
Expand Down
3 changes: 2 additions & 1 deletion modules/addefendBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getGlobal} from '../src/prebidGlobal.js';

const BIDDER_CODE = 'addefend';

Expand All @@ -16,7 +17,7 @@ export const spec = {
},
buildRequests: function(validBidRequests, bidderRequest) {
let bid = {
v: $$PREBID_GLOBAL$$.version,
v: getGlobal().version,
auctionId: false,
pageId: false,
gdpr_applies: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? bidderRequest.gdprConsent.gdprApplies : 'true',
Expand Down
3 changes: 2 additions & 1 deletion modules/adxcgAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ajax } from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import {getGlobal} from '../src/prebidGlobal.js';

/**
* Analytics adapter from adxcg.com
Expand Down Expand Up @@ -122,7 +123,7 @@ function send (data) {
ats: adxcgAnalyticsAdapter.context.auctionTimestamp,
aav: adxcgAnalyticsVersion,
iob: intersectionObserverAvailable(window) ? '1' : '0',
pbv: $$PREBID_GLOBAL$$.version,
pbv: getGlobal().version,
sz: window.screen.width + 'x' + window.screen.height
}
});
Expand Down
3 changes: 2 additions & 1 deletion modules/atsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CONSTANTS from '../src/constants.json';
import adaptermanager from '../src/adapterManager.js';
import {ajax} from '../src/ajax.js';
import {getStorageManager} from '../src/storageManager.js';
import {getGlobal} from '../src/prebidGlobal.js';

export const storage = getStorageManager();

Expand Down Expand Up @@ -352,7 +353,7 @@ atsAnalyticsAdapter.callHandler = function (evtype, args) {
let bidWonTimeout = atsAnalyticsAdapter.context.bidWonTimeout ? atsAnalyticsAdapter.context.bidWonTimeout : 2000;
let events = [];
setTimeout(() => {
let winningBids = $$PREBID_GLOBAL$$.getAllWinningBids();
let winningBids = getGlobal().getAllWinningBids();
logInfo('ATS Analytics - winning bids: ', winningBids)
// prepare format data for sending to analytics endpoint
if (handlerRequest.length) {
Expand Down
3 changes: 2 additions & 1 deletion modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {includes} from '../src/polyfill.js';
import {timedAuctionHook} from '../src/utils/perfMetrics.js';
import {registerOrtbProcessor, REQUEST} from '../src/pbjsORTB.js';
import {enrichFPD} from '../src/fpd/enrichment.js';
import {getGlobal} from '../src/prebidGlobal.js';

const DEFAULT_CMP = 'iab';
const DEFAULT_CONSENT_TIMEOUT = 10000;
Expand Down Expand Up @@ -368,7 +369,7 @@ export function setConsentConfig(config) {
}
}
if (!addedConsentHook) {
$$PREBID_GLOBAL$$.requestBids.before(requestBidsHook, 50);
getGlobal().requestBids.before(requestBidsHook, 50);
}
addedConsentHook = true;
gdprDataHandler.enable();
Expand Down
3 changes: 2 additions & 1 deletion modules/consentManagementGpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {gppDataHandler} from '../src/adapterManager.js';
import {includes} from '../src/polyfill.js';
import {timedAuctionHook} from '../src/utils/perfMetrics.js';
import { enrichFPD } from '../src/fpd/enrichment.js';
import {getGlobal} from '../src/prebidGlobal.js';

const DEFAULT_CMP = 'iab';
const DEFAULT_CONSENT_TIMEOUT = 10000;
Expand Down Expand Up @@ -362,7 +363,7 @@ export function setConsentConfig(config) {
logInfo('consentManagement.gpp module has been activated...');

if (!addedConsentHook) {
$$PREBID_GLOBAL$$.requestBids.before(requestBidsHook, 50);
getGlobal().requestBids.before(requestBidsHook, 50);
}
addedConsentHook = true;
gppDataHandler.enable();
Expand Down
12 changes: 7 additions & 5 deletions modules/express.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { logMessage, logWarn, logError, logInfo } from '../src/utils.js';
import {getGlobal} from '../src/prebidGlobal.js';

const MODULE_NAME = 'express';
const pbjsInstance = getGlobal();

/**
* Express Module
Expand All @@ -12,7 +14,7 @@ const MODULE_NAME = 'express';
*
* @param {Object[]} [adUnits = pbjs.adUnits] - an array of adUnits for express to operate on.
*/
$$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
pbjsInstance.express = function(adUnits = pbjsInstance.adUnits) {
logMessage('loading ' + MODULE_NAME);

if (adUnits.length === 0) {
Expand Down Expand Up @@ -138,10 +140,10 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
}

if (adUnits.length) {
$$PREBID_GLOBAL$$.requestBids({
pbjsInstance.requestBids({
adUnits: adUnits,
bidsBackHandler: function () {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
pbjsInstance.setTargetingForGPTAsync();
fGptRefresh.apply(pads(), [
adUnits.map(function (adUnit) {
return gptSlotCache[adUnit.code];
Expand All @@ -168,10 +170,10 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) {
}

if (adUnits.length) {
$$PREBID_GLOBAL$$.requestBids({
pbjsInstance.requestBids({
adUnits: adUnits,
bidsBackHandler: function () {
$$PREBID_GLOBAL$$.setTargetingForGPTAsync();
pbjsInstance.setTargetingForGPTAsync();
fGptRefresh.apply(pads(), [
adUnits.map(function (adUnit) {
return gptSlotCache[adUnit.code];
Expand Down
3 changes: 2 additions & 1 deletion modules/id5AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import adapterManager from '../src/adapterManager.js';
import { ajax } from '../src/ajax.js';
import { logInfo, logError } from '../src/utils.js';
import * as events from '../src/events.js';
import {getGlobal} from '../src/prebidGlobal.js';

const {
EVENTS: {
Expand Down Expand Up @@ -34,7 +35,7 @@ const FLUSH_EVENTS = [

const CONFIG_URL_PREFIX = 'https://api.id5-sync.com/analytics'
const TZ = new Date().getTimezoneOffset();
const PBJS_VERSION = $$PREBID_GLOBAL$$.version;
const PBJS_VERSION = getGlobal().version;
const ID5_REDACTED = '__ID5_REDACTED__';
const isArray = Array.isArray;

Expand Down
4 changes: 3 additions & 1 deletion modules/mabidderBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import {getGlobal} from '../src/prebidGlobal.js';

const BIDDER_CODE = 'mabidder';
export const baseUrl = 'https://prebid.ecdrsvc.com/bid';
export const spec = {
Expand Down Expand Up @@ -33,7 +35,7 @@ export const spec = {
url: baseUrl,
method: 'POST',
data: {
v: $$PREBID_GLOBAL$$.version,
v: getGlobal().version,
bids: bids,
url: bidderRequest.refererInfo.page || '',
referer: bidderRequest.refererInfo.ref || '',
Expand Down
3 changes: 2 additions & 1 deletion modules/marsmediaAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ajax} from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import {getGlobal} from '../src/prebidGlobal.js';

/****
* Mars Media Analytics
Expand Down Expand Up @@ -33,7 +34,7 @@ var marsmediaAnalyticsAdapter = Object.assign(adapter(
success: function() {},
error: function() {}
},
JSON.stringify({act: 'prebid_analytics', params: events, 'pbjs': $$PREBID_GLOBAL$$.getBidResponses(), ver: MARS_VERSION}),
JSON.stringify({act: 'prebid_analytics', params: events, 'pbjs': getGlobal().getBidResponses(), ver: MARS_VERSION}),
{
method: 'POST'
}
Expand Down
7 changes: 4 additions & 3 deletions modules/medianetAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {ajax} from '../src/ajax.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {AUCTION_COMPLETED, AUCTION_IN_PROGRESS, getPriceGranularity} from '../src/auction.js';
import {includes} from '../src/polyfill.js';
import {getGlobal} from '../src/prebidGlobal.js';

const analyticsType = 'endpoint';
const ENDPOINT = 'https://pb-logs.media.net/log?logid=kfk&evtid=prebid_analytics_events_client';
Expand All @@ -37,7 +38,7 @@ const PRICE_GRANULARITY = {

const MEDIANET_BIDDER_CODE = 'medianet';
// eslint-disable-next-line no-undef
const PREBID_VERSION = $$PREBID_GLOBAL$$.version;
const PREBID_VERSION = getGlobal().version;
const ERROR_CONFIG_JSON_PARSE = 'analytics_config_parse_fail';
const ERROR_CONFIG_FETCH = 'analytics_config_ajax_fail';
const ERROR_WINNING_BID_ABSENT = 'winning_bid_absent';
Expand Down Expand Up @@ -822,8 +823,8 @@ medianetAnalytics.enableAnalytics = function (configuration) {
logError('Media.net Analytics adapter: cid is required.');
return;
}
$$PREBID_GLOBAL$$.medianetGlobals = $$PREBID_GLOBAL$$.medianetGlobals || {};
$$PREBID_GLOBAL$$.medianetGlobals.analyticsEnabled = true;
getGlobal().medianetGlobals = getGlobal().medianetGlobals || {};
getGlobal().medianetGlobals.analyticsEnabled = true;

pageDetails = new PageDetail();

Expand Down
11 changes: 6 additions & 5 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {Renderer} from '../src/Renderer.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import {getGlobal} from '../src/prebidGlobal.js';

const BIDDER_CODE = 'medianet';
const BID_URL = 'https://prebid.media.net/rtb/prebid';
Expand Down Expand Up @@ -51,7 +52,7 @@ const aliases = [
{ code: 'aax', gvlid: 720 },
];

$$PREBID_GLOBAL$$.medianetGlobals = $$PREBID_GLOBAL$$.medianetGlobals || {};
getGlobal().medianetGlobals = getGlobal().medianetGlobals || {};

function getTopWindowReferrer() {
try {
Expand Down Expand Up @@ -177,15 +178,15 @@ function extParams(bidRequest, bidderRequests) {
const coppaApplies = !!(config.getConfig('coppa'));
return Object.assign({},
{ customer_id: params.cid },
{ prebid_version: $$PREBID_GLOBAL$$.version },
{ prebid_version: getGlobal().version },
{ gdpr_applies: gdprApplies },
(gdprApplies) && { gdpr_consent_string: gdpr.consentString || '' },
{ usp_applies: uspApplies },
uspApplies && { usp_consent_string: uspConsent || '' },
{coppa_applies: coppaApplies},
windowSize.w !== -1 && windowSize.h !== -1 && { screen: windowSize },
userId && { user_id: userId },
$$PREBID_GLOBAL$$.medianetGlobals.analyticsEnabled && { analytics: true },
getGlobal().medianetGlobals.analyticsEnabled && { analytics: true },
!isEmpty(sChain) && {schain: sChain}
);
}
Expand Down Expand Up @@ -358,7 +359,7 @@ function getLoggingData(event, data) {
params.evtid = 'projectevents';
params.project = 'prebid';
params.acid = deepAccess(data, '0.auctionId') || '';
params.cid = $$PREBID_GLOBAL$$.medianetGlobals.cid || '';
params.cid = getGlobal().medianetGlobals.cid || '';
params.crid = data.map((adunit) => deepAccess(adunit, 'params.0.crid') || adunit.adUnitCode).join('|');
params.adunit_count = data.length || 0;
params.dn = mnData.urlData.domain || '';
Expand Down Expand Up @@ -442,7 +443,7 @@ export const spec = {
return false;
}

Object.assign($$PREBID_GLOBAL$$.medianetGlobals, !$$PREBID_GLOBAL$$.medianetGlobals.cid && {cid: bid.params.cid});
Object.assign(getGlobal().medianetGlobals, !getGlobal().medianetGlobals.cid && {cid: bid.params.cid});

return true;
},
Expand Down
3 changes: 2 additions & 1 deletion modules/orbidderBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import {getGlobal} from '../src/prebidGlobal.js';

const storageManager = getStorageManager({bidderCode: 'orbidder'});

Expand Down Expand Up @@ -96,7 +97,7 @@ export const spec = {
method: 'POST',
options: { withCredentials: true },
data: {
v: $$PREBID_GLOBAL$$.version,
v: getGlobal().version,
pageUrl: referer,
bidId: bidRequest.bidId,
auctionId: bidRequest.auctionId,
Expand Down
3 changes: 2 additions & 1 deletion modules/pixfutureBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
transformBidderParamKeywords
} from '../src/utils.js';
import { auctionManager } from '../src/auctionManager.js';
import {getGlobal} from '../src/prebidGlobal.js';

const SOURCE = 'pbjs';
const storageManager = getStorageManager({bidderCode: 'pixfuture'});
Expand Down Expand Up @@ -132,7 +133,7 @@ export const spec = {
method: 'POST',
options: {withCredentials: true},
data: {
v: $$PREBID_GLOBAL$$.version,
v: getGlobal().version,
pageUrl: referer,
bidId: bidRequest.bidId,
auctionId: bidRequest.auctionId,
Expand Down
5 changes: 3 additions & 2 deletions modules/pubCommonId.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CONSTANTS from '../src/constants.json';
import { getStorageManager } from '../src/storageManager.js';
import {timedAuctionHook} from '../src/utils/perfMetrics.js';
import {VENDORLESS_GVLID} from '../src/consentHandler.js';
import {getGlobal} from '../src/prebidGlobal.js';

const storage = getStorageManager({moduleName: 'pubCommonId', gvlid: VENDORLESS_GVLID});

Expand Down Expand Up @@ -168,7 +169,7 @@ export function getPubcidConfig() { return pubcidConfig; }
*/

export const requestBidHook = timedAuctionHook('pubCommonId', function requestBidHook(next, config) {
let adUnits = config.adUnits || $$PREBID_GLOBAL$$.adUnits;
let adUnits = config.adUnits || getGlobal().adUnits;
let pubcid = null;

// Pass control to the next function if not enabled
Expand Down Expand Up @@ -292,7 +293,7 @@ export function initPubcid() {
(storage.hasLocalStorage() && readValue(OPTOUT_NAME, LOCAL_STORAGE));

if (!optout) {
$$PREBID_GLOBAL$$.requestBids.before(requestBidHook);
getGlobal().requestBids.before(requestBidHook);
}
}

Expand Down
3 changes: 2 additions & 1 deletion modules/pubxaiAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ajax } from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import {getGlobal} from '../src/prebidGlobal.js';

const emptyUrl = '';
const analyticsType = 'endpoint';
Expand Down Expand Up @@ -180,7 +181,7 @@ function send(data, status) {
search: {
auctionTimestamp: auctionTimestamp,
pubxaiAnalyticsVersion: pubxaiAnalyticsVersion,
prebidVersion: $$PREBID_GLOBAL$$.version
prebidVersion: getGlobal().version
}
});
if (status == 'bidwon') {
Expand Down
3 changes: 2 additions & 1 deletion modules/rivrAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ajax} from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import * as utils from '../src/utils.js';
import {getGlobal} from '../src/prebidGlobal.js';

const analyticsType = 'endpoint';

Expand All @@ -20,7 +21,7 @@ rivrAnalytics.originEnableAnalytics = rivrAnalytics.enableAnalytics;
// override enableAnalytics so we can get access to the config passed in from the page
rivrAnalytics.enableAnalytics = (config) => {
if (window.rivraddon && window.rivraddon.analytics) {
window.rivraddon.analytics.enableAnalytics(config, {utils, ajax, pbjsGlobalVariable: $$PREBID_GLOBAL$$});
window.rivraddon.analytics.enableAnalytics(config, {utils, ajax, pbjsGlobalVariable: getGlobal()});
rivrAnalytics.originEnableAnalytics(config);
}
};
Expand Down
3 changes: 2 additions & 1 deletion modules/snigelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import {deepAccess, isArray, isFn, isPlainObject} from '../src/utils.js';
import {hasPurpose1Consent} from '../src/utils/gpdr.js';
import {getGlobal} from '../src/prebidGlobal.js';

const BIDDER_CODE = 'snigel';
const GVLID = 1076;
Expand Down Expand Up @@ -33,7 +34,7 @@ export const spec = {
test: getTestFlag(),
devw: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
devh: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
version: $$PREBID_GLOBAL$$.version,
version: getGlobal().version,
gdprApplies: gdprApplies,
gdprConsentString: gdprApplies === true ? deepAccess(bidderRequest, 'gdprConsent.consentString') : undefined,
gdprConsentProv: gdprApplies === true ? deepAccess(bidderRequest, 'gdprConsent.addtlConsent') : undefined,
Expand Down
3 changes: 2 additions & 1 deletion modules/tappxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import {parseDomain} from '../src/refererDetection.js';
import {getGlobal} from '../src/prebidGlobal.js';

const BIDDER_CODE = 'tappx';
const GVLID_CODE = 628;
Expand Down Expand Up @@ -473,7 +474,7 @@ function buildOneRequest(validBidRequests, bidderRequest) {
payload.regs = regs;
// < Payload

let pbjsv = ($$PREBID_GLOBAL$$.version !== null) ? encodeURIComponent($$PREBID_GLOBAL$$.version) : -1;
let pbjsv = (getGlobal().version !== null) ? encodeURIComponent(getGlobal().version) : -1;

return {
method: 'POST',
Expand Down
Loading