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

Added a consistent prefix in logWarn message in PubMatic adapter #3633

Merged
merged 1 commit into from
Mar 14, 2019
Merged
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
47 changes: 24 additions & 23 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes';
import {config} from '../src/config';

const BIDDER_CODE = 'pubmatic';
const LOG_WARN_PREFIX = 'PubMatic: ';
const ENDPOINT = '//hbopenbid.pubmatic.com/translator?source=prebid-client';
const USYNCURL = '//ads.pubmatic.com/AdServer/js/showad.js#PIX&kdntuid=1&p=';
const DEFAULT_CURRENCY = 'USD';
Expand Down Expand Up @@ -175,7 +176,7 @@ function _getDomainFromURL(url) {

function _parseSlotParam(paramName, paramValue) {
if (!utils.isStr(paramValue)) {
paramValue && utils.logWarn('PubMatic: Ignoring param key: ' + paramName + ', expects string-value, found ' + typeof paramValue);
paramValue && utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param key: ' + paramName + ', expects string-value, found ' + typeof paramValue);
return UNDEFINED;
}

Expand Down Expand Up @@ -221,15 +222,15 @@ function _parseAdSlot(bid) {
splits = slot.split('@');
if (splits.length != 2) {
if (!(sizesArrayExists)) {
utils.logWarn('AdSlot Error: adSlot not in required format');
utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format');
return;
}
}
bid.params.adUnit = splits[0];
if (splits.length > 1) { // i.e size is specified in adslot, so consider that and ignore sizes array
splits = splits[1].split('x');
if (splits.length != 2) {
utils.logWarn('AdSlot Error: adSlot not in required format');
utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format');
return;
}
bid.params.width = parseInt(splits[0]);
Expand Down Expand Up @@ -273,7 +274,7 @@ function _handleCustomParams(params, conf) {
if (utils.isStr(value)) {
conf[key] = value;
} else {
utils.logWarn('PubMatic: Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value);
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value);
}
}
}
Expand Down Expand Up @@ -311,25 +312,25 @@ function _checkParamDataType(key, value, datatype) {
switch (datatype) {
case DATA_TYPES.BOOLEAN:
if (!utils.isBoolean(value)) {
utils.logWarn(errMsg);
utils.logWarn(LOG_WARN_PREFIX + errMsg);
return UNDEFINED;
}
return value;
case DATA_TYPES.NUMBER:
if (!utils.isNumber(value)) {
utils.logWarn(errMsg);
utils.logWarn(LOG_WARN_PREFIX + errMsg);
return UNDEFINED;
}
return value;
case DATA_TYPES.STRING:
if (!utils.isStr(value)) {
utils.logWarn(errMsg);
utils.logWarn(LOG_WARN_PREFIX + errMsg);
return UNDEFINED;
}
return value;
case DATA_TYPES.ARRAY:
if (!utils.isArray(value)) {
utils.logWarn(errMsg);
utils.logWarn(LOG_WARN_PREFIX + errMsg);
return UNDEFINED;
}
return value;
Expand All @@ -356,7 +357,7 @@ function _createNativeRequest(params) {
}
};
} else {
utils.logWarn(BIDDER_CODE + ' Error: Title Length is required for native ad: ' + JSON.stringify(params));
utils.logWarn(LOG_WARN_PREFIX + 'Error: Title Length is required for native ad: ' + JSON.stringify(params));
}
break;
case NATIVE_ASSET_KEY.IMAGE:
Expand All @@ -376,7 +377,7 @@ function _createNativeRequest(params) {
};
} else {
// Log Warn
utils.logWarn(BIDDER_CODE + ' Error: Image sizes is required for native ad: ' + JSON.stringify(params));
utils.logWarn(LOG_WARN_PREFIX + 'Error: Image sizes is required for native ad: ' + JSON.stringify(params));
}
break;
case NATIVE_ASSET_KEY.ICON:
Expand All @@ -392,7 +393,7 @@ function _createNativeRequest(params) {
};
} else {
// Log Warn
utils.logWarn(BIDDER_CODE + ' Error: Icon sizes is required for native ad: ' + JSON.stringify(params));
utils.logWarn(LOG_WARN_PREFIX + 'Error: Icon sizes is required for native ad: ' + JSON.stringify(params));
};
break;
case NATIVE_ASSET_KEY.SPONSOREDBY:
Expand Down Expand Up @@ -650,7 +651,7 @@ function _createImpressionObject(bid, conf) {
impObj.banner = bannerObj;
}
if (isInvalidNativeRequest && impObj.hasOwnProperty('native')) {
utils.logWarn(BIDDER_CODE + ': Call to OpenBid will not be sent for native ad unit as it does not contain required valid native params.' + JSON.stringify(bid) + ' Refer:' + PREBID_NATIVE_HELP_LINK);
utils.logWarn(LOG_WARN_PREFIX + 'Call to OpenBid will not be sent for native ad unit as it does not contain required valid native params.' + JSON.stringify(bid) + ' Refer:' + PREBID_NATIVE_HELP_LINK);
return;
}
return impObj;
Expand Down Expand Up @@ -717,7 +718,7 @@ function _parseNativeResponse(bid, newBid) {
try {
adm = JSON.parse(bid.adm.replace(/\\/g, ''));
} catch (ex) {
utils.logWarn(BIDDER_CODE + ' Error: Cannot parse native reponse for ad response: ' + newBid.adm);
utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm);
return;
}
if (adm && adm.native && adm.native.assets && adm.native.assets.length > 0) {
Expand Down Expand Up @@ -784,17 +785,17 @@ export const spec = {
isBidRequestValid: bid => {
if (bid && bid.params) {
if (!utils.isStr(bid.params.publisherId)) {
utils.logWarn(BIDDER_CODE + ' Error: publisherId is mandatory and cannot be numeric. Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid));
utils.logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric. Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid));
return false;
}
if (!utils.isStr(bid.params.adSlot)) {
utils.logWarn(BIDDER_CODE + ': adSlotId is mandatory and cannot be numeric. Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid));
utils.logWarn(LOG_WARN_PREFIX + 'Error: adSlotId is mandatory and cannot be numeric. Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid));
return false;
}
// video ad validation
if (bid.params.hasOwnProperty('video')) {
if (!bid.params.video.hasOwnProperty('mimes') || !utils.isArray(bid.params.video.mimes) || bid.params.video.mimes.length === 0) {
utils.logWarn(BIDDER_CODE + ': For video ads, mimes is mandatory and must specify atlease 1 mime value. Call to OpenBid will not be sent for ad unit:' + JSON.stringify(bid));
utils.logWarn(LOG_WARN_PREFIX + 'Error: For video ads, mimes is mandatory and must specify atlease 1 mime value. Call to OpenBid will not be sent for ad unit:' + JSON.stringify(bid));
return false;
}
}
Expand Down Expand Up @@ -826,12 +827,12 @@ export const spec = {
_parseAdSlot(bid);
if (bid.params.hasOwnProperty('video')) {
if (!(bid.params.adSlot && bid.params.adUnit && bid.params.adUnitIndex)) {
utils.logWarn(BIDDER_CODE + ': Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
utils.logWarn(LOG_WARN_PREFIX + 'Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
return;
}
} else {
if (!(bid.params.adSlot && bid.params.adUnit && bid.params.adUnitIndex && bid.params.width && bid.params.height)) {
utils.logWarn(BIDDER_CODE + ': Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
utils.logWarn(LOG_WARN_PREFIX + 'Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
return;
}
}
Expand All @@ -841,7 +842,7 @@ export const spec = {
if (bidCurrency === '') {
bidCurrency = bid.params.currency || undefined;
} else if (bid.params.hasOwnProperty('currency') && bidCurrency !== bid.params.currency) {
utils.logWarn(BIDDER_CODE + ': Currency specifier ignored. Only one currency permitted.');
utils.logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.');
}
bid.params.currency = bidCurrency;
// check if dctr is added to more than 1 adunit
Expand Down Expand Up @@ -910,13 +911,13 @@ export const spec = {
key_val: dctr.trim()
}
} else {
utils.logWarn(BIDDER_CODE + ': Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
if (dctrArr.length > 1) {
utils.logWarn(BIDDER_CODE + ': dctr value found in more than 1 adunits. Value from 1st adunit will be picked. Ignoring values from subsequent adunits');
utils.logWarn(LOG_WARN_PREFIX + 'dctr value found in more than 1 adunits. Value from 1st adunit will be picked. Ignoring values from subsequent adunits');
}
} else {
utils.logWarn(BIDDER_CODE + ': dctr value not found in 1st adunit, ignoring values from subsequent adunits');
utils.logWarn(LOG_WARN_PREFIX + 'dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}
}

Expand Down Expand Up @@ -1004,7 +1005,7 @@ export const spec = {
url: syncurl
}];
} else {
utils.logWarn('PubMatic: Please enable iframe based user sync.');
utils.logWarn(LOG_WARN_PREFIX + 'Please enable iframe based user sync.');
}
},

Expand Down