-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathyieldmoBidAdapter.js
736 lines (666 loc) · 23.3 KB
/
yieldmoBidAdapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
import {
deepAccess,
deepSetValue,
getWindowTop,
isArray,
isArrayOfNums,
isBoolean,
isEmpty,
isInteger,
isNumber,
isStr,
logError,
parseQueryStringParameters,
parseUrl
} from '../src/utils.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {Renderer} from '../src/Renderer.js';
import {find, includes} from '../src/polyfill.js';
/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
* @typedef {import('../src/adapters/bidderFactory.js').BidderRequest} BidderRequest
* @typedef {import('../src/adapters/bidderFactory.js').ServerResponse} ServerResponse
* @typedef {import('../src/adapters/bidderFactory.js').ServerRequest} ServerRequest
*/
const BIDDER_CODE = 'yieldmo';
const GVLID = 173;
const CURRENCY = 'USD';
const TIME_TO_LIVE = 300;
const NET_REVENUE = true;
const PB_COOKIE_ASSIST_SYNC_ENDPOINT = `https://ads.yieldmo.com/pbcas`;
const BANNER_PATH = '/exchange/prebid';
const VIDEO_PATH = '/exchange/prebidvideo';
const STAGE_DOMAIN = 'https://ads-stg.yieldmo.com';
const PROD_DOMAIN = 'https://ads.yieldmo.com';
const OUTSTREAM_VIDEO_PLAYER_URL = 'https://prebid-outstream.yieldmo.com/bundle.js';
const OPENRTB_VIDEO_BIDPARAMS = ['mimes', 'startdelay', 'placement', 'plcmt', 'skipafter', 'protocols', 'api',
'playbackmethod', 'maxduration', 'minduration', 'pos', 'skip', 'skippable'];
const OPENRTB_VIDEO_SITEPARAMS = ['name', 'domain', 'cat', 'keywords'];
const LOCAL_WINDOW = getWindowTop();
const DEFAULT_PLAYBACK_METHOD = 2;
const DEFAULT_START_DELAY = 0;
const VAST_TIMEOUT = 15000;
const MAX_BANNER_REQUEST_URL_LENGTH = 8000;
const BANNER_REQUEST_PROPERTIES_TO_REDUCE = ['description', 'title', 'pr', 'page_url'];
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
gvlid: GVLID,
/**
* Determines whether or not the given bid request is valid.
* @param {object} bid bid to validate
* @return {boolean} true if valid, otherwise false
*/
isBidRequestValid: function (bid) {
return !!(bid && bid.adUnitCode && bid.bidId && (hasBannerMediaType(bid) || hasVideoMediaType(bid)) &&
validateVideoParams(bid));
},
/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server.
* @param {BidderRequest} bidderRequest bidder request object.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (bidRequests, bidderRequest) {
const stage = isStage(bidderRequest);
const bannerUrl = getAdserverUrl(BANNER_PATH, stage);
const videoUrl = getAdserverUrl(VIDEO_PATH, stage);
const bannerBidRequests = bidRequests.filter(request => hasBannerMediaType(request));
const videoBidRequests = bidRequests.filter(request => hasVideoMediaType(request));
let serverRequests = [];
const eids = getEids(bidRequests[0]) || [];
const topicsData = getTopics(bidderRequest);
const cdep = getCdep(bidderRequest);
if (bannerBidRequests.length > 0) {
let serverRequest = {
pbav: '$prebid.version$',
p: [],
// TODO: is 'page' the right value here?
page_url: bidderRequest.refererInfo.page,
bust: new Date().getTime().toString(),
dnt: getDNT(),
description: getPageDescription(),
tmax: bidderRequest.timeout || 400,
userConsent: JSON.stringify({
// case of undefined, stringify will remove param
gdprApplies:
deepAccess(bidderRequest, 'gdprConsent.gdprApplies') || '',
cmp: deepAccess(bidderRequest, 'gdprConsent.consentString') || '',
gpp: deepAccess(bidderRequest, 'gppConsent.gppString') || '',
gpp_sid:
deepAccess(bidderRequest, 'gppConsent.applicableSections') || [],
}),
us_privacy: deepAccess(bidderRequest, 'uspConsent') || '',
};
if (topicsData) {
serverRequest.topics = JSON.stringify(topicsData);
}
const gpc = getGPCSignal(bidderRequest);
if (gpc) {
serverRequest.gpc = gpc;
}
if (cdep) {
serverRequest.cdep = cdep;
}
if (canAccessTopWindow()) {
serverRequest.pr = (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || '';
serverRequest.scrd = LOCAL_WINDOW.devicePixelRatio || 0;
serverRequest.title = LOCAL_WINDOW.document.title || '';
serverRequest.w = LOCAL_WINDOW.innerWidth;
serverRequest.h = LOCAL_WINDOW.innerHeight;
}
const mtp = window.navigator.maxTouchPoints;
if (mtp) {
serverRequest.mtp = mtp;
}
bannerBidRequests.forEach(request => {
serverRequest.p.push(addPlacement(request));
const pubcid = getId(request, 'pubcid');
if (pubcid) {
serverRequest.pubcid = pubcid;
} else if (request.crumbs && request.crumbs.pubcid) {
serverRequest.pubcid = request.crumbs.pubcid;
}
const tdid = getId(request, 'tdid');
if (tdid) {
serverRequest.tdid = tdid;
}
const criteoId = getId(request, 'criteoId');
if (criteoId) {
serverRequest.cri_prebid = criteoId;
}
if (request.schain) {
serverRequest.schain = JSON.stringify(request.schain);
}
if (deepAccess(request, 'params.lr_env')) {
serverRequest.ats_envelope = request.params.lr_env;
}
});
serverRequest.p = '[' + serverRequest.p.toString() + ']';
if (eids.length) {
serverRequest.eids = JSON.stringify(eids);
};
// check if url exceeded max length
const fullUrl = `${bannerUrl}?${parseQueryStringParameters(serverRequest)}`;
let extraCharacters = fullUrl.length - MAX_BANNER_REQUEST_URL_LENGTH;
if (extraCharacters > 0) {
for (let i = 0; i < BANNER_REQUEST_PROPERTIES_TO_REDUCE.length; i++) {
extraCharacters = shortcutProperty(extraCharacters, serverRequest, BANNER_REQUEST_PROPERTIES_TO_REDUCE[i]);
if (extraCharacters <= 0) {
break;
}
}
}
serverRequests.push({
method: 'GET',
url: bannerUrl,
data: serverRequest
});
}
if (videoBidRequests.length > 0) {
const serverRequest = openRtbRequest(videoBidRequests, bidderRequest);
if (topicsData) {
serverRequest.topics = topicsData;
}
if (eids.length) {
deepSetValue(serverRequest, 'user.ext.eids', eids);
};
serverRequests.push({
method: 'POST',
url: videoUrl,
data: serverRequest
});
}
return serverRequests;
},
/**
* Makes Yieldmo Ad Server response compatible to Prebid specs
* @param {ServerResponse} serverResponse successful response from Ad Server
* @param {ServerRequest} bidRequest
* @return {Bid[]} an array of bids
*/
interpretResponse: function (serverResponse, bidRequest) {
let bids = [];
const data = serverResponse.body;
if (data.length > 0) {
data.forEach(response => {
if (response.cpm > 0) {
bids.push(createNewBannerBid(response));
}
});
}
if (data.seatbid) {
const seatbids = data.seatbid.reduce((acc, seatBid) => acc.concat(seatBid.bid), []);
seatbids.forEach(bid => bids.push(createNewVideoBid(bid, bidRequest)));
}
return bids;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent = {}, uspConsent = '') {
const syncs = [];
const gdprFlag = `&gdpr=${gdprConsent.gdprApplies ? 1 : 0}`;
const gdprString = `&gdpr_consent=${encodeURIComponent((gdprConsent.consentString || ''))}`;
const usPrivacy = `us_privacy=${encodeURIComponent(uspConsent)}`;
const pbCookieAssistSyncUrl = `${PB_COOKIE_ASSIST_SYNC_ENDPOINT}?${usPrivacy}${gdprFlag}${gdprString}`;
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: pbCookieAssistSyncUrl + '&type=iframe'
});
} else if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: pbCookieAssistSyncUrl + '&type=image'
});
}
return syncs;
}
};
registerBidder(spec);
/***************************************
* Helper Functions
***************************************/
/**
* @param {BidRequest} bidRequest bid request
*/
function hasBannerMediaType(bidRequest) {
return !!deepAccess(bidRequest, 'mediaTypes.banner');
}
/**
* @param {BidRequest} bidRequest bid request
*/
function hasVideoMediaType(bidRequest) {
return !!deepAccess(bidRequest, 'mediaTypes.video');
}
/**
* Adds placement information to array
* @param request bid request
*/
function addPlacement(request) {
const gpid = deepAccess(request, 'ortb2Imp.ext.gpid') || deepAccess(request, 'ortb2Imp.ext.data.pbadslot');
const placementInfo = {
placement_id: request.adUnitCode,
callback_id: request.bidId,
sizes: request.mediaTypes.banner.sizes
};
if (request.params) {
if (request.params.placementId) {
placementInfo.ym_placement_id = request.params.placementId;
}
const bidfloor = getBidFloor(request, BANNER);
if (bidfloor) {
placementInfo.bidFloor = bidfloor;
}
}
if (gpid) {
placementInfo.gpid = gpid;
}
// get the transaction id for the banner bid.
const transactionId = deepAccess(request, 'ortb2Imp.ext.tid');
if (transactionId) {
placementInfo.tid = transactionId;
}
if (request.auctionId) {
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
placementInfo.auctionId = request.auctionId;
}
return JSON.stringify(placementInfo);
}
/**
* creates a new banner bid with response information
* @param response server response
*/
function createNewBannerBid(response) {
return {
dealId: response.publisherDealId,
requestId: response['callback_id'],
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creative_id,
currency: CURRENCY,
netRevenue: NET_REVENUE,
ttl: TIME_TO_LIVE,
ad: response.ad,
meta: {
advertiserDomains: response.adomain || [],
mediaType: BANNER,
},
};
}
/**
* creates a new video bid with response information
* @param response openRTB server response
* @param bidRequest server request
*/
function createNewVideoBid(response, bidRequest) {
const imp = find((deepAccess(bidRequest, 'data.imp') || []), imp => imp.id === response.impid);
let result = {
dealId: response.dealid,
requestId: imp.id,
cpm: response.price,
width: imp.video.w,
height: imp.video.h,
creativeId: response.crid || response.adid,
currency: CURRENCY,
netRevenue: NET_REVENUE,
mediaType: VIDEO,
ttl: TIME_TO_LIVE,
vastXml: response.adm,
meta: {
advertiserDomains: response.adomain || [],
mediaType: VIDEO,
},
};
if (imp.video.plcmt && imp.video.plcmt !== 1) {
const renderer = Renderer.install({
url: OUTSTREAM_VIDEO_PLAYER_URL,
config: {
width: result.width,
height: result.height,
vastTimeout: VAST_TIMEOUT,
maxAllowedVastTagRedirects: 5,
allowVpaid: true,
autoPlay: true,
preload: true,
mute: true,
},
id: imp.tagid,
loaded: false,
});
renderer.setRender(function (bid) {
bid.renderer.push(() => {
const { id, config } = bid.renderer;
window.YMoutstreamPlayer(bid, id, config);
});
});
result.renderer = renderer;
}
return result;
}
/**
* Detects whether dnt is true
* @returns true if user enabled dnt
*/
function getDNT() {
return (
window.doNotTrack === '1' || window.navigator.doNotTrack === '1' || false
);
}
/**
* get page description
*/
function getPageDescription() {
if (document.querySelector('meta[name="description"]')) {
return document
.querySelector('meta[name="description"]')
.getAttribute('content') || ''; // Value of the description metadata from the publisher's page.
} else {
return '';
}
}
/**
* Gets an id from the userId object if it exists
* @param {*} request
* @param {*} idType
* @returns an id if there is one, or undefined
*/
function getId(request, idType) {
return (typeof deepAccess(request, 'userId') === 'object') ? request.userId[idType] : undefined;
}
/**
* @param {BidRequest[]} bidRequests bid request object
* @param {BidderRequest} bidderRequest bidder request object
* @return Object OpenRTB request object
*/
function openRtbRequest(bidRequests, bidderRequest) {
const schain = bidRequests[0].schain;
let openRtbRequest = {
id: bidRequests[0].bidderRequestId,
tmax: bidderRequest.timeout || 400,
at: 1,
imp: bidRequests.map(bidRequest => openRtbImpression(bidRequest)),
site: openRtbSite(bidRequests[0], bidderRequest),
device: deepAccess(bidderRequest, 'ortb2.device'),
badv: bidRequests[0].params.badv || [],
bcat: deepAccess(bidderRequest, 'bcat') || bidRequests[0].params.bcat || [],
ext: {
prebid: '$prebid.version$',
},
ats_envelope: bidRequests[0].params.lr_env,
};
if (schain) {
openRtbRequest.schain = schain;
}
const gpc = getGPCSignal(bidderRequest);
if (gpc) {
deepSetValue(openRtbRequest, 'regs.ext.gpc', gpc);
}
if (bidRequests[0].auctionId) {
openRtbRequest.auctionId = bidRequests[0].auctionId;
}
populateOpenRtbGdpr(openRtbRequest, bidderRequest);
return openRtbRequest;
}
function getGPCSignal(bidderRequest) {
const gpc = deepAccess(bidderRequest, 'ortb2.regs.ext.gpc');
return gpc;
}
function getCdep(bidderRequest) {
const cdep = deepAccess(bidderRequest, 'ortb2.device.ext.cdep') || null;
return cdep;
}
function getTopics(bidderRequest) {
const userData = deepAccess(bidderRequest, 'ortb2.user.data') || [];
const topicsData = userData.filter((dataObj) => {
const segtax = dataObj.ext?.segtax;
return segtax >= 600 && segtax <= 609;
})[0];
if (topicsData) {
let topicsObject = {
taxonomy: topicsData.ext.segtax,
classifier: topicsData.ext.segclass,
// topics needs to be array of numbers
topics: Object.values(topicsData.segment).map(i => Number(i)),
};
return topicsObject;
}
return null;
}
/**
* @param {BidRequest} bidRequest bidder request object.
* @return Object OpenRTB's 'imp' (impression) object
*/
function openRtbImpression(bidRequest) {
const gpid = deepAccess(bidRequest, 'ortb2Imp.ext.gpid') || deepAccess(bidRequest, 'ortb2Imp.ext.data.pbadslot');
const size = extractPlayerSize(bidRequest);
const imp = {
id: bidRequest.bidId,
tagid: bidRequest.adUnitCode,
bidfloor: getBidFloor(bidRequest, VIDEO),
ext: {
placement_id: bidRequest.params.placementId,
tid: deepAccess(bidRequest, 'ortb2Imp.ext.tid')
},
video: {
w: size[0],
h: size[1],
linearity: 1
}
};
const mediaTypesParams = deepAccess(bidRequest, 'mediaTypes.video', {});
Object.keys(mediaTypesParams)
.filter(param => includes(OPENRTB_VIDEO_BIDPARAMS, param))
.forEach(param => imp.video[param] = mediaTypesParams[param]);
const videoParams = deepAccess(bidRequest, 'params.video', {});
Object.keys(videoParams)
.filter(param => includes(OPENRTB_VIDEO_BIDPARAMS, param))
.forEach(param => imp.video[param] = videoParams[param]);
if (imp.video.skippable) {
imp.video.skip = 1;
delete imp.video.skippable;
}
if (imp.video.plcmt !== 1 || imp.video.placement !== 1) {
imp.video.startdelay = DEFAULT_START_DELAY;
imp.video.playbackmethod = [ DEFAULT_PLAYBACK_METHOD ];
}
if (gpid) {
imp.ext.gpid = gpid;
}
return imp;
}
function getBidFloor(bidRequest, mediaType) {
let floorInfo = {};
if (typeof bidRequest.getFloor === 'function') {
floorInfo = bidRequest.getFloor({ currency: CURRENCY, mediaType, size: '*' });
}
return floorInfo.floor || bidRequest.params.bidfloor || bidRequest.params.bidFloor || 0;
}
/**
* @param {BidRequest} bidRequest bidder request object.
* @return [number, number] || null Player's width and height, or undefined otherwise.
*/
function extractPlayerSize(bidRequest) {
const sizeArr = deepAccess(bidRequest, 'mediaTypes.video.playerSize');
if (isArrayOfNums(sizeArr, 2)) {
return sizeArr;
} else if (isArray(sizeArr) && isArrayOfNums(sizeArr[0], 2)) {
return sizeArr[0];
}
return null;
}
/**
* @param {BidRequest} bidRequest bid request object
* @param {BidderRequest} bidderRequest bidder request object
* @return Object OpenRTB's 'site' object
*/
function openRtbSite(bidRequest, bidderRequest) {
let result = {};
const loc = parseUrl(deepAccess(bidderRequest, 'refererInfo.page'));
if (!isEmpty(loc)) {
result.page = `${loc.protocol}://${loc.hostname}${loc.pathname}`;
}
if (bidderRequest.refererInfo?.ref) {
result.ref = bidderRequest.refererInfo.ref;
}
const keywords = document.getElementsByTagName('meta')['keywords'];
if (keywords && keywords.content) {
result.keywords = keywords.content;
}
const siteParams = deepAccess(bidRequest, 'params.site');
if (siteParams) {
Object.keys(siteParams)
.filter(param => includes(OPENRTB_VIDEO_SITEPARAMS, param))
.forEach(param => result[param] = siteParams[param]);
}
return result;
}
/**
* Updates openRtbRequest with GDPR info from bidderRequest, if present.
* @param {Object} openRtbRequest OpenRTB's request to update.
* @param {BidderRequest} bidderRequest bidder request object.
*/
function populateOpenRtbGdpr(openRtbRequest, bidderRequest) {
const gdpr = bidderRequest.gdprConsent;
const gpp = deepAccess(bidderRequest, 'gppConsent.gppString');
const gppsid = deepAccess(bidderRequest, 'gppConsent.applicableSections');
if (gpp) {
deepSetValue(openRtbRequest, 'regs.ext.gpp', gpp);
} else {
deepSetValue(openRtbRequest, 'regs.ext.gdpr', gdpr && gdpr.gdprApplies ? 1 : 0);
deepSetValue(openRtbRequest, 'user.ext.consent', gdpr && gdpr.consentString ? gdpr.consentString : '');
}
if (gppsid && gppsid.length > 0) {
deepSetValue(openRtbRequest, 'regs.ext.gpp_sid', gppsid);
}
const uspConsent = deepAccess(bidderRequest, 'uspConsent');
if (!gpp && uspConsent) {
deepSetValue(openRtbRequest, 'regs.ext.us_privacy', uspConsent);
}
}
/**
* Determines whether or not the given video bid request is valid. If it's not a video bid, returns true.
* @param {object} bid bid to validate
* @return {boolean} true if valid, otherwise false
*/
function validateVideoParams(bid) {
if (!hasVideoMediaType(bid)) {
return true;
}
const paramRequired = (paramStr, value, conditionStr) => {
let error = `"${paramStr}" is required`;
if (conditionStr) {
error += ' when ' + conditionStr;
}
throw new Error(error);
};
const paramInvalid = (paramStr, value, expectedStr) => {
expectedStr = expectedStr ? ', expected: ' + expectedStr : '';
value = JSON.stringify(value);
throw new Error(`"${paramStr}"=${value} is invalid${expectedStr}`);
};
const isDefined = val => typeof val !== 'undefined';
const validate = (fieldPath, validateCb, errorCb, errorCbParam) => {
if (fieldPath.indexOf('video') === 0) {
const valueFieldPath = 'params.' + fieldPath;
const mediaFieldPath = 'mediaTypes.' + fieldPath;
const valueParams = deepAccess(bid, valueFieldPath);
const mediaTypesParams = deepAccess(bid, mediaFieldPath);
const hasValidValueParams = validateCb(valueParams);
const hasValidMediaTypesParams = validateCb(mediaTypesParams);
if (hasValidValueParams) return valueParams;
else if (hasValidMediaTypesParams) return hasValidMediaTypesParams;
else {
if (!hasValidValueParams) errorCb(valueFieldPath, valueParams, errorCbParam);
else if (!hasValidMediaTypesParams) errorCb(mediaFieldPath, mediaTypesParams, errorCbParam);
}
return valueParams || mediaTypesParams;
} else {
const value = deepAccess(bid, fieldPath);
if (!validateCb(value)) {
errorCb(fieldPath, value, errorCbParam);
}
return value;
}
};
try {
validate('video.context', val => !isEmpty(val), paramRequired);
validate('params.placementId', val => !isEmpty(val), paramRequired);
validate('video.playerSize', val => isArrayOfNums(val, 2) ||
(isArray(val) && val.every(v => isArrayOfNums(v, 2))),
paramInvalid, 'array of 2 integers, ex: [640,480] or [[640,480]]');
validate('video.mimes', val => isDefined(val), paramRequired);
validate('video.mimes', val => isArray(val) && val.every(v => isStr(v)), paramInvalid,
'array of strings, ex: ["video/mp4"]');
validate('video.protocols', val => isDefined(val), paramRequired);
validate('video.api', val => isDefined(val), paramRequired);
validate('video.api', val => isArrayOfNums(val) && val.every(v => (v >= 1 && v <= 6)),
paramInvalid, 'array of numbers, ex: [2,3]');
validate('video.playbackmethod', val => !isDefined(val) || isArrayOfNums(val), paramInvalid,
'array of integers, ex: [2,6]');
validate('video.maxduration', val => isDefined(val), paramRequired);
validate('video.maxduration', val => isInteger(val), paramInvalid);
validate('video.minduration', val => !isDefined(val) || isNumber(val), paramInvalid);
validate('video.skippable', val => !isDefined(val) || isBoolean(val), paramInvalid);
validate('video.skipafter', val => !isDefined(val) || isNumber(val), paramInvalid);
validate('video.pos', val => !isDefined(val) || isNumber(val), paramInvalid);
validate('params.badv', val => !isDefined(val) || isArray(val), paramInvalid,
'array of strings, ex: ["ford.com","pepsi.com"]');
validate('params.bcat', val => !isDefined(val) || isArray(val), paramInvalid,
'array of strings, ex: ["IAB1-5","IAB1-6"]');
return true;
} catch (e) {
logError(e.message);
return false;
}
}
/**
* Shortcut object property and check if required characters count was deleted
*
* @param {number} extraCharacters count of characters to remove
* @param {object} target object on which string property length should be reduced
* @param {string} propertyName name of property to reduce
* @return {number} 0 if required characters count was removed otherwise count of how many left
*/
function shortcutProperty(extraCharacters, target, propertyName) {
if (target[propertyName].length > extraCharacters) {
target[propertyName] = target[propertyName].substring(0, target[propertyName].length - extraCharacters);
return 0
}
const charactersLeft = extraCharacters - target[propertyName].length;
target[propertyName] = '';
return charactersLeft;
}
/**
* Creates and returnes eids arr using createEidsArray from './userId/eids.js' module;
* @param {Object} bidRequest OpenRTB's request as a cource of userId.
* @return array of eids objects
*/
function getEids(bidRequest) {
if (deepAccess(bidRequest, 'userIdAsEids')) {
return bidRequest.userIdAsEids || [];
}
};
/**
* Check if top window can be accessed
*
* @return {boolean} true if can access top window otherwise false
*/
function canAccessTopWindow() {
try {
if (getWindowTop().location.href) {
return true;
}
} catch (error) {
return false;
}
}
function isStage(bidderRequest) {
return !!bidderRequest.refererInfo?.referer?.includes('pb_force_a');
}
function getAdserverUrl(path, stage) {
const domain = stage ? STAGE_DOMAIN : PROD_DOMAIN;
return `${domain}${path}`;
}