prebid-universal-creative 1.14.1 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,44 +60,33 @@
60
60
  /******/ __webpack_require__.p = "";
61
61
  /******/
62
62
  /******/ // Load entry module and return exports
63
- /******/ return __webpack_require__(__webpack_require__.s = 2);
63
+ /******/ return __webpack_require__(__webpack_require__.s = 3);
64
64
  /******/ })
65
65
  /************************************************************************/
66
66
  /******/ ([
67
67
  /* 0 */
68
- /***/ (function(module, exports, __webpack_require__) {
68
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
69
69
 
70
70
  "use strict";
71
-
72
-
73
- Object.defineProperty(exports, "__esModule", {
74
- value: true
75
- });
76
- exports.triggerPixel = triggerPixel;
77
- exports.createTrackPixelHtml = createTrackPixelHtml;
78
- exports.writeAdUrl = writeAdUrl;
79
- exports.writeAdHtml = writeAdHtml;
80
- exports.sendRequest = sendRequest;
81
- exports.getUUID = getUUID;
82
- exports.loadScript = loadScript;
83
- exports.getCreativeComment = getCreativeComment;
84
- exports.getCreativeCommentMarkup = getCreativeCommentMarkup;
85
- exports.transformAuctionTargetingData = transformAuctionTargetingData;
86
- exports.parseUrl = parseUrl;
87
-
88
- var domHelper = _interopRequireWildcard(__webpack_require__(1));
89
-
90
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
91
-
92
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
93
-
94
- var postscribe = __webpack_require__(4);
71
+ /* harmony export (immutable) */ __webpack_exports__["i"] = triggerPixel;
72
+ /* harmony export (immutable) */ __webpack_exports__["a"] = createTrackPixelHtml;
73
+ /* harmony export (immutable) */ __webpack_exports__["j"] = writeAdUrl;
74
+ /* unused harmony export writeAdHtml */
75
+ /* harmony export (immutable) */ __webpack_exports__["g"] = sendRequest;
76
+ /* harmony export (immutable) */ __webpack_exports__["d"] = getUUID;
77
+ /* harmony export (immutable) */ __webpack_exports__["e"] = loadScript;
78
+ /* harmony export (immutable) */ __webpack_exports__["b"] = getCreativeComment;
79
+ /* harmony export (immutable) */ __webpack_exports__["c"] = getCreativeCommentMarkup;
80
+ /* harmony export (immutable) */ __webpack_exports__["h"] = transformAuctionTargetingData;
81
+ /* harmony export (immutable) */ __webpack_exports__["f"] = parseUrl;
82
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__domHelper__ = __webpack_require__(1);
95
83
 
96
84
  /**
97
85
  * Inserts an image pixel with the specified `url` for cookie sync
98
86
  * @param {string} url URL string of the image pixel to load
99
87
  * @param {function} [done] an optional exit callback, used when this usersync pixel is added during an async process
100
88
  */
89
+
101
90
  function triggerPixel(url, done) {
102
91
  var img = new Image();
103
92
 
@@ -108,7 +97,6 @@ function triggerPixel(url, done) {
108
97
 
109
98
  img.src = url;
110
99
  }
111
-
112
100
  function createTrackPixelHtml(url) {
113
101
  if (!url) {
114
102
  return '';
@@ -118,13 +106,11 @@ function createTrackPixelHtml(url) {
118
106
  var img = "<div style=\"position:absolute;left:0px;top:0px;visibility:hidden;\"><img src=\"".concat(escapedUrl, "\"></div>");
119
107
  return img;
120
108
  }
121
-
122
109
  function writeAdUrl(adUrl, width, height) {
123
- var iframe = domHelper.getEmptyIframe(height, width);
110
+ var iframe = __WEBPACK_IMPORTED_MODULE_0__domHelper__["a" /* getEmptyIframe */](height, width);
124
111
  iframe.src = adUrl;
125
112
  document.body.appendChild(iframe);
126
113
  }
127
-
128
114
  function writeAdHtml(markup) {
129
115
  // remove <?xml> and <!doctype> tags
130
116
  // https://github.com/prebid/prebid-universal-creative/issues/134
@@ -133,7 +119,6 @@ function writeAdHtml(markup) {
133
119
  error: console.error
134
120
  });
135
121
  }
136
-
137
122
  function sendRequest(url, callback) {
138
123
  function reqListener() {
139
124
  callback(oReq.responseText);
@@ -144,7 +129,6 @@ function sendRequest(url, callback) {
144
129
  oReq.open('GET', url);
145
130
  oReq.send();
146
131
  }
147
-
148
132
  function getUUID() {
149
133
  var d = new Date().getTime();
150
134
  var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
@@ -154,9 +138,7 @@ function getUUID() {
154
138
  });
155
139
  return uuid;
156
140
  }
157
-
158
141
  ;
159
-
160
142
  function loadScript(currentWindow, tagSrc, successCallback, errorCallback) {
161
143
  var doc = currentWindow.document;
162
144
  var scriptTag = doc.createElement('script');
@@ -196,7 +178,6 @@ function loadScript(currentWindow, tagSrc, successCallback, errorCallback) {
196
178
 
197
179
  return scriptTag;
198
180
  }
199
-
200
181
  ;
201
182
  /**
202
183
  * Return comment element
@@ -211,14 +192,12 @@ function getCreativeComment(bid) {
211
192
  * @param {*} bid
212
193
  */
213
194
 
214
-
215
195
  function getCreativeCommentMarkup(bid) {
216
- var creativeComment = exports.getCreativeComment(bid);
196
+ var creativeComment = getCreativeComment(bid);
217
197
  var wrapper = document.createElement('div');
218
198
  wrapper.appendChild(creativeComment);
219
199
  return wrapper.innerHTML;
220
200
  }
221
-
222
201
  function transformAuctionTargetingData(tagData) {
223
202
  // this map object translates the Prebid.js auction keys to their equivalent Prebid Universal Creative keys
224
203
  // when the publisher uses their adserver's generic macro that provides all targeting keys (ie tagData.targetingMap), we need to convert the keys
@@ -315,7 +294,6 @@ function transformAuctionTargetingData(tagData) {
315
294
  });
316
295
  return auctionData;
317
296
  }
318
-
319
297
  function parseUrl(url) {
320
298
  var parsed = document.createElement('a');
321
299
  parsed.href = decodeURIComponent(url);
@@ -348,17 +326,11 @@ function isStr(object) {
348
326
 
349
327
  /***/ }),
350
328
  /* 1 */
351
- /***/ (function(module, exports, __webpack_require__) {
329
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
352
330
 
353
331
  "use strict";
354
-
355
-
356
- Object.defineProperty(exports, "__esModule", {
357
- value: true
358
- });
359
- exports.getEmptyIframe = getEmptyIframe;
360
- exports.insertElement = insertElement;
361
-
332
+ /* harmony export (immutable) */ __webpack_exports__["a"] = getEmptyIframe;
333
+ /* harmony export (immutable) */ __webpack_exports__["b"] = insertElement;
362
334
  /**
363
335
  * domHelper: a collection of helpful dom things
364
336
  */
@@ -389,7 +361,6 @@ function getEmptyIframe(height, width) {
389
361
  * @param {string} target
390
362
  */
391
363
 
392
-
393
364
  function insertElement(elm, doc, target) {
394
365
  doc = doc || document;
395
366
  var elToAppend;
@@ -412,476 +383,629 @@ function insertElement(elm, doc, target) {
412
383
 
413
384
  /***/ }),
414
385
  /* 2 */
415
- /***/ (function(module, exports, __webpack_require__) {
386
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
416
387
 
417
388
  "use strict";
389
+ /* harmony export (immutable) */ __webpack_exports__["b"] = isAmp;
390
+ /* harmony export (immutable) */ __webpack_exports__["d"] = isSafeFrame;
391
+ /* unused harmony export isCrossDomain */
392
+ /* unused harmony export canInspectWindow */
393
+ /* harmony export (immutable) */ __webpack_exports__["a"] = canLocatePrebid;
394
+ /* harmony export (immutable) */ __webpack_exports__["c"] = isMobileApp;
395
+ /***************************************
396
+ * Detect Environment Helper Functions
397
+ ***************************************/
418
398
 
399
+ /**
400
+ * Functions to detect below environments:
401
+ * Amp: google Accelerate Mobile Pages ampproject.org
402
+ * SafeFrame: SafeFrame
403
+ * CrossDomain: An iframe that can't get to the top window
404
+ * Mobile App: function to detect mobile app environment
405
+ */
419
406
 
420
- var _renderingManager = __webpack_require__(3);
407
+ /**
408
+ * @param {String} uuid key value from auction, contains the cache id of the winning bid stored in prebid cache
409
+ * @returns true if there is an AMP context object
410
+ */
411
+ function isAmp(uuid, win) {
412
+ // TODO Use amp context once it is available in cross domain
413
+ // https://github.com/ampproject/amphtml/issues/6829
414
+ return typeof uuid === 'string' && uuid !== "" && isCrossDomain(win);
415
+ }
416
+ /**
417
+ * @returns true if the environment is a SafeFrame.
418
+ */
421
419
 
422
- var _environment = __webpack_require__(6);
420
+ function isSafeFrame(win) {
421
+ return !!(win.$sf && win.$sf.ext);
422
+ }
423
+ /**
424
+ * Return true if we are in an iframe and can't access the top window.
425
+ * @returns true if the environment is a Cross Domain
426
+ */
423
427
 
428
+ function isCrossDomain(win) {
429
+ return win.top !== win && !canInspectWindow(win);
430
+ }
424
431
  /**
425
- * creative.js
426
- *
427
- * This file is inserted into the prebid creative as a placeholder for the winning prebid creative. It should support the following formats:
428
- * - Banner
429
- * - Outstream Video
430
- * - Mobile
431
- * - AMP creatives
432
- * - All safeFrame creatives
432
+ * Returns true if win's properties can be accessed and win is defined.
433
+ * This functioned is used to determine if a window is cross-domained
434
+ * from the perspective of the current window.
435
+ * @param {!Window} win
436
+ * @return {boolean}
433
437
  */
434
- window.ucTag = window.ucTag || {};
435
- var environment = (0, _environment.newEnvironment)(window);
436
- var renderCreative = (0, _renderingManager.newRenderingManager)(window, environment);
437
- window.ucTag.renderAd = renderCreative.renderAd;
438
+
439
+ function canInspectWindow(win) {
440
+ try {
441
+ // force an exception in x-domain environments. #1509
442
+ win.top.location.toString();
443
+ return true;
444
+ } catch (e) {
445
+ return false;
446
+ }
447
+ }
448
+ /**
449
+ * Returns true if we can find the prebid global object (eg pbjs) as we
450
+ * climb the accessible windows. Return false if it's not found.
451
+ * @returns {boolean}
452
+ */
453
+
454
+ function canLocatePrebid(win) {
455
+ var result = false;
456
+ var currentWindow = win;
457
+
458
+ while (!result) {
459
+ try {
460
+ if (currentWindow.pbjs) {
461
+ result = true;
462
+ break;
463
+ }
464
+ } catch (e) {}
465
+
466
+ if (currentWindow === window.top) break;
467
+ currentWindow = currentWindow.parent;
468
+ }
469
+
470
+ return result;
471
+ }
472
+ /**
473
+ * @param {String} env key value from auction, indicates the environment where tag is served
474
+ * @returns true if env exists and is equal to the string 'mobile-app'
475
+ */
476
+
477
+ function isMobileApp(env) {
478
+ return env && env === 'mobile-app';
479
+ }
438
480
 
439
481
  /***/ }),
440
482
  /* 3 */
441
- /***/ (function(module, exports, __webpack_require__) {
483
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
442
484
 
443
485
  "use strict";
486
+ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
487
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(0);
488
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__renderingManager__ = __webpack_require__(4);
489
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__mobileAndAmpRender__ = __webpack_require__(6);
490
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__environment__ = __webpack_require__(2);
491
+ /**
492
+ * legacy.js
493
+ * This is deprecated code, publishers should not use one .js creative to handle all different types of creative.
494
+ * To reduce bytes transfered for each ad, publishers should use specific .js based on hb_format targeting key-value.
495
+ *
496
+ * This file is inserted into the prebid creative as a placeholder for the winning prebid creative. It should support the following formats:
497
+ * - Banner
498
+ * - AMP
499
+ * - Mobile
500
+ * - Outstream Video
501
+ * - All safeFrame creatives
502
+ */
444
503
 
445
504
 
446
- Object.defineProperty(exports, "__esModule", {
447
- value: true
448
- });
449
- exports.newRenderingManager = newRenderingManager;
450
505
 
451
- var utils = _interopRequireWildcard(__webpack_require__(0));
452
506
 
453
- var domHelper = _interopRequireWildcard(__webpack_require__(1));
507
+ window.ucTag = window.ucTag || {};
454
508
 
455
- var _messaging = __webpack_require__(5);
509
+ window.ucTag.renderAd = function (doc, dataObject) {
510
+ var targetingData = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["h" /* transformAuctionTargetingData */])(dataObject);
456
511
 
457
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
512
+ if (Object(__WEBPACK_IMPORTED_MODULE_3__environment__["c" /* isMobileApp */])(targetingData.env) || Object(__WEBPACK_IMPORTED_MODULE_3__environment__["b" /* isAmp */])(targetingData.uuid, window)) {
513
+ Object(__WEBPACK_IMPORTED_MODULE_2__mobileAndAmpRender__["a" /* renderAmpOrMobileAd */])(dataObject);
514
+ } else {
515
+ Object(__WEBPACK_IMPORTED_MODULE_1__renderingManager__["a" /* renderBannerOrDisplayAd */])(doc, dataObject);
516
+ }
517
+ };
458
518
 
459
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
519
+ /***/ }),
520
+ /* 4 */
521
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
460
522
 
461
- var DEFAULT_CACHE_HOST = 'prebid.adnxs.com';
462
- var DEFAULT_CACHE_PATH = '/pbc/v1/cache';
463
- /**
464
- *
465
- * @param {Object} win Window object
466
- * @param {Object} environment Environment object
467
- * @returns {Object}
468
- */
523
+ "use strict";
524
+ /* harmony export (immutable) */ __webpack_exports__["a"] = renderBannerOrDisplayAd;
525
+ /* unused harmony export renderLegacy */
526
+ /* unused harmony export renderCrossDomain */
527
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(0);
528
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__environment__ = __webpack_require__(2);
529
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__domHelper__ = __webpack_require__(1);
530
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__messaging_js__ = __webpack_require__(5);
469
531
 
470
- function newRenderingManager(win, environment) {
471
- /**
472
- * DataObject passed to render the ad
473
- * @typedef {Object} dataObject
474
- * @property {string} host - Prebid cache host
475
- * @property {string} uuid - ID to fetch the value from prebid cache
476
- * @property {string} mediaType - Creative media type, It can be banner, native or video
477
- * @property {string} pubUrl - Publisher url
478
- * @property {string} winurl
479
- * @property {string} winbidid
480
- */
481
532
 
482
- /**
483
- * Public render ad function to be used in dfp creative setup
484
- * @param {object} doc
485
- * @param {dataObject} dataObject
486
- */
487
- var renderAd = function renderAd(doc, dataObject) {
488
- var targetingData = utils.transformAuctionTargetingData(dataObject);
489
-
490
- if (environment.isMobileApp(targetingData.env)) {
491
- renderAmpOrMobileAd(targetingData.cacheHost, targetingData.cachePath, targetingData.uuid, targetingData.size, targetingData.hbPb, true);
492
- } else if (environment.isAmp(targetingData.uuid)) {
493
- renderAmpOrMobileAd(targetingData.cacheHost, targetingData.cachePath, targetingData.uuid, targetingData.size, targetingData.hbPb);
494
- } else if (!environment.canLocatePrebid()) {
495
- renderCrossDomain(targetingData.adId, targetingData.adServerDomain, targetingData.pubUrl);
496
- } else {
497
- renderLegacy(doc, targetingData.adId);
498
- }
499
- };
500
- /**
501
- * Calls prebid.js renderAd function to render ad
502
- * @param {Object} doc Document
503
- * @param {string} adId Id of creative to render
504
- */
505
533
 
506
534
 
507
- function renderLegacy(doc, adId) {
508
- var w = win;
535
+ function renderBannerOrDisplayAd(doc, dataObject) {
536
+ var targetingData = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["h" /* transformAuctionTargetingData */])(dataObject);
509
537
 
510
- for (var i = 0; i < 10; i++) {
511
- w = w.parent;
538
+ if (!Object(__WEBPACK_IMPORTED_MODULE_1__environment__["a" /* canLocatePrebid */])(window)) {
539
+ renderCrossDomain(window, targetingData.adId, targetingData.adServerDomain, targetingData.pubUrl);
540
+ } else {
541
+ renderLegacy(doc, targetingData.adId);
542
+ }
543
+ }
544
+ /**
545
+ * Calls prebid.js renderAd function to render ad
546
+ * @param {Object} doc Document
547
+ * @param {string} adId Id of creative to render
548
+ */
512
549
 
513
- if (w.pbjs) {
514
- try {
515
- w.pbjs.renderAd(doc, adId);
516
- break;
517
- } catch (e) {
518
- continue;
519
- }
550
+ function renderLegacy(doc, adId) {
551
+ var w = window;
552
+
553
+ for (var i = 0; i < 10; i++) {
554
+ w = w.parent;
555
+
556
+ if (w.pbjs) {
557
+ try {
558
+ w.pbjs.renderAd(doc, adId);
559
+ break;
560
+ } catch (e) {
561
+ continue;
520
562
  }
521
563
  }
522
564
  }
523
- /**
524
- * Render ad in safeframe using postmessage
525
- * @param {string} adId Id of creative to render
526
- * @param {string} pubAdServerDomain publisher adserver domain name
527
- * @param {string} pubUrl Url of publisher page
528
- */
565
+ }
566
+ /**
567
+ * Render ad in safeframe using postmessage
568
+ * @param {string} adId Id of creative to render
569
+ * @param {string} pubAdServerDomain publisher adserver domain name
570
+ * @param {string} pubUrl Url of publisher page
571
+ */
529
572
 
573
+ function renderCrossDomain(win, adId) {
574
+ var pubAdServerDomain = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
575
+ var pubUrl = arguments.length > 3 ? arguments[3] : undefined;
576
+ var windowLocation = win.location;
577
+ var adServerDomain = pubAdServerDomain || win.location.hostname;
578
+ var fullAdServerDomain = windowLocation.protocol + '//' + adServerDomain;
579
+ var sendMessage = Object(__WEBPACK_IMPORTED_MODULE_3__messaging_js__["a" /* prebidMessenger */])(pubUrl, win);
530
580
 
531
- function renderCrossDomain(adId) {
532
- var pubAdServerDomain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
533
- var pubUrl = arguments.length > 2 ? arguments[2] : undefined;
534
- var windowLocation = win.location;
535
- var adServerDomain = pubAdServerDomain || win.location.hostname;
536
- var fullAdServerDomain = windowLocation.protocol + '//' + adServerDomain;
537
- var sendMessage = (0, _messaging.prebidMessenger)(pubUrl, win);
581
+ function renderAd(ev) {
582
+ var key = ev.message ? "message" : "data";
583
+ var adObject = {};
538
584
 
539
- function renderAd(ev) {
540
- var key = ev.message ? 'message' : 'data';
541
- var adObject = {};
585
+ try {
586
+ adObject = JSON.parse(ev[key]);
587
+ } catch (e) {
588
+ return;
589
+ }
542
590
 
591
+ if (adObject.message && adObject.message === "Prebid Response" && adObject.adId === adId) {
543
592
  try {
544
- adObject = JSON.parse(ev[key]);
545
- } catch (e) {
546
- return;
547
- }
593
+ var body = win.document.body;
594
+ var ad = adObject.ad;
595
+ var url = adObject.adUrl;
596
+ var width = adObject.width;
597
+ var height = adObject.height;
548
598
 
549
- if (adObject.message && adObject.message === 'Prebid Response' && adObject.adId === adId) {
550
- try {
551
- var body = win.document.body;
552
- var ad = adObject.ad;
553
- var url = adObject.adUrl;
554
- var width = adObject.width;
555
- var height = adObject.height;
556
-
557
- if (adObject.mediaType === 'video') {
558
- signalRenderResult(false, {
559
- reason: 'preventWritingOnMainDocument',
560
- message: "Cannot render video ad ".concat(adId)
561
- });
562
- console.log('Error trying to write ad.');
563
- } else if (ad) {
564
- var iframe = domHelper.getEmptyIframe(adObject.height, adObject.width);
565
- body.appendChild(iframe);
566
- iframe.contentDocument.open();
567
- iframe.contentDocument.write(ad);
568
- iframe.contentDocument.close();
569
- signalRenderResult(true);
570
- } else if (url) {
571
- var _iframe = domHelper.getEmptyIframe(height, width);
572
-
573
- _iframe.style.display = 'inline';
574
- _iframe.style.overflow = 'hidden';
575
- _iframe.src = url;
576
- domHelper.insertElement(_iframe, document, 'body');
577
- signalRenderResult(true);
578
- } else {
579
- signalRenderResult(false, {
580
- reason: 'noAd',
581
- message: "No ad for ".concat(adId)
582
- });
583
- console.log("Error trying to write ad. No ad markup or adUrl for ".concat(adId));
584
- }
585
- } catch (e) {
599
+ if (adObject.mediaType === "video") {
586
600
  signalRenderResult(false, {
587
- reason: "exception",
588
- message: e.message
601
+ reason: "preventWritingOnMainDocument",
602
+ message: "Cannot render video ad ".concat(adId)
589
603
  });
590
- console.log("Error in rendering ad", e);
604
+ console.log("Error trying to write ad.");
605
+ } else if (ad) {
606
+ var iframe = Object(__WEBPACK_IMPORTED_MODULE_2__domHelper__["a" /* getEmptyIframe */])(adObject.height, adObject.width);
607
+ body.appendChild(iframe);
608
+ iframe.contentDocument.open();
609
+ iframe.contentDocument.write(ad);
610
+ iframe.contentDocument.close();
611
+ signalRenderResult(true);
612
+ } else if (url) {
613
+ var _iframe = Object(__WEBPACK_IMPORTED_MODULE_2__domHelper__["a" /* getEmptyIframe */])(height, width);
614
+
615
+ _iframe.style.display = "inline";
616
+ _iframe.style.overflow = "hidden";
617
+ _iframe.src = url;
618
+ Object(__WEBPACK_IMPORTED_MODULE_2__domHelper__["b" /* insertElement */])(_iframe, document, "body");
619
+ signalRenderResult(true);
620
+ } else {
621
+ signalRenderResult(false, {
622
+ reason: "noAd",
623
+ message: "No ad for ".concat(adId)
624
+ });
625
+ console.log("Error trying to write ad. No ad markup or adUrl for ".concat(adId));
591
626
  }
627
+ } catch (e) {
628
+ signalRenderResult(false, {
629
+ reason: "exception",
630
+ message: e.message
631
+ });
632
+ console.log("Error in rendering ad", e);
592
633
  }
634
+ }
593
635
 
594
- function signalRenderResult(success) {
595
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
596
- reason = _ref.reason,
597
- message = _ref.message;
636
+ function signalRenderResult(success) {
637
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
638
+ reason = _ref.reason,
639
+ message = _ref.message;
598
640
 
599
- var payload = {
600
- message: 'Prebid Event',
601
- adId: adId,
602
- event: success ? 'adRenderSucceeded' : 'adRenderFailed'
603
- };
604
-
605
- if (!success) {
606
- payload.info = {
607
- reason: reason,
608
- message: message
609
- };
610
- }
641
+ var payload = {
642
+ message: "Prebid Event",
643
+ adId: adId,
644
+ event: success ? "adRenderSucceeded" : "adRenderFailed"
645
+ };
611
646
 
612
- sendMessage(payload);
647
+ if (!success) {
648
+ payload.info = {
649
+ reason: reason,
650
+ message: message
651
+ };
613
652
  }
614
- }
615
653
 
616
- function requestAdFromPrebid() {
617
- var message = {
618
- message: 'Prebid Request',
619
- adId: adId,
620
- adServerDomain: fullAdServerDomain
621
- };
622
- sendMessage(message, renderAd);
654
+ sendMessage(payload);
623
655
  }
656
+ }
624
657
 
625
- requestAdFromPrebid();
658
+ function requestAdFromPrebid() {
659
+ var message = {
660
+ message: 'Prebid Request',
661
+ adId: adId,
662
+ adServerDomain: fullAdServerDomain
663
+ };
664
+ sendMessage(message, renderAd);
626
665
  }
627
- /**
628
- * Returns cache endpoint concatenated with cache path
629
- * @param {string} cacheHost Cache Endpoint host
630
- * @param {string} cachePath Cache Endpoint path
631
- */
632
666
 
667
+ requestAdFromPrebid();
668
+ }
633
669
 
634
- function getCacheEndpoint(cacheHost, cachePath) {
635
- var host = typeof cacheHost === 'undefined' || cacheHost === "" ? DEFAULT_CACHE_HOST : cacheHost;
636
- var path = typeof cachePath === 'undefined' || cachePath === "" ? DEFAULT_CACHE_PATH : cachePath;
637
- return "https://".concat(host).concat(path);
638
- }
639
- /**
640
- * update iframe by using size string to resize
641
- * @param {string} size
642
- */
670
+ /***/ }),
671
+ /* 5 */
672
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
643
673
 
674
+ "use strict";
675
+ /* harmony export (immutable) */ __webpack_exports__["a"] = prebidMessenger;
676
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils_js__ = __webpack_require__(0);
644
677
 
645
- function updateIframe(size) {
646
- if (size) {
647
- var sizeArr = size.split('x').map(Number);
648
- resizeIframe(sizeArr[0], sizeArr[1]);
649
- } else {
650
- console.log('Targeting key hb_size not found to resize creative');
678
+ function prebidMessenger(publisherURL) {
679
+ var win = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
680
+
681
+ var prebidDomain = function () {
682
+ if (publisherURL == null) {
683
+ return null;
651
684
  }
652
- }
653
- /**
654
- * Render mobile or amp ad
655
- * @param {string} cacheHost Cache host
656
- * @param {string} cachePath Cache path
657
- * @param {string} uuid id to render response from cache endpoint
658
- * @param {string} size size of the creative
659
- * @param {string} hbPb final price of the winning bid
660
- * @param {Bool} isMobileApp flag to detect mobile app
661
- */
662
685
 
686
+ var parsedUrl = Object(__WEBPACK_IMPORTED_MODULE_0__utils_js__["f" /* parseUrl */])(publisherURL);
687
+ return parsedUrl.protocol + '://' + parsedUrl.host;
688
+ }();
663
689
 
664
- function renderAmpOrMobileAd(cacheHost, cachePath) {
665
- var uuid = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
666
- var size = arguments.length > 3 ? arguments[3] : undefined;
667
- var hbPb = arguments.length > 4 ? arguments[4] : undefined;
668
- var isMobileApp = arguments.length > 5 ? arguments[5] : undefined;
669
- // For MoPub, creative is stored in localStorage via SDK.
670
- var search = 'Prebid_';
690
+ return function sendMessage(message, onResponse) {
691
+ if (prebidDomain == null) {
692
+ throw new Error('Missing pubUrl');
693
+ }
671
694
 
672
- if (uuid.substr(0, search.length) === search) {
673
- loadFromLocalCache(uuid); //register creative right away to not miss initial geom-update
695
+ message = JSON.stringify(message);
696
+ var messagePort;
674
697
 
675
- updateIframe(size);
698
+ if (onResponse == null) {
699
+ win.parent.postMessage(message, prebidDomain);
676
700
  } else {
677
- var adUrl = "".concat(getCacheEndpoint(cacheHost, cachePath), "?uuid=").concat(uuid); //register creative right away to not miss initial geom-update
678
-
679
- updateIframe(size);
680
- utils.sendRequest(adUrl, responseCallback(isMobileApp, hbPb));
701
+ var channel = new MessageChannel();
702
+ messagePort = channel.port1;
703
+ messagePort.onmessage = onResponse;
704
+ win.addEventListener('message', windowListener);
705
+ win.parent.postMessage(message, prebidDomain, [channel.port2]);
681
706
  }
682
- }
683
- /**
684
- * Cache request Callback to display creative
685
- * @param {Bool} isMobileApp
686
- * @param {string} hbPb final price of the winning bid
687
- * @returns {function} a callback function that parses response
688
- */
689
-
690
707
 
691
- function responseCallback(isMobileApp, hbPb) {
692
- return function (response) {
693
- var bidObject = parseResponse(response);
694
- var auctionPrice = bidObject.price || hbPb;
695
- var ad = utils.getCreativeCommentMarkup(bidObject);
696
- var width = bidObject.width ? bidObject.width : bidObject.w;
697
- var height = bidObject.height ? bidObject.height : bidObject.h; // When Prebid Universal Creative reads from Prebid Cache, we need to have it check for the existence of the wurl parameter. If it exists, hit it.
708
+ return function stopListening() {
709
+ if (messagePort != null) {
710
+ win.removeEventListener('message', windowListener);
711
+ messagePort.onmessage = null;
712
+ messagePort = null;
713
+ }
714
+ };
698
715
 
699
- if (bidObject.wurl) {
700
- (0, utils.triggerPixel)(decodeURIComponent(bidObject.wurl));
716
+ function windowListener(ev) {
717
+ if ((ev.origin || ev.originalEvent && ev.originalEvent.origin) === prebidDomain) {
718
+ onResponse(ev);
701
719
  }
720
+ }
721
+ };
722
+ }
702
723
 
703
- if (bidObject.adm) {
704
- if (auctionPrice) {
705
- // replace ${AUCTION_PRICE} macro with the bidObject.price or hb_pb.
706
- bidObject.adm = bidObject.adm.replace('${AUCTION_PRICE}', auctionPrice);
707
- } else {
708
- /*
709
- From OpenRTB spec 2.5: If the source value is an optional parameter that was not specified, the macro will simply be removed (i.e., replaced with a zero-length string).
710
- */
711
- bidObject.adm = bidObject.adm.replace('${AUCTION_PRICE}', '');
712
- }
724
+ /***/ }),
725
+ /* 6 */
726
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
713
727
 
714
- ad += isMobileApp ? constructMarkup(bidObject.adm, width, height) : bidObject.adm;
728
+ "use strict";
729
+ /* harmony export (immutable) */ __webpack_exports__["a"] = renderAmpOrMobileAd;
730
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__utils__ = __webpack_require__(0);
731
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__environment__ = __webpack_require__(2);
732
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__domHelper__ = __webpack_require__(1);
733
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__postscribeRender__ = __webpack_require__(7);
715
734
 
716
- if (bidObject.nurl) {
717
- ad += utils.createTrackPixelHtml(decodeURIComponent(bidObject.nurl));
718
- }
719
735
 
720
- if (bidObject.burl) {
721
- var triggerBurl = function triggerBurl() {
722
- utils.triggerPixel(bidObject.burl);
723
- };
724
-
725
- if (isMobileApp) {
726
- var mraidScript = utils.loadScript(win, 'mraid.js', function () {
727
- // Success loading MRAID
728
- var result = registerMRAIDViewableEvent(triggerBurl);
729
-
730
- if (!result) {
731
- triggerBurl(); // Error registering event
732
- }
733
- }, triggerBurl // Error loading MRAID
734
- );
735
- } else {
736
- triggerBurl(); // Not a mobile app
737
- }
738
- }
739
736
 
740
- utils.writeAdHtml(ad);
741
- } else if (bidObject.nurl) {
742
- if (isMobileApp) {
743
- var adhtml = utils.loadScript(win, bidObject.nurl);
744
- ad += constructMarkup(adhtml.outerHTML, width, height);
745
- utils.writeAdHtml(ad);
746
- } else {
747
- var nurl = bidObject.nurl;
748
- var commentElm = utils.getCreativeComment(bidObject);
749
- domHelper.insertElement(commentElm, document, 'body');
750
- utils.writeAdUrl(nurl, width, height);
751
- }
752
- }
753
- };
754
- }
755
737
 
756
- ;
757
- /**
758
- * Load response from localStorage. In case of MoPub, sdk caches response
759
- * @param {string} cacheId
760
- */
738
+ var DEFAULT_CACHE_HOST = 'prebid.adnxs.com';
739
+ var DEFAULT_CACHE_PATH = '/pbc/v1/cache';
740
+ /**
741
+ * Render mobile or amp ad
742
+ * @param {string} cacheHost Cache host
743
+ * @param {string} cachePath Cache path
744
+ * @param {string} uuid id to render response from cache endpoint
745
+ * @param {string} size size of the creative
746
+ * @param {string} hbPb final price of the winning bid
747
+ * @param {Bool} isMobileApp flag to detect mobile app
748
+ */
761
749
 
762
- function loadFromLocalCache(cacheId) {
763
- var bid = win.localStorage.getItem(cacheId);
764
- var displayFn = responseCallback(true);
765
- displayFn(bid);
766
- }
767
- /**
768
- * Parse response
769
- * @param {string} response
770
- * @returns {Object} bidObject parsed response
771
- */
750
+ function renderAmpOrMobileAd(dataObject) {
751
+ var targetingData = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["h" /* transformAuctionTargetingData */])(dataObject);
752
+ var cacheHost = targetingData.cacheHost,
753
+ cachePath = targetingData.cachePath,
754
+ uuid = targetingData.uuid,
755
+ size = targetingData.size,
756
+ hbPb = targetingData.hbPb;
757
+ uuid = uuid || ''; // For MoPub, creative is stored in localStorage via SDK.
772
758
 
759
+ var search = 'Prebid_';
773
760
 
774
- function parseResponse(response) {
775
- var bidObject;
761
+ if (uuid.substr(0, search.length) === search) {
762
+ loadFromLocalCache(uuid); //register creative right away to not miss initial geom-update
776
763
 
777
- try {
778
- bidObject = JSON.parse(response);
779
- } catch (error) {
780
- console.log("Error parsing response from cache host: ".concat(error));
781
- }
764
+ updateIframe(size);
765
+ } else {
766
+ var adUrl = "".concat(getCacheEndpoint(cacheHost, cachePath), "?uuid=").concat(uuid); //register creative right away to not miss initial geom-update
782
767
 
783
- return bidObject;
768
+ updateIframe(size);
769
+ Object(__WEBPACK_IMPORTED_MODULE_0__utils__["g" /* sendRequest */])(adUrl, responseCallback(Object(__WEBPACK_IMPORTED_MODULE_1__environment__["c" /* isMobileApp */])(targetingData.env), hbPb));
784
770
  }
785
- /**
786
- * Wrap mobile app creative in div
787
- * @param {string} ad html for creative
788
- * @param {Number} width width of creative
789
- * @param {Number} height height of creative
790
- * @returns {string} creative markup
791
- */
771
+ }
772
+ /**
773
+ * Load response from localStorage. In case of MoPub, sdk caches response
774
+ * @param {string} cacheId
775
+ */
776
+
777
+ function loadFromLocalCache(cacheId) {
778
+ var bid = window.localStorage.getItem(cacheId);
779
+ var displayFn = responseCallback(true);
780
+ displayFn(bid);
781
+ }
782
+ /**
783
+ * update iframe by using size string to resize
784
+ * @param {string} size
785
+ */
792
786
 
793
787
 
794
- function constructMarkup(ad, width, height) {
795
- var id = utils.getUUID();
796
- return "<div id=\"".concat(id, "\" style=\"border-style: none; position: absolute; width:100%; height:100%;\">\n <div id=\"").concat(id, "_inner\" style=\"margin: 0 auto; width:").concat(width, "px; height:").concat(height, "px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);\">").concat(ad, "</div>\n </div>");
788
+ function updateIframe(size) {
789
+ if (size) {
790
+ var sizeArr = size.split('x').map(Number);
791
+ resizeIframe(sizeArr[0], sizeArr[1]);
792
+ } else {
793
+ console.log('Targeting key hb_size not found to resize creative');
797
794
  }
798
- /**
799
- * Resize container iframe
800
- * @param {Number} width width of creative
801
- * @param {Number} height height of creative
802
- */
795
+ }
796
+ /**
797
+ * Resize container iframe
798
+ * @param {Number} width width of creative
799
+ * @param {Number} height height of creative
800
+ */
803
801
 
804
802
 
805
- function resizeIframe(width, height) {
806
- if (environment.isSafeFrame()) {
807
- var resize = function resize(status) {
808
- var newWidth = width - iframeWidth;
809
- var newHeight = height - iframeHeight;
810
- win.$sf.ext.expand({
811
- r: newWidth,
812
- b: newHeight,
813
- push: true
814
- });
815
- };
803
+ function resizeIframe(width, height) {
804
+ if (Object(__WEBPACK_IMPORTED_MODULE_1__environment__["d" /* isSafeFrame */])(window)) {
805
+ var resize = function resize(status) {
806
+ var newWidth = width - iframeWidth;
807
+ var newHeight = height - iframeHeight;
808
+ window.$sf.ext.expand({
809
+ r: newWidth,
810
+ b: newHeight,
811
+ push: true
812
+ });
813
+ };
816
814
 
817
- var iframeWidth = win.innerWidth;
818
- var iframeHeight = win.innerHeight;
815
+ var iframeWidth = window.innerWidth;
816
+ var iframeHeight = window.innerHeight;
819
817
 
820
- if (iframeWidth !== width || iframeHeight !== height) {
821
- win.$sf.ext.register(width, height, resize); // we need to resize the DFP container as well
818
+ if (iframeWidth !== width || iframeHeight !== height) {
819
+ window.$sf.ext.register(width, height, resize); // we need to resize the DFP container as well
822
820
 
823
- win.parent.postMessage({
824
- sentinel: 'amp',
825
- type: 'embed-size',
826
- width: width,
827
- height: height
828
- }, '*');
829
- }
821
+ window.parent.postMessage({
822
+ sentinel: 'amp',
823
+ type: 'embed-size',
824
+ width: width,
825
+ height: height
826
+ }, '*');
830
827
  }
831
828
  }
829
+ }
830
+ /**
831
+ * Returns cache endpoint concatenated with cache path
832
+ * @param {string} cacheHost Cache Endpoint host
833
+ * @param {string} cachePath Cache Endpoint path
834
+ */
832
835
 
833
- function registerMRAIDViewableEvent(callback) {
834
- function exposureChangeListener(exposure) {
835
- if (exposure > 0) {
836
- mraid.removeEventListener('exposureChange', exposureChangeListener);
837
- callback();
838
- }
836
+
837
+ function getCacheEndpoint(cacheHost, cachePath) {
838
+ var host = typeof cacheHost === 'undefined' || cacheHost === "" ? DEFAULT_CACHE_HOST : cacheHost;
839
+ var path = typeof cachePath === 'undefined' || cachePath === "" ? DEFAULT_CACHE_PATH : cachePath;
840
+ return "https://".concat(host).concat(path);
841
+ }
842
+ /**
843
+ * Cache request Callback to display creative
844
+ * @param {Bool} isMobileApp
845
+ * @param {string} hbPb final price of the winning bid
846
+ * @returns {function} a callback function that parses response
847
+ */
848
+
849
+
850
+ function responseCallback(isMobileApp, hbPb) {
851
+ return function (response) {
852
+ var bidObject = parseResponse(response);
853
+ var auctionPrice = bidObject.price || hbPb;
854
+ var ad = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["c" /* getCreativeCommentMarkup */])(bidObject);
855
+ var width = bidObject.width ? bidObject.width : bidObject.w;
856
+ var height = bidObject.height ? bidObject.height : bidObject.h; // When Prebid Universal Creative reads from Prebid Cache, we need to have it check for the existence of the wurl parameter. If it exists, hit it.
857
+
858
+ if (bidObject.wurl) {
859
+ Object(__WEBPACK_IMPORTED_MODULE_0__utils__["i" /* triggerPixel */])(decodeURIComponent(bidObject.wurl));
839
860
  }
840
861
 
841
- function viewableChangeListener(viewable) {
842
- if (viewable) {
843
- mraid.removeEventListener('viewableChange', viewableChangeListener);
844
- callback();
862
+ if (bidObject.adm) {
863
+ if (auctionPrice) {
864
+ // replace ${AUCTION_PRICE} macro with the bidObject.price or hb_pb.
865
+ bidObject.adm = bidObject.adm.replace('${AUCTION_PRICE}', auctionPrice);
866
+ } else {
867
+ /*
868
+ From OpenRTB spec 2.5: If the source value is an optional parameter that was not specified, the macro will simply be removed (i.e., replaced with a zero-length string).
869
+ */
870
+ bidObject.adm = bidObject.adm.replace('${AUCTION_PRICE}', '');
845
871
  }
846
- }
847
872
 
848
- function registerViewableChecks() {
849
- if (win.MRAID_ENV && parseFloat(win.MRAID_ENV.version) >= 3) {
850
- mraid.addEventListener('exposureChange', exposureChangeListener);
851
- } else if (win.MRAID_ENV && parseFloat(win.MRAID_ENV.version) < 3) {
852
- if (mraid.isViewable()) {
853
- callback();
873
+ ad += isMobileApp ? constructMarkup(bidObject.adm, width, height) : bidObject.adm;
874
+
875
+ if (bidObject.nurl) {
876
+ ad += Object(__WEBPACK_IMPORTED_MODULE_0__utils__["a" /* createTrackPixelHtml */])(decodeURIComponent(bidObject.nurl));
877
+ }
878
+
879
+ if (bidObject.burl) {
880
+ var triggerBurl = function triggerBurl() {
881
+ Object(__WEBPACK_IMPORTED_MODULE_0__utils__["i" /* triggerPixel */])(bidObject.burl);
882
+ };
883
+
884
+ if (isMobileApp) {
885
+ var mraidScript = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["e" /* loadScript */])(window, 'mraid.js', function () {
886
+ // Success loading MRAID
887
+ var result = registerMRAIDViewableEvent(triggerBurl);
888
+
889
+ if (!result) {
890
+ triggerBurl(); // Error registering event
891
+ }
892
+ }, triggerBurl // Error loading MRAID
893
+ );
854
894
  } else {
855
- mraid.addEventListener('viewableChange', viewableChangeListener);
895
+ triggerBurl(); // Not a mobile app
856
896
  }
857
897
  }
898
+
899
+ Object(__WEBPACK_IMPORTED_MODULE_3__postscribeRender__["a" /* writeAdHtml */])(ad);
900
+ } else if (bidObject.nurl) {
901
+ if (isMobileApp) {
902
+ var adhtml = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["e" /* loadScript */])(window, bidObject.nurl);
903
+ ad += constructMarkup(adhtml.outerHTML, width, height);
904
+ Object(__WEBPACK_IMPORTED_MODULE_3__postscribeRender__["a" /* writeAdHtml */])(ad);
905
+ } else {
906
+ var nurl = bidObject.nurl;
907
+ var commentElm = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["b" /* getCreativeComment */])(bidObject);
908
+ Object(__WEBPACK_IMPORTED_MODULE_2__domHelper__["b" /* insertElement */])(commentElm, document, 'body');
909
+ Object(__WEBPACK_IMPORTED_MODULE_0__utils__["j" /* writeAdUrl */])(nurl, width, height);
910
+ }
858
911
  }
912
+ };
913
+ }
859
914
 
860
- function readyListener() {
861
- mraid.removeEventListener('ready', readyListener);
862
- registerViewableChecks();
915
+ ;
916
+ /**
917
+ * Parse response
918
+ * @param {string} response
919
+ * @returns {Object} bidObject parsed response
920
+ */
921
+
922
+ function parseResponse(response) {
923
+ var bidObject;
924
+
925
+ try {
926
+ bidObject = JSON.parse(response);
927
+ } catch (error) {
928
+ console.log("Error parsing response from cache host: ".concat(error));
929
+ }
930
+
931
+ return bidObject;
932
+ }
933
+ /**
934
+ * Wrap mobile app creative in div
935
+ * @param {string} ad html for creative
936
+ * @param {Number} width width of creative
937
+ * @param {Number} height height of creative
938
+ * @returns {string} creative markup
939
+ */
940
+
941
+
942
+ function constructMarkup(ad, width, height) {
943
+ var id = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["d" /* getUUID */])();
944
+ return "<div id=\"".concat(id, "\" style=\"border-style: none; position: absolute; width:100%; height:100%;\">\n <div id=\"").concat(id, "_inner\" style=\"margin: 0 auto; width:").concat(width, "px; height:").concat(height, "px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);\">").concat(ad, "</div>\n </div>");
945
+ }
946
+
947
+ function registerMRAIDViewableEvent(callback) {
948
+ function exposureChangeListener(exposure) {
949
+ if (exposure > 0) {
950
+ mraid.removeEventListener('exposureChange', exposureChangeListener);
951
+ callback();
863
952
  }
953
+ }
864
954
 
865
- if (win.mraid && win.MRAID_ENV) {
866
- if (mraid.getState() == 'loading') {
867
- mraid.addEventListener('ready', readyListener);
955
+ function viewableChangeListener(viewable) {
956
+ if (viewable) {
957
+ mraid.removeEventListener('viewableChange', viewableChangeListener);
958
+ callback();
959
+ }
960
+ }
961
+
962
+ function registerViewableChecks() {
963
+ if (window.MRAID_ENV && parseFloat(window.MRAID_ENV.version) >= 3) {
964
+ mraid.addEventListener('exposureChange', exposureChangeListener);
965
+ } else if (window.MRAID_ENV && parseFloat(window.MRAID_ENV.version) < 3) {
966
+ if (mraid.isViewable()) {
967
+ callback();
868
968
  } else {
869
- registerViewableChecks();
969
+ mraid.addEventListener('viewableChange', viewableChangeListener);
870
970
  }
971
+ }
972
+ }
973
+
974
+ function readyListener() {
975
+ mraid.removeEventListener('ready', readyListener);
976
+ registerViewableChecks();
977
+ }
871
978
 
872
- return true;
979
+ if (window.mraid && window.MRAID_ENV) {
980
+ if (mraid.getState() == 'loading') {
981
+ mraid.addEventListener('ready', readyListener);
873
982
  } else {
874
- return false;
983
+ registerViewableChecks();
875
984
  }
985
+
986
+ return true;
987
+ } else {
988
+ return false;
876
989
  }
990
+ }
877
991
 
878
- return {
879
- renderAd: renderAd
880
- };
992
+ /***/ }),
993
+ /* 7 */
994
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
995
+
996
+ "use strict";
997
+ /* harmony export (immutable) */ __webpack_exports__["a"] = writeAdHtml;
998
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_postscribe__ = __webpack_require__(8);
999
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_postscribe___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_postscribe__);
1000
+
1001
+ function writeAdHtml(markup) {
1002
+ __WEBPACK_IMPORTED_MODULE_0_postscribe___default()(document.body, markup, {
1003
+ error: console.error
1004
+ });
881
1005
  }
882
1006
 
883
1007
  /***/ }),
884
- /* 4 */
1008
+ /* 8 */
885
1009
  /***/ (function(module, exports, __webpack_require__) {
886
1010
 
887
1011
  /**
@@ -2973,177 +3097,5 @@ return /******/ (function(modules) { // webpackBootstrap
2973
3097
  ;
2974
3098
  //# sourceMappingURL=postscribe.js.map
2975
3099
 
2976
- /***/ }),
2977
- /* 5 */
2978
- /***/ (function(module, exports, __webpack_require__) {
2979
-
2980
- "use strict";
2981
-
2982
-
2983
- Object.defineProperty(exports, "__esModule", {
2984
- value: true
2985
- });
2986
- exports.prebidMessenger = prebidMessenger;
2987
-
2988
- var _utils = __webpack_require__(0);
2989
-
2990
- function prebidMessenger(publisherURL) {
2991
- var win = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
2992
-
2993
- var prebidDomain = function () {
2994
- if (publisherURL == null) {
2995
- return null;
2996
- }
2997
-
2998
- var parsedUrl = (0, _utils.parseUrl)(publisherURL);
2999
- return parsedUrl.protocol + '://' + parsedUrl.host;
3000
- }();
3001
-
3002
- return function sendMessage(message, onResponse) {
3003
- if (prebidDomain == null) {
3004
- throw new Error('Missing pubUrl');
3005
- }
3006
-
3007
- message = JSON.stringify(message);
3008
- var messagePort;
3009
-
3010
- if (onResponse == null) {
3011
- win.parent.postMessage(message, prebidDomain);
3012
- } else {
3013
- var channel = new MessageChannel();
3014
- messagePort = channel.port1;
3015
- messagePort.onmessage = onResponse;
3016
- win.addEventListener('message', windowListener);
3017
- win.parent.postMessage(message, prebidDomain, [channel.port2]);
3018
- }
3019
-
3020
- return function stopListening() {
3021
- if (messagePort != null) {
3022
- win.removeEventListener('message', windowListener);
3023
- messagePort.onmessage = null;
3024
- messagePort = null;
3025
- }
3026
- };
3027
-
3028
- function windowListener(ev) {
3029
- if ((ev.origin || ev.originalEvent && ev.originalEvent.origin) === prebidDomain) {
3030
- onResponse(ev);
3031
- }
3032
- }
3033
- };
3034
- }
3035
-
3036
- /***/ }),
3037
- /* 6 */
3038
- /***/ (function(module, exports, __webpack_require__) {
3039
-
3040
- "use strict";
3041
-
3042
-
3043
- Object.defineProperty(exports, "__esModule", {
3044
- value: true
3045
- });
3046
- exports.newEnvironment = newEnvironment;
3047
-
3048
- /***************************************
3049
- * Detect Environment Helper Functions
3050
- ***************************************/
3051
-
3052
- /**
3053
- * Functions to detect below environments:
3054
- * Amp: google Accelerate Mobile Pages ampproject.org
3055
- * SafeFrame: SafeFrame
3056
- * CrossDomain: An iframe that can't get to the top window
3057
- * Mobile App: function to detect mobile app environment
3058
- */
3059
- function newEnvironment(win) {
3060
- /**
3061
- * @param {String} uuid key value from auction, contains the cache id of the winning bid stored in prebid cache
3062
- * @returns true if there is an AMP context object
3063
- */
3064
- function isAmp(uuid) {
3065
- // TODO Use amp context once it is available in cross domain
3066
- // https://github.com/ampproject/amphtml/issues/6829
3067
- return typeof uuid === 'string' && uuid !== "" && isCrossDomain();
3068
- }
3069
- /**
3070
- * @returns true if the environment is a SafeFrame.
3071
- */
3072
-
3073
-
3074
- function isSafeFrame() {
3075
- return !!(win.$sf && win.$sf.ext);
3076
- }
3077
- /**
3078
- * Return true if we are in an iframe and can't access the top window.
3079
- * @returns true if the environment is a Cross Domain
3080
- */
3081
-
3082
-
3083
- function isCrossDomain() {
3084
- return win.top !== win && !canInspectWindow(win);
3085
- }
3086
- /**
3087
- * Returns true if win's properties can be accessed and win is defined.
3088
- * This functioned is used to determine if a window is cross-domained
3089
- * from the perspective of the current window.
3090
- * @param {!Window} win
3091
- * @return {boolean}
3092
- */
3093
-
3094
-
3095
- function canInspectWindow(win) {
3096
- try {
3097
- // force an exception in x-domain environments. #1509
3098
- win.top.location.toString();
3099
- return true;
3100
- } catch (e) {
3101
- return false;
3102
- }
3103
- }
3104
- /**
3105
- * Returns true if we can find the prebid global object (eg pbjs) as we
3106
- * climb the accessible windows. Return false if it's not found.
3107
- * @returns {boolean}
3108
- */
3109
-
3110
-
3111
- function canLocatePrebid() {
3112
- var result = false;
3113
- var currentWindow = win;
3114
-
3115
- while (!result) {
3116
- try {
3117
- if (currentWindow.pbjs) {
3118
- result = true;
3119
- break;
3120
- }
3121
- } catch (e) {}
3122
-
3123
- if (currentWindow === window.top) break;
3124
- currentWindow = currentWindow.parent;
3125
- }
3126
-
3127
- return result;
3128
- }
3129
- /**
3130
- * @param {String} env key value from auction, indicates the environment where tag is served
3131
- * @returns true if env exists and is equal to the string 'mobile-app'
3132
- */
3133
-
3134
-
3135
- function isMobileApp(env) {
3136
- return env && env === 'mobile-app';
3137
- }
3138
-
3139
- return {
3140
- isMobileApp: isMobileApp,
3141
- isCrossDomain: isCrossDomain,
3142
- isSafeFrame: isSafeFrame,
3143
- isAmp: isAmp,
3144
- canLocatePrebid: canLocatePrebid
3145
- };
3146
- }
3147
-
3148
3100
  /***/ })
3149
3101
  /******/ ]);