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#7495)

* 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 f5ba64e commit c5147cb
Show file tree
Hide file tree
Showing 15 changed files with 279 additions and 282 deletions.
12 changes: 5 additions & 7 deletions modules/realvuAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import adapter from '../src/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import CONSTANTS from '../src/constants.json';
import { getStorageManager } from '../src/storageManager.js';

import { logMessage, logError } from '../src/utils.js';
const storage = getStorageManager();

const utils = require('../src/utils.js');

let realvuAnalyticsAdapter = adapter({
global: 'realvuAnalytics',
handler: 'on',
Expand Down Expand Up @@ -401,7 +399,7 @@ export let lib = {
// @if NODE_ENV='debug'
let now = new Date();
let msg = (now.getTime() - time0) / 1000 + ' RENDERED ' + a.unit_id;
utils.logMessage(msg);
logMessage(msg);
// @endif
let rpt = z.bids_rpt(a, true);
z.track(a, 'rend', rpt);
Expand Down Expand Up @@ -885,7 +883,7 @@ realvuAnalyticsAdapter.originEnableAnalytics = realvuAnalyticsAdapter.enableAnal
realvuAnalyticsAdapter.enableAnalytics = function (config) {
_options = config.options;
if (typeof (_options.partnerId) == 'undefined' || _options.partnerId == '') {
utils.logError('Missed realvu.com partnerId parameter', 101, 'Missed partnerId parameter');
logError('Missed realvu.com partnerId parameter', 101, 'Missed partnerId parameter');
}
realvuAnalyticsAdapter.originEnableAnalytics(config);
return _options.partnerId;
Expand All @@ -905,7 +903,7 @@ realvuAnalyticsAdapter.track = function ({eventType, args}) {
' creativei_id=' + args.creative_id;
}
// msg += '\nargs=' + JSON.stringify(args) + '<br>';
utils.logMessage(msg);
logMessage(msg);
// @endif

const boost = window.top1.realvu_aa;
Expand Down Expand Up @@ -935,7 +933,7 @@ realvuAnalyticsAdapter.track = function ({eventType, args}) {
realvuAnalyticsAdapter.checkIn = function (bid, partnerId) {
// find (or add if not registered yet) the unit in boost
if (typeof (partnerId) == 'undefined' || partnerId == '') {
utils.logError('Missed realvu.com partnerId parameter', 102, 'Missed partnerId parameter');
logError('Missed realvu.com partnerId parameter', 102, 'Missed partnerId parameter');
}
let a = window.top1.realvu_aa.check({
unit_id: bid.adUnitCode,
Expand Down
12 changes: 6 additions & 6 deletions modules/reconciliationRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { submodule } from '../src/hook.js';
import { ajaxBuilder } from '../src/ajax.js';
import * as utils from '../src/utils.js';
import { isGptPubadsDefined, timestamp, generateUUID, logError } from '../src/utils.js';
import find from 'core-js-pure/features/array/find.js';

/** @type {Object} */
Expand Down Expand Up @@ -52,7 +52,7 @@ function handleAdMessage(e) {
}

if (data.type === MessageType.IMPRESSION_REQUEST) {
if (utils.isGptPubadsDefined()) {
if (isGptPubadsDefined()) {
// 1. Find the last iframed window before window.top where the tracker was injected
// (the tracker could be injected in nested iframes)
const adWin = getTopIFrameWin(e.source);
Expand All @@ -65,7 +65,7 @@ function handleAdMessage(e) {
adDeliveryId = adSlot.getTargeting('RSDK_ADID');
adDeliveryId = adDeliveryId.length
? adDeliveryId[0]
: `${utils.timestamp()}-${utils.generateUUID()}`;
: `${timestamp()}-${generateUUID()}`;
}
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ export function getTopIFrameWin(win, topWin) {
* @return {Object[]} slot GoogleTag slots
*/
function getAllSlots() {
return utils.isGptPubadsDefined() && window.googletag.pubads().getSlots();
return isGptPubadsDefined() && window.googletag.pubads().getSlots();
}

/**
Expand Down Expand Up @@ -246,7 +246,7 @@ function getReconciliationData(adUnitsCodes) {

const adSlot = getSlotByCode(adUnitCode);
const adUnitId = adSlot ? adSlot.getAdUnitPath() : adUnitCode;
const adDeliveryId = `${utils.timestamp()}-${utils.generateUUID()}`;
const adDeliveryId = `${timestamp()}-${generateUUID()}`;

dataToReturn[adUnitCode] = {
RSDK_AUID: adUnitId,
Expand Down Expand Up @@ -287,7 +287,7 @@ function init(moduleConfig) {
_moduleParams = Object.assign({}, DEFAULT_PARAMS, params);
initListeners();
} else {
utils.logError('missing params for Reconciliation provider');
logError('missing params for Reconciliation provider');
}
return true;
}
Expand Down
72 changes: 36 additions & 36 deletions modules/relaidoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { deepAccess, logWarn, getBidIdParameter, parseQueryStringParameters, triggerPixel, generateUUID, isArray } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';
Expand All @@ -13,19 +13,19 @@ const UUID_KEY = 'relaido_uuid';
const storage = getStorageManager();

function isBidRequestValid(bid) {
if (!utils.deepAccess(bid, 'params.placementId')) {
utils.logWarn('placementId param is reqeuired.');
if (!deepAccess(bid, 'params.placementId')) {
logWarn('placementId param is reqeuired.');
return false;
}
if (hasVideoMediaType(bid) && isVideoValid(bid)) {
return true;
} else {
utils.logWarn('Invalid mediaType video.');
logWarn('Invalid mediaType video.');
}
if (hasBannerMediaType(bid) && isBannerValid(bid)) {
return true;
} else {
utils.logWarn('Invalid mediaType banner.');
logWarn('Invalid mediaType banner.');
}
return false;
}
Expand All @@ -35,7 +35,7 @@ function buildRequests(validBidRequests, bidderRequest) {

for (let i = 0; i < validBidRequests.length; i++) {
const bidRequest = validBidRequests[i];
const placementId = utils.getBidIdParameter('placementId', bidRequest.params);
const placementId = getBidIdParameter('placementId', bidRequest.params);
const bidDomain = bidRequest.params.domain || BIDDER_DOMAIN;
const bidUrl = `https://${bidDomain}/bid/v1/prebid/${placementId}`;
const uuid = getUuid();
Expand All @@ -44,12 +44,12 @@ function buildRequests(validBidRequests, bidderRequest) {
let height = 0;

if (hasVideoMediaType(bidRequest) && isVideoValid(bidRequest)) {
const playerSize = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'));
const playerSize = getValidSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize'));
width = playerSize[0][0];
height = playerSize[0][1];
mediaType = VIDEO;
} else if (hasBannerMediaType(bidRequest) && isBannerValid(bidRequest)) {
const sizes = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes'));
const sizes = getValidSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes'));
width = sizes[0][0];
height = sizes[0][1];
mediaType = BANNER;
Expand Down Expand Up @@ -136,7 +136,7 @@ function getUserSyncs(syncOptions, serverResponses) {
}
let syncUrl = `https://${BIDDER_DOMAIN}/tr/v1/prebid/sync.html`;
if (serverResponses.length > 0) {
syncUrl = utils.deepAccess(serverResponses, '0.body.syncUrl') || syncUrl;
syncUrl = deepAccess(serverResponses, '0.body.syncUrl') || syncUrl;
}
return [{
type: 'iframe',
Expand All @@ -145,34 +145,34 @@ function getUserSyncs(syncOptions, serverResponses) {
}

function onBidWon(bid) {
let query = utils.parseQueryStringParameters({
placement_id: utils.deepAccess(bid, 'params.0.placementId'),
creative_id: utils.deepAccess(bid, 'creativeId'),
price: utils.deepAccess(bid, 'cpm'),
auction_id: utils.deepAccess(bid, 'auctionId'),
bid_id: utils.deepAccess(bid, 'requestId'),
ad_id: utils.deepAccess(bid, 'adId'),
ad_unit_code: utils.deepAccess(bid, 'adUnitCode'),
let query = parseQueryStringParameters({
placement_id: deepAccess(bid, 'params.0.placementId'),
creative_id: deepAccess(bid, 'creativeId'),
price: deepAccess(bid, 'cpm'),
auction_id: deepAccess(bid, 'auctionId'),
bid_id: deepAccess(bid, 'requestId'),
ad_id: deepAccess(bid, 'adId'),
ad_unit_code: deepAccess(bid, 'adUnitCode'),
ref: window.location.href,
}).replace(/\&$/, '');
const bidDomain = utils.deepAccess(bid, 'params.0.domain') || BIDDER_DOMAIN;
const bidDomain = deepAccess(bid, 'params.0.domain') || BIDDER_DOMAIN;
const burl = `https://${bidDomain}/tr/v1/prebid/win.gif?${query}`;
utils.triggerPixel(burl);
triggerPixel(burl);
}

function onTimeout(data) {
let query = utils.parseQueryStringParameters({
placement_id: utils.deepAccess(data, '0.params.0.placementId'),
timeout: utils.deepAccess(data, '0.timeout'),
auction_id: utils.deepAccess(data, '0.auctionId'),
bid_id: utils.deepAccess(data, '0.bidId'),
ad_unit_code: utils.deepAccess(data, '0.adUnitCode'),
let query = parseQueryStringParameters({
placement_id: deepAccess(data, '0.params.0.placementId'),
timeout: deepAccess(data, '0.timeout'),
auction_id: deepAccess(data, '0.auctionId'),
bid_id: deepAccess(data, '0.bidId'),
ad_unit_code: deepAccess(data, '0.adUnitCode'),
version: ADAPTER_VERSION,
ref: window.location.href,
}).replace(/\&$/, '');
const bidDomain = utils.deepAccess(data, '0.params.0.domain') || BIDDER_DOMAIN;
const bidDomain = deepAccess(data, '0.params.0.domain') || BIDDER_DOMAIN;
const timeoutUrl = `https://${bidDomain}/tr/v1/prebid/timeout.gif?${query}`;
utils.triggerPixel(timeoutUrl);
triggerPixel(timeoutUrl);
}

function createPlayerTag(playerUrl) {
Expand All @@ -199,7 +199,7 @@ function newRenderer(bidId, playerUrl) {
try {
renderer.setRender(outstreamRender);
} catch (err) {
utils.logWarn('renderer.setRender Error', err);
logWarn('renderer.setRender Error', err);
}
return renderer;
}
Expand All @@ -220,17 +220,17 @@ function isBannerValid(bid) {
if (!isMobile()) {
return false;
}
const sizes = getValidSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes'));
const sizes = getValidSizes(deepAccess(bid, 'mediaTypes.banner.sizes'));
if (sizes.length > 0) {
return true;
}
return false;
}

function isVideoValid(bid) {
const playerSize = getValidSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize'));
const playerSize = getValidSizes(deepAccess(bid, 'mediaTypes.video.playerSize'));
if (playerSize.length > 0) {
const context = utils.deepAccess(bid, 'mediaTypes.video.context');
const context = deepAccess(bid, 'mediaTypes.video.context');
if (context && context === 'outstream') {
return true;
}
Expand All @@ -241,7 +241,7 @@ function isVideoValid(bid) {
function getUuid() {
const id = storage.getCookie(UUID_KEY)
if (id) return id;
const newId = utils.generateUUID();
const newId = generateUUID();
storage.setCookie(UUID_KEY, newId);
return newId;
}
Expand All @@ -255,18 +255,18 @@ export function isMobile() {
}

function hasBannerMediaType(bid) {
return !!utils.deepAccess(bid, 'mediaTypes.banner');
return !!deepAccess(bid, 'mediaTypes.banner');
}

function hasVideoMediaType(bid) {
return !!utils.deepAccess(bid, 'mediaTypes.video');
return !!deepAccess(bid, 'mediaTypes.video');
}

function getValidSizes(sizes) {
let result = [];
if (sizes && utils.isArray(sizes) && sizes.length > 0) {
if (sizes && isArray(sizes) && sizes.length > 0) {
for (let i = 0; i < sizes.length; i++) {
if (utils.isArray(sizes[i]) && sizes[i].length == 2) {
if (isArray(sizes[i]) && sizes[i].length == 2) {
const width = sizes[i][0];
const height = sizes[i][1];
if (width == 1 && height == 1) {
Expand Down
7 changes: 3 additions & 4 deletions modules/resetdigitalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import * as utils from '../src/utils.js';
import { timestamp, deepAccess, getOrigin } from '../src/utils.js';
import { config } from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getOrigin} from '../src/utils.js';
const BIDDER_CODE = 'resetdigital';

export const spec = {
Expand All @@ -20,7 +19,7 @@ export const spec = {
? config.getConfig('userSync').syncsPerBidder : 5

const payload = {
start_time: utils.timestamp(),
start_time: timestamp(),
language: window.navigator.userLanguage || window.navigator.language,
site: {
domain: getOrigin(),
Expand Down Expand Up @@ -51,7 +50,7 @@ export const spec = {
imp_id: req.transactionId,
sizes: req.sizes,
force_bid: req.params.forceBid,
media_types: utils.deepAccess(req, 'mediaTypes')
media_types: deepAccess(req, 'mediaTypes')
});
}

Expand Down
18 changes: 9 additions & 9 deletions modules/revcontentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import { triggerPixel, isFn, deepAccess, getAdUnitSizes, parseGPTSingleSizeArrayToRtbSize, _map } from '../src/utils.js';

const BIDDER_CODE = 'revcontent';
const NATIVE_PARAMS = {
Expand Down Expand Up @@ -160,7 +160,7 @@ export const spec = {
},
onBidWon: function (bid) {
if (bid.nurl) {
utils.triggerPixel(bid.nurl);
triggerPixel(bid.nurl);
}
return true;
}
Expand Down Expand Up @@ -215,14 +215,14 @@ function extractHostname(url) {

function buildImp(bid, id) {
let bidfloor;
if (utils.isFn(bid.getFloor)) {
if (isFn(bid.getFloor)) {
bidfloor = bid.getFloor({
currency: 'USD',
mediaType: '*',
size: '*'
}).floor;
} else {
bidfloor = utils.deepAccess(bid, `params.bidfloor`) || 0.1;
bidfloor = deepAccess(bid, `params.bidfloor`) || 0.1;
}

let imp = {
Expand All @@ -236,17 +236,17 @@ function buildImp(bid, id) {
secure: '1'
};

let bannerReq = utils.deepAccess(bid, `mediaTypes.banner`);
let nativeReq = utils.deepAccess(bid, `mediaTypes.native`);
let bannerReq = deepAccess(bid, `mediaTypes.banner`);
let nativeReq = deepAccess(bid, `mediaTypes.native`);
if (bannerReq) {
let sizes = utils.getAdUnitSizes(bid);
let sizes = getAdUnitSizes(bid);
imp.banner = {
w: sizes[0][0],
h: sizes[0][1],
format: sizes.map(wh => utils.parseGPTSingleSizeArrayToRtbSize(wh)),
format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)),
}
} else if (nativeReq) {
const assets = utils._map(bid.nativeParams, (bidParams, key) => {
const assets = _map(bid.nativeParams, (bidParams, key) => {
const props = NATIVE_PARAMS[key];
const asset = {
required: bidParams.required & 1
Expand Down
Loading

0 comments on commit c5147cb

Please sign in to comment.