Skip to content

Commit

Permalink
import utils functions as needed and not the whole module
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-harshad-mane committed Sep 24, 2021
1 parent bc6c9f6 commit ef500ab
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 58 deletions.
22 changes: 11 additions & 11 deletions modules/atsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError, logInfo } from '../src/utils.js';
import adapter from '../src/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adaptermanager from '../src/adapterManager.js';
import * as utils from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {getStorageManager} from '../src/storageManager.js';

Expand Down Expand Up @@ -256,7 +256,7 @@ export function parseBrowser() {
let browserName = result && result.length ? result[0].name : '';
return (listOfSupportedBrowsers.indexOf(browserName) >= 0) ? browserName : 'Unknown';
} catch (err) {
utils.logError('ATS Analytics - Error while checking user browser!', err);
logError('ATS Analytics - Error while checking user browser!', err);
}
}

Expand All @@ -265,20 +265,20 @@ function sendDataToAnalytic () {
try {
let dataToSend = {'Data': atsAnalyticsAdapter.context.events};
let strJSON = JSON.stringify(dataToSend);
utils.logInfo('ATS Analytics - tried to send analytics data!');
logInfo('ATS Analytics - tried to send analytics data!');
ajax(analyticsUrl, function () {
}, strJSON, {method: 'POST', contentType: 'application/json'});
} catch (err) {
utils.logError('ATS Analytics - request encounter an error: ', err);
logError('ATS Analytics - request encounter an error: ', err);
}
}

// preflight request, to check did publisher have permission to send data to analytics endpoint
function preflightRequest (envelopeSourceCookieValue) {
utils.logInfo('ATS Analytics - preflight request!');
logInfo('ATS Analytics - preflight request!');
ajax(preflightUrl + atsAnalyticsAdapter.context.pid, function (data) {
let samplingRateObject = JSON.parse(data);
utils.logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject);
logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject);
let samplingRate = samplingRateObject['samplingRate'];
setSamplingCookie(samplingRate);
let samplingRateNumber = Number(samplingRate);
Expand Down Expand Up @@ -332,7 +332,7 @@ let atsAnalyticsAdapter = Object.assign(adapter(
}
}
} catch (err) {
utils.logError('ATS Analytics - preflight request encounter an error: ', err);
logError('ATS Analytics - preflight request encounter an error: ', err);
}
}
}
Expand All @@ -345,10 +345,10 @@ atsAnalyticsAdapter.originEnableAnalytics = atsAnalyticsAdapter.enableAnalytics;
atsAnalyticsAdapter.shouldFireRequest = function (samplingRate) {
if (samplingRate !== 0) {
let shouldFireRequestValue = (Math.floor((Math.random() * 100 + 1)) === 100);
utils.logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue);
logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue);
return shouldFireRequestValue;
} else {
utils.logInfo('ATS Analytics - Should Fire Request: ', false);
logInfo('ATS Analytics - Should Fire Request: ', false);
return false;
}
};
Expand All @@ -359,15 +359,15 @@ atsAnalyticsAdapter.getUserAgent = function () {
// override enableAnalytics so we can get access to the config passed in from the page
atsAnalyticsAdapter.enableAnalytics = function (config) {
if (!config.options.pid) {
utils.logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work');
logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work');
return;
}
atsAnalyticsAdapter.context = {
events: [],
pid: config.options.pid
};
let initOptions = config.options;
utils.logInfo('ATS Analytics - adapter enabled! ');
logInfo('ATS Analytics - adapter enabled! ');
atsAnalyticsAdapter.originEnableAnalytics(initOptions); // call the base class function
};

Expand Down
30 changes: 15 additions & 15 deletions modules/audiencerunBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from '../src/utils.js';
import { deepAccess, isFn, logError, getValue, getBidIdParameter, _each, isArray, triggerPixel } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
Expand All @@ -20,7 +20,7 @@ let requestedBids = [];
function getPageUrl(bidderRequest) {
return (
config.getConfig('pageUrl') ||
utils.deepAccess(bidderRequest, 'refererInfo.referer') ||
deepAccess(bidderRequest, 'refererInfo.referer') ||
null
);
}
Expand All @@ -32,8 +32,8 @@ function getPageUrl(bidderRequest) {
* @returns {number}
*/
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 @@ -61,8 +61,8 @@ export const spec = {
*/
isBidRequestValid: function (bid) {
let isValid = true;
if (!utils.deepAccess(bid, 'params.zoneId')) {
utils.logError('AudienceRun zoneId parameter is required. Bid aborted.');
if (!deepAccess(bid, 'params.zoneId')) {
logError('AudienceRun zoneId parameter is required. Bid aborted.');
isValid = false;
}
return isValid;
Expand All @@ -77,19 +77,19 @@ export const spec = {
*/
buildRequests: function (bidRequests, bidderRequest) {
const bids = bidRequests.map((bid) => {
const sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes', []);
const sizes = deepAccess(bid, 'mediaTypes.banner.sizes', []);
return {
zoneId: utils.getValue(bid.params, 'zoneId'),
zoneId: getValue(bid.params, 'zoneId'),
sizes: sizes.map((size) => ({
w: size[0],
h: size[1],
})),
bidfloor: getBidFloor(bid),
bidId: bid.bidId,
bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid),
adUnitCode: utils.getBidIdParameter('adUnitCode', bid),
auctionId: utils.getBidIdParameter('auctionId', bid),
transactionId: utils.getBidIdParameter('transactionId', bid),
bidderRequestId: getBidIdParameter('bidderRequestId', bid),
adUnitCode: getBidIdParameter('adUnitCode', bid),
auctionId: getBidIdParameter('auctionId', bid),
transactionId: getBidIdParameter('transactionId', bid),
};
});

Expand Down Expand Up @@ -133,7 +133,7 @@ export const spec = {
*/
interpretResponse: function (serverResponse, bidRequest) {
const bids = [];
utils._each(serverResponse.body.bid, function (bidObject) {
_each(serverResponse.body.bid, function (bidObject) {
if (!bidObject.cpm || bidObject.cpm === null || !bidObject.adm) {
return;
}
Expand Down Expand Up @@ -196,15 +196,15 @@ export const spec = {
* @param {Array} timeoutData timeout specific data
*/
onTimeout: function (timeoutData) {
if (!utils.isArray(timeoutData)) {
if (!isArray(timeoutData)) {
return;
}

timeoutData.forEach((bid) => {
const bidOnTimeout = requestedBids.find((requestedBid) => requestedBid.bidId === bid.bidId);

if (bidOnTimeout) {
utils.triggerPixel(
triggerPixel(
`${TIMEOUT_EVENT_URL}/${bidOnTimeout.zoneId}/${bidOnTimeout.bidId}`
);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/automatadBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logInfo } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js'
import * as utils from '../src/utils.js'
import {BANNER} from '../src/mediaTypes.js'
import {ajax} from '../src/ajax.js'

Expand Down Expand Up @@ -92,7 +92,7 @@ export const spec = {
})
})
} else {
utils.logInfo('automatad :: no valid responses to interpret')
logInfo('automatad :: no valid responses to interpret')
}

return bidResponses
Expand Down
14 changes: 7 additions & 7 deletions modules/axonixBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isArray, logError, deepAccess, isEmpty, triggerPixel, replaceAuctionPrice } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import * as utils from '../src/utils.js';
import { ajax } from '../src/ajax.js';

const BIDDER_CODE = 'axonix';
Expand Down Expand Up @@ -68,9 +68,9 @@ export const spec = {
// video bid request validation
if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) {
if (!bid.mediaTypes[VIDEO].hasOwnProperty('mimes') ||
!utils.isArray(bid.mediaTypes[VIDEO].mimes) ||
!isArray(bid.mediaTypes[VIDEO].mimes) ||
bid.mediaTypes[VIDEO].mimes.length === 0) {
utils.logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid));
logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid));

return false;
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export const spec = {
interpretResponse: function(serverResponse) {
const response = serverResponse ? serverResponse.body : [];

if (!utils.isArray(response)) {
if (!isArray(response)) {
return [];
}

Expand All @@ -160,9 +160,9 @@ export const spec = {
},

onTimeout: function(timeoutData) {
const params = utils.deepAccess(timeoutData, '0.params.0');
const params = deepAccess(timeoutData, '0.params.0');

if (!utils.isEmpty(params)) {
if (!isEmpty(params)) {
ajax(getURL(params, 'prebid/timeout'), null, timeoutData[0], {
method: 'POST',
options: {
Expand All @@ -177,7 +177,7 @@ export const spec = {
const { nurl } = bid || {};

if (bid.nurl) {
utils.triggerPixel(utils.replaceAuctionPrice(nurl, bid.cpm));
triggerPixel(replaceAuctionPrice(nurl, bid.cpm));
};
}
}
Expand Down
Loading

0 comments on commit ef500ab

Please sign in to comment.