Skip to content

Commit

Permalink
Multiple Bid/Analytics/ID/ other modules: import utils functions as n…
Browse files Browse the repository at this point in the history
…eeded and not the whole module (prebid#7490)

* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* Revert "import utils functions as needed and not the whole module"

This reverts commit bc6c9f6.

* Revert "import utils functions as needed and not the whole module"

This reverts commit ef500ab.

* Revert "import utils functions as needed and not the whole module"

This reverts commit 7e3fa3f.

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module

* import utils functions as needed and not the whole module
  • Loading branch information
pm-harshad-mane authored and Chris Pabst committed Jan 10, 2022
1 parent e047e8c commit b870ae4
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 117 deletions.
8 changes: 4 additions & 4 deletions modules/krushmediaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isFn, deepAccess, logMessage } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'krushmedia';
const AD_URL = 'https://ads4.krushmedia.com/?c=rtb&m=hb';
Expand All @@ -24,8 +24,8 @@ function isBidResponseValid(bid) {
}

function getBidFloor(bid) {
if (!utils.isFn(bid.getFloor)) {
return utils.deepAccess(bid, 'params.bidfloor', 0);
if (!isFn(bid.getFloor)) {
return deepAccess(bid, 'params.bidfloor', 0);
}

try {
Expand Down Expand Up @@ -56,7 +56,7 @@ export const spec = {
winTop = window.top;
} catch (e) {
location = winTop.location;
utils.logMessage(e);
logMessage(e);
};

const placements = [];
Expand Down
10 changes: 5 additions & 5 deletions modules/kubientBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isArray, deepAccess } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'kubient';
const END_POINT = 'https://kssp.kbntx.ch/kubprebidjs';
Expand Down Expand Up @@ -96,7 +96,7 @@ export const spec = {
ad: bid.adm,
meta: {}
};
if (bid.meta && bid.meta.adomain && utils.isArray(bid.meta.adomain)) {
if (bid.meta && bid.meta.adomain && isArray(bid.meta.adomain)) {
bidResponse.meta.advertiserDomains = bid.meta.adomain;
}
if (bid.mediaType === VIDEO) {
Expand Down Expand Up @@ -137,13 +137,13 @@ export const spec = {
function kubientGetConsentGiven(gdprConsent) {
let consentGiven = 0;
if (typeof gdprConsent !== 'undefined') {
let apiVersion = utils.deepAccess(gdprConsent, `apiVersion`);
let apiVersion = deepAccess(gdprConsent, `apiVersion`);
switch (apiVersion) {
case 1:
consentGiven = utils.deepAccess(gdprConsent, `vendorData.vendorConsents.${VENDOR_ID}`) ? 1 : 0;
consentGiven = deepAccess(gdprConsent, `vendorData.vendorConsents.${VENDOR_ID}`) ? 1 : 0;
break;
case 2:
consentGiven = utils.deepAccess(gdprConsent, `vendorData.vendor.consents.${VENDOR_ID}`) ? 1 : 0;
consentGiven = deepAccess(gdprConsent, `vendorData.vendor.consents.${VENDOR_ID}`) ? 1 : 0;
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions modules/limelightDigitalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logMessage, groupBy, uniques } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {ajax} from '../src/ajax.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'limelightDigital';

Expand Down Expand Up @@ -51,10 +51,10 @@ export const spec = {
winTop = window.top;
winTop.location.toString();
} catch (e) {
utils.logMessage(e);
logMessage(e);
winTop = window;
}
const placements = utils.groupBy(validBidRequests.map(bidRequest => buildPlacement(bidRequest)), 'host')
const placements = groupBy(validBidRequests.map(bidRequest => buildPlacement(bidRequest)), 'host')
return Object.keys(placements)
.map(host => buildRequest(winTop, host, placements[host].map(placement => placement.adUnit)));
},
Expand Down Expand Up @@ -125,7 +125,7 @@ function buildPlacement(bidRequest) {
break;
}
}
sizes = (sizes || []).concat(bidRequest.sizes || []).filter(utils.uniques);
sizes = (sizes || []).concat(bidRequest.sizes || []).filter(uniques);
return {
host: bidRequest.params.host,
adUnit: {
Expand Down
9 changes: 4 additions & 5 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* @module modules/liveIntentIdSystem
* @requires module:modules/userId
*/
import * as utils from '../src/utils.js';
import { triggerPixel } from '../src/utils.js';
import { triggerPixel, logError } from '../src/utils.js';
import { ajaxBuilder } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { LiveConnect } from 'live-connect-js/esm/initializer.js';
Expand Down Expand Up @@ -93,8 +92,8 @@ function initializeLiveConnect(configParams) {
liveConnectConfig.gdprConsent = gdprConsent.consentString;
}

// The second param is the storage object, LS & Cookie manipulation uses PBJS utils.
// The third param is the ajax and pixel object, the ajax and pixel use PBJS utils.
// The second param is the storage object, LS & Cookie manipulation uses PBJS
// The third param is the ajax and pixel object, the ajax and pixel use PBJS
liveConnect = liveIntentIdSubmodule.getInitializer()(liveConnectConfig, storage, calls);
if (configParams.emailHash) {
liveConnect.push({ hash: configParams.emailHash })
Expand Down Expand Up @@ -169,7 +168,7 @@ export const liveIntentIdSubmodule = {
callback(response);
},
error => {
utils.logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
logError(`${MODULE_NAME}: ID fetch encountered an error: `, error);
callback();
}
)
Expand Down
26 changes: 13 additions & 13 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { timestamp, logInfo, getWindowTop } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
Expand All @@ -21,16 +21,16 @@ const cache = {

let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), {
track({eventType, args}) {
const time = utils.timestamp();
utils.logInfo('LIVEWRAPPED_EVENT:', [eventType, args]);
const time = timestamp();
logInfo('LIVEWRAPPED_EVENT:', [eventType, args]);

switch (eventType) {
case CONSTANTS.EVENTS.AUCTION_INIT:
utils.logInfo('LIVEWRAPPED_AUCTION_INIT:', args);
logInfo('LIVEWRAPPED_AUCTION_INIT:', args);
cache.auctions[args.auctionId] = {bids: {}, bidAdUnits: {}};
break;
case CONSTANTS.EVENTS.BID_REQUESTED:
utils.logInfo('LIVEWRAPPED_BID_REQUESTED:', args);
logInfo('LIVEWRAPPED_BID_REQUESTED:', args);
cache.auctions[args.auctionId].timeStamp = args.start;

args.bids.forEach(function(bidRequest) {
Expand Down Expand Up @@ -62,12 +62,12 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
lw: bidRequest.lw
}

utils.logInfo(bidRequest);
logInfo(bidRequest);
})
utils.logInfo(livewrappedAnalyticsAdapter.requestEvents);
logInfo(livewrappedAnalyticsAdapter.requestEvents);
break;
case CONSTANTS.EVENTS.BID_RESPONSE:
utils.logInfo('LIVEWRAPPED_BID_RESPONSE:', args);
logInfo('LIVEWRAPPED_BID_RESPONSE:', args);

let bidResponse = cache.auctions[args.auctionId].bids[args.requestId];
bidResponse.isBid = args.getStatusCode() === CONSTANTS.STATUS.GOOD;
Expand All @@ -90,7 +90,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
}
break;
case CONSTANTS.EVENTS.BIDDER_DONE:
utils.logInfo('LIVEWRAPPED_BIDDER_DONE:', args);
logInfo('LIVEWRAPPED_BIDDER_DONE:', args);
args.bids.forEach(doneBid => {
let bid = cache.auctions[doneBid.auctionId].bids[doneBid.bidId || doneBid.requestId];
if (!bid.ttr) {
Expand All @@ -100,21 +100,21 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
});
break;
case CONSTANTS.EVENTS.BID_WON:
utils.logInfo('LIVEWRAPPED_BID_WON:', args);
logInfo('LIVEWRAPPED_BID_WON:', args);
let wonBid = cache.auctions[args.auctionId].bids[args.requestId];
wonBid.won = true;
if (wonBid.sendStatus != 0) {
livewrappedAnalyticsAdapter.sendEvents();
}
break;
case CONSTANTS.EVENTS.BID_TIMEOUT:
utils.logInfo('LIVEWRAPPED_BID_TIMEOUT:', args);
logInfo('LIVEWRAPPED_BID_TIMEOUT:', args);
args.forEach(timeout => {
cache.auctions[timeout.auctionId].bids[timeout.bidId].timeout = true;
});
break;
case CONSTANTS.EVENTS.AUCTION_END:
utils.logInfo('LIVEWRAPPED_AUCTION_END:', args);
logInfo('LIVEWRAPPED_AUCTION_END:', args);
setTimeout(() => {
livewrappedAnalyticsAdapter.sendEvents();
}, BID_WON_TIMEOUT);
Expand Down Expand Up @@ -159,7 +159,7 @@ livewrappedAnalyticsAdapter.sendEvents = function() {

function getAdblockerRecovered() {
try {
return utils.getWindowTop().I12C && utils.getWindowTop().I12C.Morph === 1;
return getWindowTop().I12C && getWindowTop().I12C.Morph === 1;
} catch (e) {}
}

Expand Down
14 changes: 7 additions & 7 deletions modules/livewrappedBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { isSafariBrowser, deepAccess, getWindowTop } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import find from 'core-js-pure/features/array/find.js';
Expand Down Expand Up @@ -83,7 +83,7 @@ export const spec = {
gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined,
coppa: getCoppa(),
usPrivacy: bidderRequest.uspConsent,
cookieSupport: !utils.isSafariBrowser() && storage.cookiesAreEnabled(),
cookieSupport: !isSafariBrowser() && storage.cookiesAreEnabled(),
rcv: getAdblockerRecovered(),
adRequests: [...adRequests],
rtbData: handleEids(bidRequests),
Expand Down Expand Up @@ -228,19 +228,19 @@ function bidToAdRequest(bid) {
adRequest.auc = bid.auc;
}

adRequest.native = utils.deepAccess(bid, 'mediaTypes.native');
adRequest.native = deepAccess(bid, 'mediaTypes.native');

adRequest.video = utils.deepAccess(bid, 'mediaTypes.video');
adRequest.video = deepAccess(bid, 'mediaTypes.video');

if ((adRequest.native || adRequest.video) && utils.deepAccess(bid, 'mediaTypes.banner')) {
if ((adRequest.native || adRequest.video) && deepAccess(bid, 'mediaTypes.banner')) {
adRequest.banner = true;
}

return adRequest;
}

function getSizes(bid) {
if (utils.deepAccess(bid, 'mediaTypes.banner.sizes')) {
if (deepAccess(bid, 'mediaTypes.banner.sizes')) {
return bid.mediaTypes.banner.sizes;
} else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) {
return bid.sizes;
Expand All @@ -257,7 +257,7 @@ function sizeToFormat(size) {

function getAdblockerRecovered() {
try {
return utils.getWindowTop().I12C && utils.getWindowTop().I12C.Morph === 1;
return getWindowTop().I12C && getWindowTop().I12C.Morph === 1;
} catch (e) {}
}

Expand Down
26 changes: 13 additions & 13 deletions modules/liveyieldAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError } from '../src/utils.js';
import adapter from '../src/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import * as utils from '../src/utils.js';

const {
EVENTS: { BID_REQUESTED, BID_TIMEOUT, BID_RESPONSE, BID_WON }
Expand Down Expand Up @@ -198,7 +198,7 @@ const liveyield = Object.assign(adapter({ analyticsType: 'bundle' }), {
args.bidderCode
);
} catch (e) {
utils.logError(e);
logError(e);
}
});
break;
Expand All @@ -220,7 +220,7 @@ const liveyield = Object.assign(adapter({ analyticsType: 'bundle' }), {
args.statusMessage !== 'Bid available'
);
} catch (e) {
utils.logError(e);
logError(e);
}
break;
case BID_TIMEOUT:
Expand All @@ -243,7 +243,7 @@ const liveyield = Object.assign(adapter({ analyticsType: 'bundle' }), {
)
);
if (!ad) {
utils.logError(
logError(
'Cannot find ad by unit name: ' +
liveyield.instanceConfig.getAdUnitName(
liveyield.instanceConfig.getPlacementOrAdUnitCode(
Expand All @@ -255,7 +255,7 @@ const liveyield = Object.assign(adapter({ analyticsType: 'bundle' }), {
break;
}
if (!args.bidderCode || !args.cpm) {
utils.logError('Bidder code or cpm is not valid');
logError('Bidder code or cpm is not valid');
break;
}
const resolution = { targetings: [] };
Expand All @@ -280,7 +280,7 @@ const liveyield = Object.assign(adapter({ analyticsType: 'bundle' }), {
resolutionToUse
);
} catch (e) {
utils.logError(e);
logError(e);
}
break;
}
Expand Down Expand Up @@ -310,27 +310,27 @@ liveyield.originEnableAnalytics = liveyield.enableAnalytics;
*/
liveyield.enableAnalytics = function(config) {
if (!config || !config.provider || config.provider !== 'liveyield') {
utils.logError('expected config.provider to equal liveyield');
logError('expected config.provider to equal liveyield');
return;
}
if (!config.options) {
utils.logError('options must be defined');
logError('options must be defined');
return;
}
if (!config.options.customerId) {
utils.logError('options.customerId is required');
logError('options.customerId is required');
return;
}
if (!config.options.customerName) {
utils.logError('options.customerName is required');
logError('options.customerName is required');
return;
}
if (!config.options.customerSite) {
utils.logError('options.customerSite is required');
logError('options.customerSite is required');
return;
}
if (!config.options.sessionTimezoneOffset) {
utils.logError('options.sessionTimezoneOffset is required');
logError('options.sessionTimezoneOffset is required');
return;
}
liveyield.instanceConfig = Object.assign(
Expand All @@ -340,7 +340,7 @@ liveyield.enableAnalytics = function(config) {
);

if (typeof window[liveyield.instanceConfig.rtaFunctionName] !== 'function') {
utils.logError(
logError(
`Function ${liveyield.instanceConfig.rtaFunctionName} is not defined.` +
`Make sure that LiveYield snippet in included before the Prebid Analytics configuration.`
);
Expand Down
4 changes: 2 additions & 2 deletions modules/lockerdomeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { getBidIdParameter } from '../src/utils.js';
import {BANNER} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';

Expand All @@ -16,7 +16,7 @@ export const spec = {
return {
requestId: bid.bidId,
adUnitCode: bid.adUnitCode,
adUnitId: utils.getBidIdParameter('adUnitId', bid.params),
adUnitId: getBidIdParameter('adUnitId', bid.params),
sizes: bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes
};
});
Expand Down
8 changes: 4 additions & 4 deletions modules/loganBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isFn, deepAccess, getWindowTop } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';

const BIDDER_CODE = 'logan';
Expand All @@ -25,8 +25,8 @@ function isBidResponseValid(bid) {
}

function getBidFloor(bid) {
if (!utils.isFn(bid.getFloor)) {
return utils.deepAccess(bid, 'params.bidfloor', 0);
if (!isFn(bid.getFloor)) {
return deepAccess(bid, 'params.bidfloor', 0);
}

try {
Expand All @@ -50,7 +50,7 @@ export const spec = {
},

buildRequests: (validBidRequests = [], bidderRequest) => {
const winTop = utils.getWindowTop();
const winTop = getWindowTop();
const location = winTop.location;
const placements = [];
const request = {
Expand Down
Loading

0 comments on commit b870ae4

Please sign in to comment.