-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprebid.js
More file actions
2810 lines (2388 loc) · 84.4 KB
/
prebid.js
File metadata and controls
2810 lines (2388 loc) · 84.4 KB
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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /** @module pbjs */
var _utils = __webpack_require__(1);
__webpack_require__(3);
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
// if pbjs already exists in global document scope, use it, if not, create the object
window.pbjs = window.pbjs || {};
window.pbjs.que = window.pbjs.que || [];
var pbjs = window.pbjs;
var CONSTANTS = __webpack_require__(2);
var utils = __webpack_require__(1);
var bidmanager = __webpack_require__(4);
var adaptermanager = __webpack_require__(6);
var bidfactory = __webpack_require__(10);
var adloader = __webpack_require__(9);
var events = __webpack_require__(5);
/* private variables */
var objectType_function = 'function';
var objectType_undefined = 'undefined';
var objectType_object = 'object';
var BID_WON = CONSTANTS.EVENTS.BID_WON;
var BID_TIMEOUT = CONSTANTS.EVENTS.BID_TIMEOUT;
var pb_bidsTimedOut = false;
var auctionRunning = false;
var presetTargeting = [];
var pbTargetingKeys = [];
var eventValidators = {
bidWon: checkDefinedPlacement
};
/* Public vars */
pbjs._bidsRequested = [];
pbjs._bidsReceived = [];
pbjs._adsReceived = [];
pbjs._sendAllBids = false;
//default timeout for all bids
pbjs.bidderTimeout = pbjs.bidderTimeout || 3000;
pbjs.logging = pbjs.logging || false;
//let the world know we are loaded
pbjs.libLoaded = true;
//version auto generated from build
utils.logInfo('Prebid.js v0.11.0 loaded');
//create adUnit array
pbjs.adUnits = pbjs.adUnits || [];
/**
* Command queue that functions will execute once prebid.js is loaded
* @param {function} cmd Annoymous function to execute
* @alias module:pbjs.que.push
*/
pbjs.que.push = function (cmd) {
if ((typeof cmd === 'undefined' ? 'undefined' : _typeof(cmd)) === objectType_function) {
try {
cmd.call();
} catch (e) {
utils.logError('Error processing command :' + e.message);
}
} else {
utils.logError('Commands written into pbjs.que.push must wrapped in a function');
}
};
function processQue() {
for (var i = 0; i < pbjs.que.length; i++) {
if (_typeof(pbjs.que[i].called) === objectType_undefined) {
try {
pbjs.que[i].call();
pbjs.que[i].called = true;
} catch (e) {
utils.logError('Error processing command :', 'prebid.js', e);
}
}
}
}
function timeOutBidders() {
if (!pb_bidsTimedOut) {
pb_bidsTimedOut = true;
var timedOutBidders = bidmanager.getTimedOutBidders();
events.emit(BID_TIMEOUT, timedOutBidders);
}
}
function checkDefinedPlacement(id) {
var placementCodes = pbjs._bidsRequested.map(function (bidSet) {
return bidSet.bids.map(function (bid) {
return bid.placementCode;
});
}).reduce(_utils.flatten).filter(_utils.uniques);
if (!utils.contains(placementCodes, id)) {
utils.logError('The "' + id + '" placement is not defined.');
return;
}
return true;
}
function resetPresetTargeting() {
if ((0, _utils.isGptPubadsDefined)()) {
window.googletag.pubads().getSlots().forEach(function (slot) {
pbTargetingKeys.forEach(function (key) {
slot.setTargeting(key, null);
});
});
}
}
function setTargeting(targetingConfig) {
window.googletag.pubads().getSlots().forEach(function (slot) {
targetingConfig.filter(function (targeting) {
return Object.keys(targeting)[0] === slot.getAdUnitPath() || Object.keys(targeting)[0] === slot.getSlotElementId();
}).forEach(function (targeting) {
return targeting[Object.keys(targeting)[0]].forEach(function (key) {
key[Object.keys(key)[0]].map(function (value) {
utils.logMessage('Attempting to set key value for slot: ' + slot.getSlotElementId() + ' key: ' + Object.keys(key)[0] + ' value: ' + value);
return value;
}).forEach(function (value) {
slot.setTargeting(Object.keys(key)[0], value);
});
});
});
});
}
function isNotSetByPb(key) {
return pbTargetingKeys.indexOf(key) === -1;
}
function getPresetTargeting() {
if ((0, _utils.isGptPubadsDefined)()) {
presetTargeting = function getPresetTargeting() {
return window.googletag.pubads().getSlots().map(function (slot) {
return _defineProperty({}, slot.getAdUnitPath(), slot.getTargetingKeys().filter(isNotSetByPb).map(function (key) {
return _defineProperty({}, key, slot.getTargeting(key));
}));
});
}();
}
}
function getWinningBidTargeting() {
var winners = pbjs._bidsReceived.map(function (bid) {
return bid.adUnitCode;
}).filter(_utils.uniques).map(function (adUnitCode) {
return pbjs._bidsReceived.filter(function (bid) {
return bid.adUnitCode === adUnitCode ? bid : null;
}).reduce(_utils.getHighestCpm, {
adUnitCode: adUnitCode,
cpm: 0,
adserverTargeting: {},
timeToRespond: 0
});
});
// winning bids with deals need an hb_deal targeting key
winners.filter(function (bid) {
return bid.dealId;
}).map(function (bid) {
return bid.adserverTargeting.hb_deal = bid.dealId;
});
winners = winners.map(function (winner) {
return _defineProperty({}, winner.adUnitCode, Object.keys(winner.adserverTargeting, function (key) {
return key;
}).map(function (key) {
return _defineProperty({}, key.substring(0, 20), [winner.adserverTargeting[key]]);
}));
});
return winners;
}
function getDealTargeting() {
return pbjs._bidsReceived.filter(function (bid) {
return bid.dealId;
}).map(function (bid) {
var dealKey = 'hb_deal_' + bid.bidderCode;
return _defineProperty({}, bid.adUnitCode, CONSTANTS.TARGETING_KEYS.map(function (key) {
return _defineProperty({}, (key + '_' + bid.bidderCode).substring(0, 20), [bid.adserverTargeting[key]]);
}).concat(_defineProperty({}, dealKey, [bid.adserverTargeting[dealKey]])));
});
}
/**
* Get custom targeting keys for bids that have `alwaysUseBid=true`.
*/
function getAlwaysUseBidTargeting() {
return pbjs._bidsReceived.map(function (bid) {
if (bid.alwaysUseBid) {
var _ret = function () {
var standardKeys = CONSTANTS.TARGETING_KEYS;
return {
v: _defineProperty({}, bid.adUnitCode, Object.keys(bid.adserverTargeting, function (key) {
return key;
}).map(function (key) {
// Get only the non-standard keys of the losing bids, since we
// don't want to override the standard keys of the winning bid.
if (standardKeys.indexOf(key) > -1) {
return;
}
return _defineProperty({}, key.substring(0, 20), [bid.adserverTargeting[key]]);
}).filter(function (key) {
return key;
}))
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
}
}).filter(function (bid) {
return bid;
}); // removes empty elements in array;
}
function getBidLandscapeTargeting() {
var standardKeys = CONSTANTS.TARGETING_KEYS;
return pbjs._bidsReceived.map(function (bid) {
if (bid.adserverTargeting) {
return _defineProperty({}, bid.adUnitCode, standardKeys.map(function (key) {
return _defineProperty({}, (key + '_' + bid.bidderCode).substring(0, 20), [bid.adserverTargeting[key]]);
}));
}
}).filter(function (bid) {
return bid;
}); // removes empty elements in array
}
function getAllTargeting() {
// Get targeting for the winning bid. Add targeting for any bids that have
// `alwaysUseBid=true`. If sending all bids is enabled, add targeting for losing bids.
var targeting = getDealTargeting().concat(getWinningBidTargeting()).concat(getAlwaysUseBidTargeting()).concat(pbjs._sendAllBids ? getBidLandscapeTargeting() : []);
//store a reference of the targeting keys
targeting.map(function (adUnitCode) {
Object.keys(adUnitCode).map(function (key) {
adUnitCode[key].map(function (targetKey) {
if (pbTargetingKeys.indexOf(Object.keys(targetKey)[0]) === -1) {
pbTargetingKeys = Object.keys(targetKey).concat(pbTargetingKeys);
}
});
});
});
return targeting;
}
//////////////////////////////////
// //
// Start Public APIs //
// //
//////////////////////////////////
/**
* This function returns the query string targeting parameters available at this moment for a given ad unit. Note that some bidder's response may not have been received if you call this function too quickly after the requests are sent.
* @param {string} [adunitCode] adUnitCode to get the bid responses for
* @alias module:pbjs.getAdserverTargetingForAdUnitCodeStr
* @return {array} returnObj return bids array
*/
pbjs.getAdserverTargetingForAdUnitCodeStr = function (adunitCode) {
utils.logInfo('Invoking pbjs.getAdserverTargetingForAdUnitCodeStr', arguments);
// call to retrieve bids array
if (adunitCode) {
var res = pbjs.getAdserverTargetingForAdUnitCode(adunitCode);
return utils.transformAdServerTargetingObj(res);
} else {
utils.logMessage('Need to call getAdserverTargetingForAdUnitCodeStr with adunitCode');
}
};
/**
* This function returns the query string targeting parameters available at this moment for a given ad unit. Note that some bidder's response may not have been received if you call this function too quickly after the requests are sent.
* @param adUnitCode {string} adUnitCode to get the bid responses for
* @returns {object} returnObj return bids
*/
pbjs.getAdserverTargetingForAdUnitCode = function (adUnitCode) {
utils.logInfo('Invoking pbjs.getAdserverTargetingForAdUnitCode', arguments);
return getAllTargeting().filter(function (targeting) {
return (0, _utils.getKeys)(targeting)[0] === adUnitCode;
}).map(function (targeting) {
return _defineProperty({}, Object.keys(targeting)[0], targeting[Object.keys(targeting)[0]].map(function (target) {
return _defineProperty({}, Object.keys(target)[0], target[Object.keys(target)[0]].join(', '));
}).reduce(function (p, c) {
return _extends(c, p);
}, {}));
}).reduce(function (accumulator, targeting) {
var key = Object.keys(targeting)[0];
accumulator[key] = _extends({}, accumulator[key], targeting[key]);
return accumulator;
}, {})[adUnitCode];
};
/**
* returns all ad server targeting for all ad units
* @return {object} Map of adUnitCodes and targeting values []
* @alias module:pbjs.getAdserverTargeting
*/
pbjs.getAdserverTargeting = function () {
utils.logInfo('Invoking pbjs.getAdserverTargeting', arguments);
return getAllTargeting().map(function (targeting) {
return _defineProperty({}, Object.keys(targeting)[0], targeting[Object.keys(targeting)[0]].map(function (target) {
return _defineProperty({}, Object.keys(target)[0], target[Object.keys(target)[0]].join(', '));
}).reduce(function (p, c) {
return _extends(c, p);
}, {}));
}).reduce(function (accumulator, targeting) {
var key = Object.keys(targeting)[0];
accumulator[key] = _extends({}, accumulator[key], targeting[key]);
return accumulator;
}, {});
};
/**
* This function returns the bid responses at the given moment.
* @alias module:pbjs.getBidResponses
* @return {object} map | object that contains the bidResponses
*/
pbjs.getBidResponses = function () {
utils.logInfo('Invoking pbjs.getBidResponses', arguments);
return pbjs._bidsReceived.map(function (bid) {
return bid.adUnitCode;
}).filter(_utils.uniques).map(function (adUnitCode) {
return pbjs._bidsReceived.filter(function (bid) {
return bid.adUnitCode === adUnitCode;
});
}).map(function (bids) {
return _defineProperty({}, bids[0].adUnitCode, { bids: bids });
}).reduce(function (a, b) {
return _extends(a, b);
}, {});
};
/**
* Returns bidResponses for the specified adUnitCode
* @param {String} adUnitCode adUnitCode
* @alias module:pbjs.getBidResponsesForAdUnitCode
* @return {Object} bidResponse object
*/
pbjs.getBidResponsesForAdUnitCode = function (adUnitCode) {
var bids = pbjs._bidsReceived.filter(function (bid) {
return bid.adUnitCode === adUnitCode;
});
return {
bids: bids
};
};
/**
* Set query string targeting on all GPT ad units.
* @alias module:pbjs.setTargetingForGPTAsync
*/
pbjs.setTargetingForGPTAsync = function () {
utils.logInfo('Invoking pbjs.setTargetingForGPTAsync', arguments);
if (!(0, _utils.isGptPubadsDefined)()) {
utils.logError('window.googletag is not defined on the page');
return;
}
//first reset any old targeting
getPresetTargeting();
resetPresetTargeting();
//now set new targeting keys
setTargeting(getAllTargeting());
};
/**
* Returns a bool if all the bids have returned or timed out
* @alias module:pbjs.allBidsAvailable
* @return {bool} all bids available
*/
pbjs.allBidsAvailable = function () {
utils.logInfo('Invoking pbjs.allBidsAvailable', arguments);
return bidmanager.bidsBackAll();
};
/**
* This function will render the ad (based on params) in the given iframe document passed through. Note that doc SHOULD NOT be the parent document page as we can't doc.write() asynchrounsly
* @param {object} doc document
* @param {string} id bid id to locate the ad
* @alias module:pbjs.renderAd
*/
pbjs.renderAd = function (doc, id) {
utils.logInfo('Invoking pbjs.renderAd', arguments);
utils.logMessage('Calling renderAd with adId :' + id);
if (doc && id) {
try {
//lookup ad by ad Id
var adObject = pbjs._bidsReceived.find(function (bid) {
return bid.adId === id;
});
if (adObject) {
//emit 'bid won' event here
events.emit(BID_WON, adObject);
var height = adObject.height;
var width = adObject.width;
var url = adObject.adUrl;
var ad = adObject.ad;
if (ad) {
doc.write(ad);
doc.close();
if (doc.defaultView && doc.defaultView.frameElement) {
doc.defaultView.frameElement.width = width;
doc.defaultView.frameElement.height = height;
}
}
//doc.body.style.width = width;
//doc.body.style.height = height;
else if (url) {
doc.write('<IFRAME SRC="' + url + '" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true" WIDTH="' + width + '" HEIGHT="' + height + '"></IFRAME>');
doc.close();
if (doc.defaultView && doc.defaultView.frameElement) {
doc.defaultView.frameElement.width = width;
doc.defaultView.frameElement.height = height;
}
} else {
utils.logError('Error trying to write ad. No ad for bid response id: ' + id);
}
} else {
utils.logError('Error trying to write ad. Cannot find ad by given id : ' + id);
}
} catch (e) {
utils.logError('Error trying to write ad Id :' + id + ' to the page:' + e.message);
}
} else {
utils.logError('Error trying to write ad Id :' + id + ' to the page. Missing document or adId');
}
};
/**
* Remove adUnit from the pbjs configuration
* @param {String} adUnitCode the adUnitCode to remove
* @alias module:pbjs.removeAdUnit
*/
pbjs.removeAdUnit = function (adUnitCode) {
utils.logInfo('Invoking pbjs.removeAdUnit', arguments);
if (adUnitCode) {
for (var i = 0; i < pbjs.adUnits.length; i++) {
if (pbjs.adUnits[i].code === adUnitCode) {
pbjs.adUnits.splice(i, 1);
}
}
}
};
pbjs.clearAuction = function () {
auctionRunning = false;
utils.logMessage('Prebid auction cleared');
};
/**
*
* @param bidsBackHandler
* @param timeout
* @param adUnits
* @param adUnitCodes
*/
pbjs.requestBids = function (_ref15) {
var bidsBackHandler = _ref15.bidsBackHandler;
var timeout = _ref15.timeout;
var adUnits = _ref15.adUnits;
var adUnitCodes = _ref15.adUnitCodes;
if (auctionRunning) {
utils.logError('Prebid Error: `pbjs.requestBids` was called while a previous auction was' + ' still running. Resubmit this request.');
return;
} else {
auctionRunning = true;
pbjs._bidsRequested = [];
pbjs._bidsReceived = [];
}
var cbTimeout = timeout || pbjs.bidderTimeout;
// use adUnits provided or from pbjs global
adUnits = adUnits || pbjs.adUnits;
// if specific adUnitCodes filter adUnits for those codes
if (adUnitCodes && adUnitCodes.length) {
adUnits = adUnits.filter(function (adUnit) {
return adUnitCodes.includes(adUnit.code);
});
}
if ((typeof bidsBackHandler === 'undefined' ? 'undefined' : _typeof(bidsBackHandler)) === objectType_function) {
bidmanager.addOneTimeCallback(bidsBackHandler);
}
utils.logInfo('Invoking pbjs.requestBids', arguments);
if (!adUnits || adUnits.length === 0) {
utils.logMessage('No adUnits configured. No bids requested.');
bidmanager.executeCallback();
return;
}
//set timeout for all bids
setTimeout(bidmanager.executeCallback, cbTimeout);
adaptermanager.callBids({ adUnits: adUnits, adUnitCodes: adUnitCodes, cbTimeout: cbTimeout });
};
/**
*
* Add adunit(s)
* @param {Array|String} adUnitArr Array of adUnits or single adUnit Object.
* @alias module:pbjs.addAdUnits
*/
pbjs.addAdUnits = function (adUnitArr) {
utils.logInfo('Invoking pbjs.addAdUnits', arguments);
if (utils.isArray(adUnitArr)) {
//append array to existing
pbjs.adUnits.push.apply(pbjs.adUnits, adUnitArr);
} else if ((typeof adUnitArr === 'undefined' ? 'undefined' : _typeof(adUnitArr)) === objectType_object) {
pbjs.adUnits.push(adUnitArr);
}
};
/**
* @param {String} event the name of the event
* @param {Function} handler a callback to set on event
* @param {String} id an identifier in the context of the event
*
* This API call allows you to register a callback to handle a Prebid.js event.
* An optional `id` parameter provides more finely-grained event callback registration.
* This makes it possible to register callback events for a specific item in the
* event context. For example, `bidWon` events will accept an `id` for ad unit code.
* `bidWon` callbacks registered with an ad unit code id will be called when a bid
* for that ad unit code wins the auction. Without an `id` this method registers the
* callback for every `bidWon` event.
*
* Currently `bidWon` is the only event that accepts an `id` parameter.
*/
pbjs.onEvent = function (event, handler, id) {
utils.logInfo('Invoking pbjs.onEvent', arguments);
if (!utils.isFn(handler)) {
utils.logError('The event handler provided is not a function and was not set on event "' + event + '".');
return;
}
if (id && !eventValidators[event].call(null, id)) {
utils.logError('The id provided is not valid for event "' + event + '" and no handler was set.');
return;
}
events.on(event, handler, id);
};
/**
* @param {String} event the name of the event
* @param {Function} handler a callback to remove from the event
* @param {String} id an identifier in the context of the event (see `pbjs.onEvent`)
*/
pbjs.offEvent = function (event, handler, id) {
utils.logInfo('Invoking pbjs.offEvent', arguments);
if (id && !eventValidators[event].call(null, id)) {
return;
}
events.off(event, handler, id);
};
/**
* Add a callback event
* @param {String} eventStr event to attach callback to Options: "allRequestedBidsBack" | "adUnitBidsBack"
* @param {Function} func function to execute. Paramaters passed into the function: (bidResObj), [adUnitCode]);
* @alias module:pbjs.addCallback
* @returns {String} id for callback
*/
pbjs.addCallback = function (eventStr, func) {
utils.logInfo('Invoking pbjs.addCallback', arguments);
var id = null;
if (!eventStr || !func || (typeof func === 'undefined' ? 'undefined' : _typeof(func)) !== objectType_function) {
utils.logError('error registering callback. Check method signature');
return id;
}
id = utils.getUniqueIdentifierStr;
bidmanager.addCallback(id, func, eventStr);
return id;
};
/**
* Remove a callback event
* //@param {string} cbId id of the callback to remove
* @alias module:pbjs.removeCallback
* @returns {String} id for callback
*/
pbjs.removeCallback = function () /* cbId */{
//todo
return null;
};
/**
* Wrapper to register bidderAdapter externally (adaptermanager.registerBidAdapter())
* @param {[type]} bidderAdaptor [description]
* @param {[type]} bidderCode [description]
* @return {[type]} [description]
*/
pbjs.registerBidAdapter = function (bidderAdaptor, bidderCode) {
utils.logInfo('Invoking pbjs.registerBidAdapter', arguments);
try {
adaptermanager.registerBidAdapter(bidderAdaptor(), bidderCode);
} catch (e) {
utils.logError('Error registering bidder adapter : ' + e.message);
}
};
/**
* Wrapper to register analyticsAdapter externally (adaptermanager.registerAnalyticsAdapter())
* @param {[type]} options [description]
*/
pbjs.registerAnalyticsAdapter = function (options) {
utils.logInfo('Invoking pbjs.registerAnalyticsAdapter', arguments);
try {
adaptermanager.registerAnalyticsAdapter(options);
} catch (e) {
utils.logError('Error registering analytics adapter : ' + e.message);
}
};
pbjs.bidsAvailableForAdapter = function (bidderCode) {
utils.logInfo('Invoking pbjs.bidsAvailableForAdapter', arguments);
pbjs._bidsRequested.find(function (bidderRequest) {
return bidderRequest.bidderCode === bidderCode;
}).bids.map(function (bid) {
return _extends(bid, bidfactory.createBid(1), {
bidderCode: bidderCode,
adUnitCode: bid.placementCode
});
}).map(function (bid) {
return pbjs._bidsReceived.push(bid);
});
};
/**
* Wrapper to bidfactory.createBid()
* @param {[type]} statusCode [description]
* @return {[type]} [description]
*/
pbjs.createBid = function (statusCode) {
utils.logInfo('Invoking pbjs.createBid', arguments);
return bidfactory.createBid(statusCode);
};
/**
* Wrapper to bidmanager.addBidResponse
* @param {[type]} adUnitCode [description]
* @param {[type]} bid [description]
*/
pbjs.addBidResponse = function (adUnitCode, bid) {
utils.logInfo('Invoking pbjs.addBidResponse', arguments);
bidmanager.addBidResponse(adUnitCode, bid);
};
/**
* Wrapper to adloader.loadScript
* @param {[type]} tagSrc [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
pbjs.loadScript = function (tagSrc, callback, useCache) {
utils.logInfo('Invoking pbjs.loadScript', arguments);
adloader.loadScript(tagSrc, callback, useCache);
};
/**
* Will enable sendinga prebid.js to data provider specified
* @param {object} config object {provider : 'string', options : {}}
*/
pbjs.enableAnalytics = function (config) {
if (config && !utils.isEmpty(config)) {
utils.logInfo('Invoking pbjs.enableAnalytics for: ', config);
adaptermanager.enableAnalytics(config);
} else {
utils.logError('pbjs.enableAnalytics should be called with option {}');
}
};
/**
* This will tell analytics that all bids received after are "timed out"
*/
pbjs.sendTimeoutEvent = function () {
utils.logInfo('Invoking pbjs.sendTimeoutEvent', arguments);
timeOutBidders();
};
pbjs.aliasBidder = function (bidderCode, alias) {
utils.logInfo('Invoking pbjs.aliasBidder', arguments);
if (bidderCode && alias) {
adaptermanager.aliasBidAdapter(bidderCode, alias);
} else {
utils.logError('bidderCode and alias must be passed as arguments', 'pbjs.aliasBidder');
}
};
pbjs.setPriceGranularity = function (granularity) {
utils.logInfo('Invoking pbjs.setPriceGranularity', arguments);
if (!granularity) {
utils.logError('Prebid Error: no value passed to `setPriceGranularity()`');
} else {
bidmanager.setPriceGranularity(granularity);
}
};
pbjs.enableSendAllBids = function () {
pbjs._sendAllBids = true;
};
processQue();
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
exports.uniques = uniques;
exports.flatten = flatten;
exports.getBidRequest = getBidRequest;
exports.getKeys = getKeys;
exports.getValue = getValue;
exports.getBidderCodes = getBidderCodes;
exports.isGptPubadsDefined = isGptPubadsDefined;
exports.getHighestCpm = getHighestCpm;
var CONSTANTS = __webpack_require__(2);
var objectType_object = 'object';
var objectType_string = 'string';
var objectType_number = 'number';
var _loggingChecked = false;
var t_Arr = 'Array';
var t_Str = 'String';
var t_Fn = 'Function';
var toString = Object.prototype.toString;
var infoLogger = null;
try {
infoLogger = console.info.bind(window.console);
} catch (e) {}
/*
* Substitutes into a string from a given map using the token
* Usage
* var str = 'text %%REPLACE%% this text with %%SOMETHING%%';
* var map = {};
* map['replace'] = 'it was subbed';
* map['something'] = 'something else';
* console.log(replaceTokenInString(str, map, '%%')); => "text it was subbed this text with something else"
*/
exports.replaceTokenInString = function (str, map, token) {
this._each(map, function (value, key) {
value = value === undefined ? '' : value;
var keyString = token + key.toUpperCase() + token;
var re = new RegExp(keyString, 'g');
str = str.replace(re, value);
});
return str;
};
/* utility method to get incremental integer starting from 1 */
var getIncrementalInteger = function () {
var count = 0;
return function () {
count++;
return count;
};
}();
function _getUniqueIdentifierStr() {
return getIncrementalInteger() + Math.random().toString(16).substr(2);
}
//generate a random string (to be used as a dynamic JSONP callback)
exports.getUniqueIdentifierStr = _getUniqueIdentifierStr;
/**
* Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,
* where each x is replaced with a random hexadecimal digit from 0 to f,
* and y is replaced with a random hexadecimal digit from 8 to b.
* https://gist.github.com/jed/982883 via node-uuid
*/
exports.generateUUID = function generateUUID(placeholder) {
return placeholder ? (placeholder ^ Math.random() * 16 >> placeholder / 4).toString(16) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, generateUUID);
};
exports.getBidIdParamater = function (key, paramsObj) {
if (paramsObj && paramsObj[key]) {
return paramsObj[key];
}
return '';
};
exports.tryAppendQueryString = function (existingUrl, key, value) {
if (value) {
return existingUrl += key + '=' + encodeURIComponent(value) + '&';
}
return existingUrl;
};
//parse a query string object passed in bid params
//bid params should be an object such as {key: "value", key1 : "value1"}
exports.parseQueryStringParameters = function (queryObj) {
var result = '';
for (var k in queryObj) {
if (queryObj.hasOwnProperty(k)) result += k + '=' + encodeURIComponent(queryObj[k]) + '&';
}
return result;
};
//transform an AdServer targeting bids into a query string to send to the adserver
exports.transformAdServerTargetingObj = function (targeting) {
// we expect to receive targeting for a single slot at a time
if (targeting && Object.getOwnPropertyNames(targeting).length > 0) {
return getKeys(targeting).map(function (key) {
return key + '=' + encodeURIComponent(getValue(targeting, key));
}).join('&');
} else {
return '';
}
};
//Copy all of the properties in the source objects over to the target object
//return the target object.
exports.extend = function (target, source) {
target = target || {};
this._each(source, function (value, prop) {
if (_typeof(source[prop]) === objectType_object) {
target[prop] = this.extend(target[prop], source[prop]);
} else {
target[prop] = source[prop];
}
});
return target;
};
/**
* Parse a GPT-Style general size Array like `[[300, 250]]` or `"300x250,970x90"` into an array of sizes `["300x250"]` or '['300x250', '970x90']'
* @param {array[array|number]} sizeObj Input array or double array [300,250] or [[300,250], [728,90]]
* @return {array[string]} Array of strings like `["300x250"]` or `["300x250", "728x90"]`
*/
exports.parseSizesInput = function (sizeObj) {
var parsedSizes = [];
//if a string for now we can assume it is a single size, like "300x250"
if ((typeof sizeObj === 'undefined' ? 'undefined' : _typeof(sizeObj)) === objectType_string) {
//multiple sizes will be comma-separated
var sizes = sizeObj.split(',');
//regular expression to match strigns like 300x250
//start of line, at least 1 number, an "x" , then at least 1 number, and the then end of the line
var sizeRegex = /^(\d)+x(\d)+$/i;
if (sizes) {
for (var curSizePos in sizes) {
if (hasOwn(sizes, curSizePos) && sizes[curSizePos].match(sizeRegex)) {
parsedSizes.push(sizes[curSizePos]);
}
}
}
} else if ((typeof sizeObj === 'undefined' ? 'undefined' : _typeof(sizeObj)) === objectType_object) {
var sizeArrayLength = sizeObj.length;
//don't process empty array
if (sizeArrayLength > 0) {
//if we are a 2 item array of 2 numbers, we must be a SingleSize array
if (sizeArrayLength === 2 && _typeof(sizeObj[0]) === objectType_number && _typeof(sizeObj[1]) === objectType_number) {
parsedSizes.push(this.parseGPTSingleSizeArray(sizeObj));
} else {
//otherwise, we must be a MultiSize array
for (var i = 0; i < sizeArrayLength; i++) {
parsedSizes.push(this.parseGPTSingleSizeArray(sizeObj[i]));
}
}
}
}
return parsedSizes;
};
//parse a GPT style sigle size array, (i.e [300,250])
//into an AppNexus style string, (i.e. 300x250)
exports.parseGPTSingleSizeArray = function (singleSize) {
//if we aren't exactly 2 items in this array, it is invalid
if (this.isArray(singleSize) && singleSize.length === 2 && !isNaN(singleSize[0]) && !isNaN(singleSize[1])) {
return singleSize[0] + 'x' + singleSize[1];
}
};
exports.getTopWindowUrl = function () {
try {
return window.top.location.href;
} catch (e) {
return window.location.href;
}
};
exports.logWarn = function (msg) {
if (debugTurnedOn() && console.warn) {
console.warn('WARNING: ' + msg);
}
};
exports.logInfo = function (msg, args) {
if (debugTurnedOn() && hasConsoleLogger()) {
if (infoLogger) {
if (!args || args.length === 0) {
args = '';
}
infoLogger('INFO: ' + msg + (args === '' ? '' : ' : params : '), args);
}
}