Skip to content

Commit

Permalink
Core: New activity control - load external script (prebid#12207)
Browse files Browse the repository at this point in the history
* prebid#11010 New activity control - load external script

* improvements

* adding module type to load external script

* update loadScript stub

* Swap moduleType/moduleCode for consistency

---------

Co-authored-by: Marcin Komorski <[email protected]>
Co-authored-by: Marcin Komorski <[email protected]>
Co-authored-by: Demetrio Girardi <[email protected]>
  • Loading branch information
4 people authored Oct 10, 2024
1 parent 169638e commit 9965e0e
Show file tree
Hide file tree
Showing 37 changed files with 102 additions and 50 deletions.
3 changes: 2 additions & 1 deletion modules/51DegreesRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';
import {loadExternalScript} from '../src/adloader.js';
import {submodule} from '../src/hook.js';
import {
Expand Down Expand Up @@ -263,7 +264,7 @@ export const getBidRequestData = (reqBidsConfigObj, callback, moduleConfig, user
}

// Inject 51Degrees script, get device data and merge it into the ORTB2 object
loadExternalScript(scriptURL, MODULE_NAME, () => {
loadExternalScript(scriptURL, MODULE_TYPE_RTD, MODULE_NAME, () => {
logMessage('Successfully injected 51Degrees script');
const fod = /** @type {Object} */ (window.fod);
// Convert and merge device data in the callback
Expand Down
2 changes: 1 addition & 1 deletion modules/a1MediaRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function loadLbScript(tagname) {
linkback.l = true;

const scriptUrl = `${SCRIPT_URL}/${tagname}`;
loadExternalScript(scriptUrl, MODULE_NAME);
loadExternalScript(scriptUrl, MODULE_TYPE_RTD, MODULE_NAME);
}
}

Expand Down
3 changes: 2 additions & 1 deletion modules/aaxBlockmeterRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {isEmptyStr, isStr, logError, isFn, logWarn} from '../src/utils.js';
import {submodule} from '../src/hook.js';
import { loadExternalScript } from '../src/adloader.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

export const _config = {
MODULE: 'aaxBlockmeter',
Expand Down Expand Up @@ -28,7 +29,7 @@ function loadBlockmeter(_rtdConfig) {
}

const scriptUrl = `https://${url}&${params.join('&')}`;
loadExternalScript(scriptUrl, _config.MODULE);
loadExternalScript(scriptUrl, MODULE_TYPE_RTD, _config.MODULE);
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ function loadAdagioScript(config) {
return;
}

loadExternalScript(SCRIPT_URL, SUBMODULE_NAME, undefined, undefined, { id: `adagiojs-${getUniqueIdentifierStr()}`, 'data-pid': config.params.organizationId });
loadExternalScript(SCRIPT_URL, MODULE_TYPE_RTD, SUBMODULE_NAME, undefined, undefined, {
id: `adagiojs-${getUniqueIdentifierStr()}`,
'data-pid': config.params.organizationId
});
});
}

Expand Down
3 changes: 2 additions & 1 deletion modules/adlooxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
parseUrl
} from '../src/utils.js';
import {getGptSlotInfoForAdUnitCode} from '../libraries/gptUtils/gptUtils.js';
import { MODULE_TYPE_ANALYTICS } from '../src/activities/modules.js';

const MODULE = 'adlooxAnalyticsAdapter';

Expand Down Expand Up @@ -262,7 +263,7 @@ analyticsAdapter[`handle_${EVENTS.BID_WON}`] = function(bid) {
[ 'creatype', '%%creatype%%' ]
]);

loadExternalScript(analyticsAdapter.url(`${analyticsAdapter.context.js}#`, params, bid), 'adloox');
loadExternalScript(analyticsAdapter.url(`${analyticsAdapter.context.js}#`, params, bid), MODULE_TYPE_ANALYTICS, 'adloox');
}

adapterManager.registerAnalyticsAdapter({
Expand Down
2 changes: 1 addition & 1 deletion modules/airgridRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function attachScriptTagToDOM(rtdConfig) {
edktInitializor.apiKey = rtdConfig.params.apiKey;
edktInitializor.invoked = true;
const moduleSrc = getModuleUrl(rtdConfig.params.accountId);
loadExternalScript(moduleSrc, SUBMODULE_NAME);
loadExternalScript(moduleSrc, MODULE_TYPE_RTD, SUBMODULE_NAME);
}
}

Expand Down
3 changes: 2 additions & 1 deletion modules/arcspanRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { submodule } from '../src/hook.js';
import { mergeDeep } from '../src/utils.js';
import {loadExternalScript} from '../src/adloader.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
Expand Down Expand Up @@ -28,7 +29,7 @@ function init(config, userConsent) {
} else {
scriptUrl = 'https://silo' + config.params.silo + '.p7cloud.net/as.js';
}
loadExternalScript(scriptUrl, SUBMODULE_NAME);
loadExternalScript(scriptUrl, MODULE_TYPE_RTD, SUBMODULE_NAME);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/azerionedgeRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getScriptURL(config) {
*/
export function attachScript(config, userConsent) {
const script = getScriptURL(config);
loadExternalScript(script, SUBREAL_TIME_MODULE, () => {
loadExternalScript(script, MODULE_TYPE_RTD, SUBREAL_TIME_MODULE, () => {
if (typeof window.azerionPublisherAudiences === 'function') {
const publisherConfig = config.params?.process || {};
window.azerionPublisherAudiences({
Expand Down
3 changes: 2 additions & 1 deletion modules/brandmetricsRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { deepAccess, deepSetValue, logError, mergeDeep, generateUUID } from '../
import { loadExternalScript } from '../src/adloader.js';
import * as events from '../src/events.js';
import { EVENTS } from '../src/constants.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
Expand Down Expand Up @@ -140,7 +141,7 @@ function initializeBrandmetrics(scriptId) {
const file = scriptId + '.js'
const url = path + file

loadExternalScript(url, MODULE_CODE)
loadExternalScript(url, MODULE_TYPE_RTD, MODULE_CODE)
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/browsiRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let _ic = {};
* @param {Object} data
*/
export function addBrowsiTag(data) {
let script = loadExternalScript(data.u, 'browsi');
let script = loadExternalScript(data.u, MODULE_TYPE_RTD, 'browsi');
script.async = true;
script.setAttribute('data-sitekey', _moduleParams.siteKey);
script.setAttribute('data-pubkey', _moduleParams.pubKey);
Expand Down
3 changes: 2 additions & 1 deletion modules/cleanioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { loadExternalScript } from '../src/adloader.js';
import { logError, generateUUID, insertElement } from '../src/utils.js';
import * as events from '../src/events.js';
import { EVENTS } from '../src/constants.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
Expand Down Expand Up @@ -58,7 +59,7 @@ function pageInitStepPreloadScript(scriptURL) {
* @param {string} scriptURL The script URL to add to the page for protection
*/
function pageInitStepProtectPage(scriptURL) {
loadExternalScript(scriptURL, 'clean.io');
loadExternalScript(scriptURL, MODULE_TYPE_RTD, 'clean.io');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion modules/confiantRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { logError, generateUUID } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import * as events from '../src/events.js';
import { EVENTS } from '../src/constants.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/**
* Injects the Confiant Inc. configuration script into the page, based on proprtyId provided
Expand All @@ -21,7 +22,8 @@ import { EVENTS } from '../src/constants.js';
function injectConfigScript(propertyId) {
const scriptSrc = `https://cdn.confiant-integrations.net/${propertyId}/gpt_and_prebid/config.js`;

loadExternalScript(scriptSrc, 'confiant', () => {});
loadExternalScript(scriptSrc, MODULE_TYPE_RTD, 'confiant', () => {
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/contxtfulRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function initCustomer(config) {
});

addConnectorEventListener(customer, config);
loadExternalScript(CONNECTOR_URL, MODULE_NAME);
loadExternalScript(CONNECTOR_URL, MODULE_TYPE_RTD, MODULE_NAME);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/dynamicAdBoostRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { submodule } from '../src/hook.js'
import { loadExternalScript } from '../src/adloader.js';
import { getGlobal } from '../src/prebidGlobal.js';
import { deepAccess, deepSetValue, isEmptyStr } from '../src/utils.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
Expand Down Expand Up @@ -72,7 +73,7 @@ function loadLmScript(keyId) {
let viewableAdUnits = Object.keys(dynamicAdBoostAdUnits);
let viewableAdUnitsCSV = viewableAdUnits.join(',');
const scriptUrl = `${SCRIPT_URL}/${keyId}.js?viewableAdUnits=${viewableAdUnitsCSV}`;
loadExternalScript(scriptUrl, MODULE_NAME);
loadExternalScript(scriptUrl, MODULE_TYPE_RTD, MODULE_NAME);
observer.disconnect();
}

Expand Down
2 changes: 1 addition & 1 deletion modules/ftrackIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const ftrackIdSubmodule = {
}

// Creates an async script element and appends it to the document
loadExternalScript(config.params.url, MODULE_NAME);
loadExternalScript(config.params.url, MODULE_TYPE_UID, MODULE_NAME);
}
};
},
Expand Down
5 changes: 3 additions & 2 deletions modules/geoedgeRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { EVENTS } from '../src/constants.js';
import { loadExternalScript } from '../src/adloader.js';
import { auctionManager } from '../src/auctionManager.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
Expand Down Expand Up @@ -108,7 +109,7 @@ export function preloadClient(key) {
insertElement(iframe);
iframe.contentWindow.grumi = getInitialParams(key);
let url = getClientUrl(key);
loadExternalScript(url, SUBMODULE_NAME, markAsLoaded, iframe.contentDocument);
loadExternalScript(url, MODULE_TYPE_RTD, SUBMODULE_NAME, markAsLoaded, iframe.contentDocument);
}

/**
Expand Down Expand Up @@ -259,7 +260,7 @@ function fireBillableEventsForApplicableBids(params) {
function setupInPage(params) {
window.grumi = params;
window.grumi.fromPrebid = true;
loadExternalScript(getInPageUrl(params.key), SUBMODULE_NAME);
loadExternalScript(getInPageUrl(params.key), MODULE_TYPE_RTD, SUBMODULE_NAME);
}

function init(config, userConsent) {
Expand Down
2 changes: 1 addition & 1 deletion modules/hadronRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
paramOrDefault(hadronIdUrl, HADRON_ID_DEFAULT_URL, userIds),
`partner_id=${partnerId}&_it=prebid`
);
loadExternalScript(scriptUrl, 'hadron', () => {
loadExternalScript(scriptUrl, MODULE_TYPE_RTD, 'hadron', () => {
logInfo(LOG_PREFIX, 'hadronIdTag loaded', scriptUrl);
})
}
Expand Down
2 changes: 1 addition & 1 deletion modules/id5IdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ async function loadExternalModule(url) {
resolve();
} else {
try {
loadExternalScript(url, 'id5', resolve);
loadExternalScript(url, MODULE_TYPE_UID, 'id5', resolve);
} catch (error) {
reject(error);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {ortbConverter} from '../libraries/ortbConverter/converter.js';
*/
// eslint-disable-next-line no-restricted-imports
import {loadExternalScript} from '../src/adloader.js';
import { MODULE_TYPE_BIDDER } from '../src/activities/modules.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -396,7 +397,7 @@ const ID_RAZR = {
ns.q.push(data);

if (!ns.loaded) {
loadExternalScript(ID_RAZR.RENDERER_URL, BIDDER_CODE);
loadExternalScript(ID_RAZR.RENDERER_URL, MODULE_TYPE_BIDDER, BIDDER_CODE);
}
});

Expand Down
3 changes: 2 additions & 1 deletion modules/justIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as utils from '../src/utils.js'
import { submodule } from '../src/hook.js'
import { loadExternalScript } from '../src/adloader.js'
import {includes} from '../src/polyfill.js';
import { MODULE_TYPE_UID } from '../src/activities/modules.js';

/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
Expand Down Expand Up @@ -154,7 +155,7 @@ const CombinedUidProvider = function(configWrapper, consentData, cacheIdObj) {
const url = configWrapper.getUrl();

this.getUid = function(idCallback, errCallback) {
const scriptTag = loadExternalScript(url, EXTERNAL_SCRIPT_MODULE_CODE, () => {
const scriptTag = loadExternalScript(url, MODULE_TYPE_UID, EXTERNAL_SCRIPT_MODULE_CODE, () => {
utils.logInfo(LOG_PREFIX, 'script loaded', url);

const eventDetails = {
Expand Down
4 changes: 3 additions & 1 deletion modules/mediafilterRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { logError, generateUUID } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import * as events from '../src/events.js';
import { EVENTS } from '../src/constants.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

/** The event type for Media Filter. */
export const MEDIAFILTER_EVENT_TYPE = 'com.mediatrust.pbjs.';
Expand Down Expand Up @@ -54,7 +55,8 @@ export const MediaFilter = {
* @param {string} configurationHash - The configuration hash.
*/
setupScript: function(configurationHash) {
loadExternalScript(MEDIAFILTER_BASE_URL.concat(configurationHash), 'mediafilter', () => {});
loadExternalScript(MEDIAFILTER_BASE_URL.concat(configurationHash), MODULE_TYPE_RTD, 'mediafilter', () => {
});
},

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/medianetRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {loadExternalScript} from '../src/adloader.js';
import {submodule} from '../src/hook.js';
import {getGlobal} from '../src/prebidGlobal.js';
import {includes} from '../src/polyfill.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

const MODULE_NAME = 'medianet';
const SOURCE = MODULE_NAME + 'rtd';
Expand Down Expand Up @@ -84,7 +85,7 @@ function executeCommand(command) {

function loadRtdScript(customerId) {
const url = getClientUrl(customerId, window.location.hostname);
loadExternalScript(url, MODULE_NAME)
loadExternalScript(url, MODULE_TYPE_RTD, MODULE_NAME)
}

function getAdUnits(adUnits, adUnitCodes) {
Expand Down
3 changes: 2 additions & 1 deletion modules/qortexRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logWarn, mergeDeep, logMessage, generateUUID } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import * as events from '../src/events.js';
import { EVENTS } from '../src/constants.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

let requestUrl;
let bidderArray;
Expand Down Expand Up @@ -136,7 +137,7 @@ export function loadScriptTag(config) {
}
})

loadExternalScript(src, code, undefined, undefined, attr);
loadExternalScript(src, MODULE_TYPE_RTD, code, undefined, undefined, attr);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/showheroes-bsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { VIDEO, BANNER } from '../src/mediaTypes.js';
*/
// eslint-disable-next-line no-restricted-imports
import { loadExternalScript } from '../src/adloader.js';
import { MODULE_TYPE_BIDDER } from '../src/activities/modules.js';

const PROD_ENDPOINT = 'https://bs.showheroes.com/api/v1/bid';
const STAGE_ENDPOINT = 'https://bid-service.stage.showheroes.com/api/v1/bid';
Expand Down Expand Up @@ -338,7 +339,7 @@ function createOutstreamEmbedCode(bid) {

const fragment = window.document.createDocumentFragment();

let script = loadExternalScript(urls.pubTag, 'showheroes-bs', function () {
let script = loadExternalScript(urls.pubTag, MODULE_TYPE_BIDDER, 'showheroes-bs', function () {
window.ShowheroesTag = this;
});
script.setAttribute('data-player-host', urls.vlHost);
Expand Down
4 changes: 3 additions & 1 deletion modules/symitriDapRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export function createRtdProvider(moduleName, moduleCode, headerPrefix) {
window.dapCalculateEntropy(resolve, reject);
} else {
if (rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapEntropyUrl)) {
loadExternalScript(rtdConfig.params.dapEntropyUrl, MODULE_CODE, () => { dapUtils.dapGetEntropy(resolve, reject) });
loadExternalScript(rtdConfig.params.dapEntropyUrl, MODULE_TYPE_RTD, MODULE_CODE, () => {
dapUtils.dapGetEntropy(resolve, reject)
});
} else {
reject(Error('Please check if dapEntropyUrl is specified and is valid under config.params'));
}
Expand Down
3 changes: 2 additions & 1 deletion modules/tncIdSystem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { submodule } from '../src/hook.js';
import { logInfo } from '../src/utils.js';
import { loadExternalScript } from '../src/adloader.js';
import { MODULE_TYPE_UID } from '../src/activities/modules.js';

const MODULE_NAME = 'tncId';
let url = null;
Expand All @@ -20,7 +21,7 @@ const waitTNCScript = (tncNS) => {

const loadRemoteScript = () => {
return new Promise((resolve) => {
loadExternalScript(url, MODULE_NAME, resolve);
loadExternalScript(url, MODULE_TYPE_UID, MODULE_NAME, resolve);
})
}

Expand Down
3 changes: 2 additions & 1 deletion modules/wurflRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
mergeDeep,
prefixLog,
} from '../src/utils.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

// Constants
const REAL_TIME_MODULE = 'realTimeData';
Expand Down Expand Up @@ -67,7 +68,7 @@ const getBidRequestData = (reqBidsConfigObj, callback, config, userConsent) => {
logger.logMessage('url', url.toString());

try {
loadExternalScript(url.toString(), MODULE_NAME, () => {
loadExternalScript(url.toString(), MODULE_TYPE_RTD, MODULE_NAME, () => {
logger.logMessage('script injected');
window.WURFLPromises.complete.then((res) => {
logger.logMessage('received data', res);
Expand Down
Loading

0 comments on commit 9965e0e

Please sign in to comment.