Skip to content

Commit b4870e7

Browse files
pm-harshad-manejsnellbaker
authored andcommitted
Added a consistent prefix in logWarn message in PubMatic adapter (prebid#3633)
1 parent 18b04f3 commit b4870e7

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

modules/pubmaticBidAdapter.js

+24-23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes';
44
import {config} from '../src/config';
55

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

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

@@ -221,15 +222,15 @@ function _parseAdSlot(bid) {
221222
splits = slot.split('@');
222223
if (splits.length != 2) {
223224
if (!(sizesArrayExists)) {
224-
utils.logWarn('AdSlot Error: adSlot not in required format');
225+
utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format');
225226
return;
226227
}
227228
}
228229
bid.params.adUnit = splits[0];
229230
if (splits.length > 1) { // i.e size is specified in adslot, so consider that and ignore sizes array
230231
splits = splits[1].split('x');
231232
if (splits.length != 2) {
232-
utils.logWarn('AdSlot Error: adSlot not in required format');
233+
utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format');
233234
return;
234235
}
235236
bid.params.width = parseInt(splits[0]);
@@ -273,7 +274,7 @@ function _handleCustomParams(params, conf) {
273274
if (utils.isStr(value)) {
274275
conf[key] = value;
275276
} else {
276-
utils.logWarn('PubMatic: Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value);
277+
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value);
277278
}
278279
}
279280
}
@@ -311,25 +312,25 @@ function _checkParamDataType(key, value, datatype) {
311312
switch (datatype) {
312313
case DATA_TYPES.BOOLEAN:
313314
if (!utils.isBoolean(value)) {
314-
utils.logWarn(errMsg);
315+
utils.logWarn(LOG_WARN_PREFIX + errMsg);
315316
return UNDEFINED;
316317
}
317318
return value;
318319
case DATA_TYPES.NUMBER:
319320
if (!utils.isNumber(value)) {
320-
utils.logWarn(errMsg);
321+
utils.logWarn(LOG_WARN_PREFIX + errMsg);
321322
return UNDEFINED;
322323
}
323324
return value;
324325
case DATA_TYPES.STRING:
325326
if (!utils.isStr(value)) {
326-
utils.logWarn(errMsg);
327+
utils.logWarn(LOG_WARN_PREFIX + errMsg);
327328
return UNDEFINED;
328329
}
329330
return value;
330331
case DATA_TYPES.ARRAY:
331332
if (!utils.isArray(value)) {
332-
utils.logWarn(errMsg);
333+
utils.logWarn(LOG_WARN_PREFIX + errMsg);
333334
return UNDEFINED;
334335
}
335336
return value;
@@ -356,7 +357,7 @@ function _createNativeRequest(params) {
356357
}
357358
};
358359
} else {
359-
utils.logWarn(BIDDER_CODE + ' Error: Title Length is required for native ad: ' + JSON.stringify(params));
360+
utils.logWarn(LOG_WARN_PREFIX + 'Error: Title Length is required for native ad: ' + JSON.stringify(params));
360361
}
361362
break;
362363
case NATIVE_ASSET_KEY.IMAGE:
@@ -376,7 +377,7 @@ function _createNativeRequest(params) {
376377
};
377378
} else {
378379
// Log Warn
379-
utils.logWarn(BIDDER_CODE + ' Error: Image sizes is required for native ad: ' + JSON.stringify(params));
380+
utils.logWarn(LOG_WARN_PREFIX + 'Error: Image sizes is required for native ad: ' + JSON.stringify(params));
380381
}
381382
break;
382383
case NATIVE_ASSET_KEY.ICON:
@@ -392,7 +393,7 @@ function _createNativeRequest(params) {
392393
};
393394
} else {
394395
// Log Warn
395-
utils.logWarn(BIDDER_CODE + ' Error: Icon sizes is required for native ad: ' + JSON.stringify(params));
396+
utils.logWarn(LOG_WARN_PREFIX + 'Error: Icon sizes is required for native ad: ' + JSON.stringify(params));
396397
};
397398
break;
398399
case NATIVE_ASSET_KEY.SPONSOREDBY:
@@ -650,7 +651,7 @@ function _createImpressionObject(bid, conf) {
650651
impObj.banner = bannerObj;
651652
}
652653
if (isInvalidNativeRequest && impObj.hasOwnProperty('native')) {
653-
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);
654+
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);
654655
return;
655656
}
656657
return impObj;
@@ -717,7 +718,7 @@ function _parseNativeResponse(bid, newBid) {
717718
try {
718719
adm = JSON.parse(bid.adm.replace(/\\/g, ''));
719720
} catch (ex) {
720-
utils.logWarn(BIDDER_CODE + ' Error: Cannot parse native reponse for ad response: ' + newBid.adm);
721+
utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm);
721722
return;
722723
}
723724
if (adm && adm.native && adm.native.assets && adm.native.assets.length > 0) {
@@ -784,17 +785,17 @@ export const spec = {
784785
isBidRequestValid: bid => {
785786
if (bid && bid.params) {
786787
if (!utils.isStr(bid.params.publisherId)) {
787-
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));
788+
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));
788789
return false;
789790
}
790791
if (!utils.isStr(bid.params.adSlot)) {
791-
utils.logWarn(BIDDER_CODE + ': adSlotId is mandatory and cannot be numeric. Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid));
792+
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));
792793
return false;
793794
}
794795
// video ad validation
795796
if (bid.params.hasOwnProperty('video')) {
796797
if (!bid.params.video.hasOwnProperty('mimes') || !utils.isArray(bid.params.video.mimes) || bid.params.video.mimes.length === 0) {
797-
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));
798+
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));
798799
return false;
799800
}
800801
}
@@ -826,12 +827,12 @@ export const spec = {
826827
_parseAdSlot(bid);
827828
if (bid.params.hasOwnProperty('video')) {
828829
if (!(bid.params.adSlot && bid.params.adUnit && bid.params.adUnitIndex)) {
829-
utils.logWarn(BIDDER_CODE + ': Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
830+
utils.logWarn(LOG_WARN_PREFIX + 'Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
830831
return;
831832
}
832833
} else {
833834
if (!(bid.params.adSlot && bid.params.adUnit && bid.params.adUnitIndex && bid.params.width && bid.params.height)) {
834-
utils.logWarn(BIDDER_CODE + ': Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
835+
utils.logWarn(LOG_WARN_PREFIX + 'Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid));
835836
return;
836837
}
837838
}
@@ -841,7 +842,7 @@ export const spec = {
841842
if (bidCurrency === '') {
842843
bidCurrency = bid.params.currency || undefined;
843844
} else if (bid.params.hasOwnProperty('currency') && bidCurrency !== bid.params.currency) {
844-
utils.logWarn(BIDDER_CODE + ': Currency specifier ignored. Only one currency permitted.');
845+
utils.logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.');
845846
}
846847
bid.params.currency = bidCurrency;
847848
// check if dctr is added to more than 1 adunit
@@ -910,13 +911,13 @@ export const spec = {
910911
key_val: dctr.trim()
911912
}
912913
} else {
913-
utils.logWarn(BIDDER_CODE + ': Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
914+
utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
914915
}
915916
if (dctrArr.length > 1) {
916-
utils.logWarn(BIDDER_CODE + ': dctr value found in more than 1 adunits. Value from 1st adunit will be picked. Ignoring values from subsequent adunits');
917+
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');
917918
}
918919
} else {
919-
utils.logWarn(BIDDER_CODE + ': dctr value not found in 1st adunit, ignoring values from subsequent adunits');
920+
utils.logWarn(LOG_WARN_PREFIX + 'dctr value not found in 1st adunit, ignoring values from subsequent adunits');
920921
}
921922
}
922923

@@ -1004,7 +1005,7 @@ export const spec = {
10041005
url: syncurl
10051006
}];
10061007
} else {
1007-
utils.logWarn('PubMatic: Please enable iframe based user sync.');
1008+
utils.logWarn(LOG_WARN_PREFIX + 'Please enable iframe based user sync.');
10081009
}
10091010
},
10101011

0 commit comments

Comments
 (0)