diff --git a/README.md b/README.md index 6170aa6..1385f32 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You can display an advertisement by calling the `registerAd` method, this can be arcAds.registerAd({ id: 'div-id-123', slotName: 'hp/hp-1', - dimensions: '[[300, 250], [300, 600]]', + dimensions: [[300, 250], [300, 600]], display: 'desktop' }) ``` @@ -54,7 +54,7 @@ The following table shows all of the possible parameters the `registerAd` method | ------------- | ------------- | ------------- | ------------- | | `id` | The `id` parameter corresponds to a div id on the page that the advertisement should render into. | `String` | `Required` | | `slotName` | The `slotName` parameter is equal to the slot name configured within DFP, for example `sitename/hp/hp-1`. The publisher ID gets attached to the slot name within the ArcAds logic. | `String` | `Required` | -| `dimensions` | The `dimensions` parameter should be a string representing an array of arrays containing the advertisement sizes the slot can load. If left empty the advertisement will be considered as an out of page unit. | `String` | `Optional` | +| `dimensions` | The `dimensions` parameter should be an array with array of arrays containing the advertisement sizes the slot can load. If left empty the advertisement will be considered as an out of page unit. | `Array` | `Optional` | | `adType` | The `adType` parameter should describe the type of advertisement, for instance `leaderboard` or `cube`. | `String` | `Optional` | | `display` | The `display` paramter determines which user agents can render the advertisement. The available choices are `desktop`, `mobile`, or `all`. If a value is not provided it will default to `all`. | `String` | `Optional` | | `targeting` | The `targeting` paramter accepts an object containing key/value pairs which should attached to the advertisement request. | `Object` | `Optional` | @@ -105,7 +105,7 @@ arcAds.registerAd({ id: 'div-id-123', slotName: 'hp/hp-1', adType: 'cube', - dimensions: '[[300, 250], [300, 600]]', + dimensions: [[300, 250], [300, 600]], display: 'all', targeting: { section: 'weather' @@ -118,7 +118,7 @@ The service will automatically give the advertisement a `position` target key/va If `adType` is exluded from the `registerAd` call the automatic position targeting will not be included. ## Size Mapping -You can configure DFP size mapped ads with the same registration call by adding a `sizemap` object. To utilize size mapping the `dimensions` key should be updated to include a string representing a nested array of arrays containing the applicable sizes for a specific breakpoint. +You can configure DFP size mapped ads with the same registration call by adding a `sizemap` object. To utilize size mapping the `dimensions` key should be updated to include an array representing a nested array of arrays containing the applicable sizes for a specific breakpoint. ```javascript [ [[970, 250], [970, 90], [728, 90]], @@ -141,12 +141,12 @@ arcAds.registerAd({ id: 'div-id-123', slotName: 'hp/hp-1', adType: 'cube', - dimensions: '[ [[970, 250], [970, 90], [728, 90]], [[728, 90]], [[320, 100], [320, 50]] ]', + dimensions: [ [[970, 250], [970, 90], [728, 90]], [[728, 90]], [[320, 100], [320, 50]] ], targeting: { section: 'weather' }, sizemap: { - breakpoints: '[ [1280, 0], [800, 0], [0, 0] ]', + breakpoints: [ [1280, 0], [800, 0], [0, 0] ], refresh: true } }) @@ -161,7 +161,7 @@ You can setup a function within the `registerAd` call by adding a `prerender` pa arcAds.registerAd({ id: 'div-id-123', slotName: 'hp/hp-1', - dimensions: '[[300, 250], [300, 600]]', + dimensions: [[300, 250], [300, 600]], display: 'desktop', prerender: window.adFunction }) @@ -281,9 +281,9 @@ arcAds.registerAd({ slotName: 'hp/hp-1', adType: 'cube', display: 'desktop', - dimensions: '[ [[970, 250], [970, 90], [728, 90]], [[728, 90]], [[320, 100], [320, 50]] ]', + dimensions: [ [[970, 250], [970, 90], [728, 90]], [[728, 90]], [[320, 100], [320, 50]] ], sizemap: { - breakpoints: '[ [1280, 0], [800, 0], [0, 0] ]', + breakpoints: [ [1280, 0], [800, 0], [0, 0] ], refresh: 'true' }, bidding: { diff --git a/dist/arcads.js b/dist/arcads.js index 36cb391..5e7ce0f 100644 --- a/dist/arcads.js +++ b/dist/arcads.js @@ -1,1957 +1 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else { - var a = factory(); - for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; - } -})(typeof self !== 'undefined' ? self : this, function() { -return /******/ (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] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = 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; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 5); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.initializeGPT = initializeGPT; -exports.refreshSlot = refreshSlot; -exports.queueGoogletagCommand = queueGoogletagCommand; -exports.setTargeting = setTargeting; -exports.dfpSettings = dfpSettings; -exports.determineSlotName = determineSlotName; - -var _resources = __webpack_require__(3); - -var _query = __webpack_require__(14); - -/** -* @desc Initializes the Google Publisher tag scripts. -**/ -function initializeGPT() { - window.googletag = window.googletag || {}; - window.googletag.cmd = window.googletag.cmd || []; - - (0, _resources.appendResource)('script', '//www.googletagservices.com/tag/js/gpt.js', true, true); -} - -/** -* @desc Refreshes an advertisement via the GPT refresh method. If a prerender function is provided it is executed prior to the refresh. -* @param {object} obj - An object containing all of the function arguments. -* @param {Object} obj.ad - An object containing the GPT ad slot. -* @param {boolean} obj.correlator - An optional boolean that describes if the correlator value should update or not. -* @param {function} obj.prerender - An optional function that will run before the advertisement renders. -* @param {object} obj.info - An object containing information about the advertisement that is about to load. -**/ -function refreshSlot(_ref) { - var ad = _ref.ad, - _ref$correlator = _ref.correlator, - correlator = _ref$correlator === undefined ? false : _ref$correlator, - _ref$prerender = _ref.prerender, - prerender = _ref$prerender === undefined ? null : _ref$prerender, - _ref$info = _ref.info, - info = _ref$info === undefined ? {} : _ref$info; - - new Promise(function (resolve) { - if (prerender) { - try { - prerender(info).then(function () { - resolve('Prerender function has completed.'); - }); - } catch (error) { - console.warn('ArcAds: Prerender function did not return a promise or there was an error.\n Documentation: https://github.com/wapopartners/arc-ads/wiki/Utilizing-a-Prerender-Hook'); - resolve('Prerender function did not return a promise or there was an error, ignoring.'); - } - } else { - resolve('No Prerender function was provided.'); - } - }).then(function () { - runRefreshEvent(); - }); - - function runRefreshEvent() { - if (window.googletag && googletag.pubadsReady) { - window.googletag.pubads().refresh([ad], { changeCorrelator: correlator }); - } else { - setTimeout(function () { - runRefreshEvent(); - }, 200); - } - } -} - -/** -* @desc Queues a command inside of GPT. -* @param {function} fn - Accepts a function to push into the Prebid command queue. -**/ -function queueGoogletagCommand(fn) { - window.googletag.cmd.push(fn); -} - -/** -* @desc Assigns key/value targeting to a specific advertisement. -* @param {Object} ad - An object containing the GPT ad slot. -* @param {Object} options - An object containing all of the key/value targeting pairs to assign to the advertisement. -**/ -function setTargeting(ad, options) { - for (var key in options) { - if (options.hasOwnProperty(key) && options[key]) { - ad.setTargeting(key, options[key]); - } - } -} - -/** -* @desc Configures the GPT configuration options. -* @param {function} handleSlotRenderEnded - Callback function that gets fired whenever a GPT ad slot has finished rendering. -**/ -function dfpSettings(handleSlotRenderEnded) { - window.googletag.pubads().disableInitialLoad(); - window.googletag.pubads().enableSingleRequest(); - window.googletag.pubads().enableAsyncRendering(); - window.googletag.enableServices(); - - if (handleSlotRenderEnded) { - window.googletag.pubads().addEventListener('slotRenderEnded', handleSlotRenderEnded); - } -} - -/** -* @desc Determines the full slot name of the ad unit. If a user appends an 'adslot' query parameter to the page URL the slot name will be verridden. -* @param {string} dfpCode - A string containing the publishers DFP id code. -* @param {string} slotName - A string containing the slot name of the advertisement, for example 'homepage'. -* @return - Returns a string combining the DFP id code and the slot name, for example '123/homepage'. -**/ -function determineSlotName(dfpCode, slotName) { - var slotOverride = (0, _query.expandQueryString)('adslot'); - if (slotOverride && (slotOverride !== '' || slotOverride !== null)) { - return dfpCode + '/' + slotOverride; - } - return dfpCode + '/' + slotName; -} - -/***/ }), -/* 1 */ -/***/ (function(module, exports) { - -var g; - -// This works in non-strict mode -g = (function() { - return this; -})(); - -try { - // This works if eval is allowed (see CSP) - g = g || Function("return this")() || (1,eval)("this"); -} catch(e) { - // This works if the window reference is available - if(typeof window === "object") - g = window; -} - -// g can still be undefined, but nothing to do about it... -// We return undefined, instead of nothing here, so it's -// easier to handle this case. if(!global) { ...} - -module.exports = g; - - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.initializeBiddingServices = initializeBiddingServices; -exports.fetchBids = fetchBids; - -var _resources = __webpack_require__(3); - -var _prebid = __webpack_require__(4); - -var _amazon = __webpack_require__(15); - -var _gpt = __webpack_require__(0); - -/** -* @desc Initializes all header bidding services and appends the applicable scripts to the page. -* @param {object} obj - An object containing all of the function arguments. -* @param {object} obj.prebid - An object containing configuration data for Prebid.js. -* @param {object} obj.amazon - An object containing configuration data for Amazon A9 and TAM. -**/ -function initializeBiddingServices(_ref) { - var _ref$prebid = _ref.prebid, - prebid = _ref$prebid === undefined ? false : _ref$prebid, - _ref$amazon = _ref.amazon, - amazon = _ref$amazon === undefined ? false : _ref$amazon; - - window.arcBiddingReady = false; - - var enablePrebid = new Promise(function (resolve) { - if (prebid && prebid.enabled) { - var pbjs = pbjs || {}; - pbjs.que = pbjs.que || []; - - resolve('Prebid has been initialized'); - } else { - resolve('Prebid is not enabled on the wrapper...'); - } - }); - - var enableAmazon = new Promise(function (resolve) { - if (amazon && amazon.enabled) { - (0, _resources.appendResource)('script', '//c.amazon-adsystem.com/aax2/apstag.js', true, true, function () { - if (amazon.id && amazon.id !== '') { - (0, _amazon.queueAmazonCommand)(function () { - // Initializes the Amazon APS tag script. - window.apstag.init({ - pubID: amazon.id, - adServer: 'googletag' - }); - - resolve('Amazon scripts have been added onto the page!'); - }); - } else { - console.warn('ArcAds: Missing Amazon account id. \n Documentation: https://github.com/wapopartners/arc-ads#amazon-tama9'); - resolve('Amazon is not enabled on the wrapper...'); - } - }); - } else { - resolve('Amazon is not enabled on the wrapper...'); - } - }); - - // Waits for all header bidding services to be initialized before telling the service it's ready to retrieve bids. - Promise.all([enablePrebid, enableAmazon]).then(function () { - window.arcBiddingReady = true; - }); -} - -/** -* @desc Fetches a bid for an advertisement based on which services are enabled on unit and the wrapper. -* @param {object} obj - An object containing all of the function arguments. -* @param {Object} obj.ad - An object containing the GPT ad slot. -* @param {string} obj.id - A string containing the advertisement id corresponding to the div the advertisement will load into. -* @param {string} obj.slotName - A string containing the slot name of the advertisement, for instance '1234/adn.com/homepage'. -* @param {Array} obj.dimensions - An array containing all of the applicable sizes the advertisement can use. -* @param {Object} obj.wrapper - An object containing all of the wrapper settings. -* @param {Array} obj.bidding - Contains all of the applicable bid data, such as which vendors to use and their placement ids. -* @param {boolean} obj.correlator - An optional boolean that describes if the correlator value should update or not. -* @param {function} obj.prerender - An optional function that will run before the advertisement renders. -**/ -function fetchBids(_ref2) { - var _this = this; - - var ad = _ref2.ad, - id = _ref2.id, - slotName = _ref2.slotName, - dimensions = _ref2.dimensions, - wrapper = _ref2.wrapper, - bidding = _ref2.bidding, - _ref2$correlator = _ref2.correlator, - correlator = _ref2$correlator === undefined ? false : _ref2$correlator, - prerender = _ref2.prerender; - - var adInfo = { - adUnit: ad, - adSlot: slotName, - adDimensions: dimensions, - adId: id - }; - - var prebidBids = new Promise(function (resolve) { - if (wrapper.prebid && wrapper.prebid.enabled) { - var timeout = wrapper.prebid.timeout || 700; - if (bidding.prebid.slotSuffix) { - adInfo.adSlot = '' + slotName + bidding.prebid.slotSuffix; - } - - _prebid.queuePrebidCommand.bind(_this, (0, _prebid.fetchPrebidBids)(ad, id, timeout, adInfo, prerender, function () { - resolve('Fetched Prebid ads!'); - })); - } else { - resolve('Prebid is not enabled on the wrapper...'); - } - }); - - var amazonBids = new Promise(function (resolve) { - if (wrapper.amazon && wrapper.amazon.enabled) { - var targetedSlotName = bidding.amazon.slotSuffix ? '' + slotName + bidding.amazon.slotSuffix : slotName; - - (0, _amazon.fetchAmazonBids)(id, targetedSlotName, dimensions, function () { - resolve('Fetched Amazon ads!'); - }); - } else { - resolve('Amazon is not enabled on the wrapper...'); - } - }); - - if (window.arcBiddingReady) { - Promise.all([prebidBids, amazonBids]).then(function () { - (0, _gpt.refreshSlot)({ - ad: ad, - correlator: correlator, - prerender: prerender, - info: adInfo - }); - }); - } else { - setTimeout(function () { - fetchBids({ - ad: ad, - id: id, - slotName: slotName, - dimensions: dimensions, - wrapper: wrapper, - bidding: bidding, - correlator: correlator, - prerender: prerender - }); - }, 200); - } -} - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.appendResource = appendResource; -/** -* @desc Appends a remote resource to the page within a HTML tag. -* @param {string} tagname - A string containing the type of HTML tag that should be appended. -* @param {string} url - A string containing the path of the resource. -* @param {boolean} async - A boolean representing if the resource should be loaded asynchronously or not. -* @param {boolean} defer - A boolean representing if the resource should be deferred or not. -* @param {function} cb - An optional callback function that should fire whenever the resource has been appended. -**/ -function appendResource(tagname, url, async, defer, cb) { - var tag = document.createElement(tagname); - if (tagname === 'script') { - tag.src = url; - tag.async = async || false; - tag.defer = async || defer || false; - } else { - return; - } - (document.head || document.documentElement).appendChild(tag); - - if (cb) { - cb(); - } -} - -/***/ }), -/* 4 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.queuePrebidCommand = queuePrebidCommand; -exports.fetchPrebidBids = fetchPrebidBids; -exports.addUnit = addUnit; - -var _gpt = __webpack_require__(0); - -/** -* @desc Queues a command inside of Prebid.js -* @param {function} fn - Accepts a function to push into the Prebid command queue. -**/ -function queuePrebidCommand(fn) { - pbjs.que.push(fn); -} - -/** -* @desc Calls the Prebid request method for fetching bids, once fetched the advertisement is refreshed unless a callback is defined. -* @param {object} ad - An object containing the GPT ad slot. -* @param {string} id - A string containing the advertisement id corresponding to the div the advertisement will load into. -* @param {number} timeout - An integer communicating how long in ms the Prebid.js service should wait before it closes the auction for a lot. -* @param {object} info - An object containing information about the advertisement that is about to load. -* @param {function} prerender - An optional function that will run before the advertisement renders. -* @param {function} cb - An optional callback function that should fire whenever the bidding has concluded. -**/ -function fetchPrebidBids(ad, id, timeout, info, prerender) { - var cb = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null; - - pbjs.requestBids({ - timeout: timeout, - adUnitCodes: [id], - bidsBackHandler: function bidsBackHandler() { - pbjs.setTargetingForGPTAsync([id]); - if (cb) { - cb(); - } else { - (0, _gpt.refreshSlot)({ ad: ad, info: info, prerender: prerender }); - } - } - }); -} - -/** -* @desc Registers an advertisement with Prebid.js so it's prepared to fetch bids for it. -* @param {string} code - Contains the div id used for the advertisement -* @param {array} sizes - An array of applicable ad sizes that are available for bidding. -* @param {object} bids - Contains all of the applicable bid data, such as which vendors to use and their placement ids. -* @param {object} wrapper - An object containing all enabled services on the Arc Ads. -**/ -function addUnit(code, sizes, bids) { - var wrapper = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; - - // Formats the add unit for prebid.. - var slot = { code: code, sizes: sizes, bids: bids }; - var sizeConfig = wrapper.sizeConfig; - - - pbjs.addAdUnits(slot); - - if (sizeConfig) { - pbjs.setConfig({ sizeConfig: [sizeConfig] }); - } -} - -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.ArcAds = undefined; - -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -__webpack_require__(6); - -var _mobile = __webpack_require__(12); - -var _customTargeting = __webpack_require__(13); - -var _headerbidding = __webpack_require__(2); - -var _gpt = __webpack_require__(0); - -var _prebid = __webpack_require__(4); - -var _sizemapping = __webpack_require__(16); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -/** @desc Displays an advertisement from Google DFP with optional support for Prebid.js and Amazon TAM/A9. **/ -var ArcAds = exports.ArcAds = function () { - function ArcAds(options) { - var handleSlotRendered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - - _classCallCheck(this, ArcAds); - - this.dfpId = options.dfp.id || ''; - this.wrapper = options.bidding || {}; - this.positions = []; - - window.isMobile = _mobile.MobileDetection; - - if (this.dfpId === '') { - console.warn('ArcAds: DFP id is missing from the arcads initialization script.\n Documentation: https://github.com/wapopartners/arc-ads#getting-started'); - } else { - (0, _gpt.initializeGPT)(); - (0, _gpt.queueGoogletagCommand)(_gpt.dfpSettings.bind(this, handleSlotRendered)); - (0, _headerbidding.initializeBiddingServices)(this.wrapper); - } - } - - /** - * @desc Registers an advertisement in the service. - * @param {object} params - An object containing all of the advertisement configuration settings such as slot name, id, and position. - **/ - - - _createClass(ArcAds, [{ - key: 'registerAd', - value: function registerAd(params) { - var id = params.id, - dimensions = params.dimensions, - _params$adType = params.adType, - adType = _params$adType === undefined ? false : _params$adType, - _params$targeting = params.targeting, - targeting = _params$targeting === undefined ? {} : _params$targeting, - _params$display = params.display, - display = _params$display === undefined ? 'all' : _params$display, - _params$bidding = params.bidding, - bidding = _params$bidding === undefined ? false : _params$bidding; - - /* If positional targeting doesn't exist it gets assigned a numeric value - based on the order and type of the advertisement. This logic is skipped if adType is not defined. */ - - if ((!targeting.hasOwnProperty('position') || _typeof(targeting.position) === 'object') && adType !== false) { - var position = this.positions[adType] + 1 || 1; - this.positions[adType] = position; - - if (_typeof(targeting.position) === 'object' && targeting.position.as) { - Object.assign(position, (0, _customTargeting.renamePositionKey)(targeting, position)); - } else { - var positionParam = Object.assign(targeting, { position: position }); - Object.assign(params, { targeting: positionParam }); - } - } - - if (isMobile.any() && display === 'mobile' || !isMobile.any() && display === 'desktop' || display === 'all') { - // Registers the advertisement with Prebid.js if enabled on both the unit and wrapper. - if (bidding.prebid && bidding.prebid.bids && this.wrapper.prebid && this.wrapper.prebid.enabled && dimensions) { - _prebid.queuePrebidCommand.bind(this, (0, _prebid.addUnit)(id, dimensions, bidding.prebid.bids, this.wrapper.prebid)); - } - - (0, _gpt.queueGoogletagCommand)(this.displayAd.bind(this, params)); - } - } - - /** - * @desc Registers a collection of advertisements. - * @param {array} collection - An array containing a list of objects containing advertisement data. - **/ - - }, { - key: 'registerAdCollection', - value: function registerAdCollection(collection) { - var _this = this; - - collection.forEach(function (advert) { - _this.registerAd(advert); - }); - } - - /** - * @desc Displays an advertisement and sets up any neccersary event binding. - * @param {object} params - An object containing all of the function arguments. - * @param {string} params.id - A string containing the advertisement id corresponding to the div the advertisement will load into. - * @param {string} params.slotName - A string containing the slot name of the advertisement, for instance '1234/news/homepage'. - * @param {array} params.dimensions - An array containing all of the applicable sizes the advertisement can use. - * @param {object} params.targeting - An object containing all of the advertisements targeting data. - * @param {array} params.sizemap - An array containing optional size mapping information. - * @param {object} params.bidding - Contains all of the applicable bid data, such as which vendors to use and their placement ids. - * @param {function} params.prerender - An optional function that will run before the advertisement renders. - **/ - - }, { - key: 'displayAd', - value: function displayAd(_ref) { - var id = _ref.id, - slotName = _ref.slotName, - dimensions = _ref.dimensions, - targeting = _ref.targeting, - _ref$sizemap = _ref.sizemap, - sizemap = _ref$sizemap === undefined ? false : _ref$sizemap, - _ref$bidding = _ref.bidding, - bidding = _ref$bidding === undefined ? false : _ref$bidding, - _ref$prerender = _ref.prerender, - prerender = _ref$prerender === undefined ? null : _ref$prerender; - - var fullSlotName = (0, _gpt.determineSlotName)(this.dfpId, slotName); - var parsedDimensions = !dimensions.length ? null : JSON.parse(dimensions); - var ad = !dimensions ? window.googletag.defineOutOfPageSlot(fullSlotName, id) : window.googletag.defineSlot(fullSlotName, parsedDimensions, id); - - if (sizemap && sizemap.breakpoints && dimensions) { - var _prepareSizeMaps = (0, _sizemapping.prepareSizeMaps)(parsedDimensions, sizemap.breakpoints), - mapping = _prepareSizeMaps.mapping, - breakpoints = _prepareSizeMaps.breakpoints, - correlators = _prepareSizeMaps.correlators; - - ad.defineSizeMapping(mapping); - - if (sizemap.refresh) { - (0, _sizemapping.setResizeListener)({ - ad: ad, - slotName: fullSlotName, - breakpoints: breakpoints, - id: id, - mapping: mapping, - correlators: correlators, - bidding: bidding, - wrapper: this.wrapper, - prerender: prerender - }); - } - } - - ad.addService(window.googletag.pubads()); - - (0, _gpt.setTargeting)(ad, targeting); - - if (bidding && dimensions) { - (0, _headerbidding.fetchBids)({ - ad: ad, - id: id, - slotName: fullSlotName, - dimensions: parsedDimensions, - wrapper: this.wrapper, - prerender: prerender, - bidding: bidding - }); - } else { - (0, _gpt.refreshSlot)({ - ad: ad, - prerender: prerender, - info: { - adUnit: ad, - adSlot: fullSlotName, - adDimensions: parsedDimensions, - adId: id - } - }); - } - } - }]); - - return ArcAds; -}(); - -/***/ }), -/* 6 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var _promisePolyfill = __webpack_require__(7); - -var _promisePolyfill2 = _interopRequireDefault(_promisePolyfill); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -if (!window.Promise) { - window.Promise = _promisePolyfill2.default; -} - -/* eslint-disable */ - -// source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill -/* Object.assign() for IE11 (obviously) */ -if (typeof Object.assign != 'function') { - // Must be writable: true, enumerable: false, configurable: true - Object.defineProperty(Object, "assign", { - value: function assign(target, varArgs) { - // .length of function is 2 - 'use strict'; - - if (target == null) { - // TypeError if undefined or null - throw new TypeError('Cannot convert undefined or null to object'); - } - - var to = Object(target); - - for (var index = 1; index < arguments.length; index++) { - var nextSource = arguments[index]; - - if (nextSource != null) { - // Skip over if undefined or null - for (var nextKey in nextSource) { - // Avoid bugs when hasOwnProperty is shadowed - if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { - to[nextKey] = nextSource[nextKey]; - } - } - } - } - return to; - }, - writable: true, - configurable: true - }); -} - -/* eslint-enable */ - -/***/ }), -/* 7 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); -/* WEBPACK VAR INJECTION */(function(setImmediate) {/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__finally__ = __webpack_require__(11); - - -// Store setTimeout reference so promise-polyfill will be unaffected by -// other code modifying setTimeout (like sinon.useFakeTimers()) -var setTimeoutFunc = setTimeout; - -function noop() {} - -// Polyfill for Function.prototype.bind -function bind(fn, thisArg) { - return function() { - fn.apply(thisArg, arguments); - }; -} - -function Promise(fn) { - if (!(this instanceof Promise)) - throw new TypeError('Promises must be constructed via new'); - if (typeof fn !== 'function') throw new TypeError('not a function'); - this._state = 0; - this._handled = false; - this._value = undefined; - this._deferreds = []; - - doResolve(fn, this); -} - -function handle(self, deferred) { - while (self._state === 3) { - self = self._value; - } - if (self._state === 0) { - self._deferreds.push(deferred); - return; - } - self._handled = true; - Promise._immediateFn(function() { - var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; - if (cb === null) { - (self._state === 1 ? resolve : reject)(deferred.promise, self._value); - return; - } - var ret; - try { - ret = cb(self._value); - } catch (e) { - reject(deferred.promise, e); - return; - } - resolve(deferred.promise, ret); - }); -} - -function resolve(self, newValue) { - try { - // Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure - if (newValue === self) - throw new TypeError('A promise cannot be resolved with itself.'); - if ( - newValue && - (typeof newValue === 'object' || typeof newValue === 'function') - ) { - var then = newValue.then; - if (newValue instanceof Promise) { - self._state = 3; - self._value = newValue; - finale(self); - return; - } else if (typeof then === 'function') { - doResolve(bind(then, newValue), self); - return; - } - } - self._state = 1; - self._value = newValue; - finale(self); - } catch (e) { - reject(self, e); - } -} - -function reject(self, newValue) { - self._state = 2; - self._value = newValue; - finale(self); -} - -function finale(self) { - if (self._state === 2 && self._deferreds.length === 0) { - Promise._immediateFn(function() { - if (!self._handled) { - Promise._unhandledRejectionFn(self._value); - } - }); - } - - for (var i = 0, len = self._deferreds.length; i < len; i++) { - handle(self, self._deferreds[i]); - } - self._deferreds = null; -} - -function Handler(onFulfilled, onRejected, promise) { - this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; - this.onRejected = typeof onRejected === 'function' ? onRejected : null; - this.promise = promise; -} - -/** - * Take a potentially misbehaving resolver function and make sure - * onFulfilled and onRejected are only called once. - * - * Makes no guarantees about asynchrony. - */ -function doResolve(fn, self) { - var done = false; - try { - fn( - function(value) { - if (done) return; - done = true; - resolve(self, value); - }, - function(reason) { - if (done) return; - done = true; - reject(self, reason); - } - ); - } catch (ex) { - if (done) return; - done = true; - reject(self, ex); - } -} - -Promise.prototype['catch'] = function(onRejected) { - return this.then(null, onRejected); -}; - -Promise.prototype.then = function(onFulfilled, onRejected) { - var prom = new this.constructor(noop); - - handle(this, new Handler(onFulfilled, onRejected, prom)); - return prom; -}; - -Promise.prototype['finally'] = __WEBPACK_IMPORTED_MODULE_0__finally__["a" /* default */]; - -Promise.all = function(arr) { - return new Promise(function(resolve, reject) { - if (!arr || typeof arr.length === 'undefined') - throw new TypeError('Promise.all accepts an array'); - var args = Array.prototype.slice.call(arr); - if (args.length === 0) return resolve([]); - var remaining = args.length; - - function res(i, val) { - try { - if (val && (typeof val === 'object' || typeof val === 'function')) { - var then = val.then; - if (typeof then === 'function') { - then.call( - val, - function(val) { - res(i, val); - }, - reject - ); - return; - } - } - args[i] = val; - if (--remaining === 0) { - resolve(args); - } - } catch (ex) { - reject(ex); - } - } - - for (var i = 0; i < args.length; i++) { - res(i, args[i]); - } - }); -}; - -Promise.resolve = function(value) { - if (value && typeof value === 'object' && value.constructor === Promise) { - return value; - } - - return new Promise(function(resolve) { - resolve(value); - }); -}; - -Promise.reject = function(value) { - return new Promise(function(resolve, reject) { - reject(value); - }); -}; - -Promise.race = function(values) { - return new Promise(function(resolve, reject) { - for (var i = 0, len = values.length; i < len; i++) { - values[i].then(resolve, reject); - } - }); -}; - -// Use polyfill for setImmediate for performance gains -Promise._immediateFn = - (typeof setImmediate === 'function' && - function(fn) { - setImmediate(fn); - }) || - function(fn) { - setTimeoutFunc(fn, 0); - }; - -Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { - if (typeof console !== 'undefined' && console) { - console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console - } -}; - -/* harmony default export */ __webpack_exports__["default"] = (Promise); - -/* WEBPACK VAR INJECTION */}.call(__webpack_exports__, __webpack_require__(8).setImmediate)) - -/***/ }), -/* 8 */ -/***/ (function(module, exports, __webpack_require__) { - -/* WEBPACK VAR INJECTION */(function(global) {var scope = (typeof global !== "undefined" && global) || - (typeof self !== "undefined" && self) || - window; -var apply = Function.prototype.apply; - -// DOM APIs, for completeness - -exports.setTimeout = function() { - return new Timeout(apply.call(setTimeout, scope, arguments), clearTimeout); -}; -exports.setInterval = function() { - return new Timeout(apply.call(setInterval, scope, arguments), clearInterval); -}; -exports.clearTimeout = -exports.clearInterval = function(timeout) { - if (timeout) { - timeout.close(); - } -}; - -function Timeout(id, clearFn) { - this._id = id; - this._clearFn = clearFn; -} -Timeout.prototype.unref = Timeout.prototype.ref = function() {}; -Timeout.prototype.close = function() { - this._clearFn.call(scope, this._id); -}; - -// Does not start the time, just sets up the members needed. -exports.enroll = function(item, msecs) { - clearTimeout(item._idleTimeoutId); - item._idleTimeout = msecs; -}; - -exports.unenroll = function(item) { - clearTimeout(item._idleTimeoutId); - item._idleTimeout = -1; -}; - -exports._unrefActive = exports.active = function(item) { - clearTimeout(item._idleTimeoutId); - - var msecs = item._idleTimeout; - if (msecs >= 0) { - item._idleTimeoutId = setTimeout(function onTimeout() { - if (item._onTimeout) - item._onTimeout(); - }, msecs); - } -}; - -// setimmediate attaches itself to the global object -__webpack_require__(9); -// On some exotic environments, it's not clear which object `setimmediate` was -// able to install onto. Search each possibility in the same order as the -// `setimmediate` library. -exports.setImmediate = (typeof self !== "undefined" && self.setImmediate) || - (typeof global !== "undefined" && global.setImmediate) || - (this && this.setImmediate); -exports.clearImmediate = (typeof self !== "undefined" && self.clearImmediate) || - (typeof global !== "undefined" && global.clearImmediate) || - (this && this.clearImmediate); - -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1))) - -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { - -/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) { - "use strict"; - - if (global.setImmediate) { - return; - } - - var nextHandle = 1; // Spec says greater than zero - var tasksByHandle = {}; - var currentlyRunningATask = false; - var doc = global.document; - var registerImmediate; - - function setImmediate(callback) { - // Callback can either be a function or a string - if (typeof callback !== "function") { - callback = new Function("" + callback); - } - // Copy function arguments - var args = new Array(arguments.length - 1); - for (var i = 0; i < args.length; i++) { - args[i] = arguments[i + 1]; - } - // Store and register the task - var task = { callback: callback, args: args }; - tasksByHandle[nextHandle] = task; - registerImmediate(nextHandle); - return nextHandle++; - } - - function clearImmediate(handle) { - delete tasksByHandle[handle]; - } - - function run(task) { - var callback = task.callback; - var args = task.args; - switch (args.length) { - case 0: - callback(); - break; - case 1: - callback(args[0]); - break; - case 2: - callback(args[0], args[1]); - break; - case 3: - callback(args[0], args[1], args[2]); - break; - default: - callback.apply(undefined, args); - break; - } - } - - function runIfPresent(handle) { - // From the spec: "Wait until any invocations of this algorithm started before this one have completed." - // So if we're currently running a task, we'll need to delay this invocation. - if (currentlyRunningATask) { - // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a - // "too much recursion" error. - setTimeout(runIfPresent, 0, handle); - } else { - var task = tasksByHandle[handle]; - if (task) { - currentlyRunningATask = true; - try { - run(task); - } finally { - clearImmediate(handle); - currentlyRunningATask = false; - } - } - } - } - - function installNextTickImplementation() { - registerImmediate = function(handle) { - process.nextTick(function () { runIfPresent(handle); }); - }; - } - - function canUsePostMessage() { - // The test against `importScripts` prevents this implementation from being installed inside a web worker, - // where `global.postMessage` means something completely different and can't be used for this purpose. - if (global.postMessage && !global.importScripts) { - var postMessageIsAsynchronous = true; - var oldOnMessage = global.onmessage; - global.onmessage = function() { - postMessageIsAsynchronous = false; - }; - global.postMessage("", "*"); - global.onmessage = oldOnMessage; - return postMessageIsAsynchronous; - } - } - - function installPostMessageImplementation() { - // Installs an event handler on `global` for the `message` event: see - // * https://developer.mozilla.org/en/DOM/window.postMessage - // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages - - var messagePrefix = "setImmediate$" + Math.random() + "$"; - var onGlobalMessage = function(event) { - if (event.source === global && - typeof event.data === "string" && - event.data.indexOf(messagePrefix) === 0) { - runIfPresent(+event.data.slice(messagePrefix.length)); - } - }; - - if (global.addEventListener) { - global.addEventListener("message", onGlobalMessage, false); - } else { - global.attachEvent("onmessage", onGlobalMessage); - } - - registerImmediate = function(handle) { - global.postMessage(messagePrefix + handle, "*"); - }; - } - - function installMessageChannelImplementation() { - var channel = new MessageChannel(); - channel.port1.onmessage = function(event) { - var handle = event.data; - runIfPresent(handle); - }; - - registerImmediate = function(handle) { - channel.port2.postMessage(handle); - }; - } - - function installReadyStateChangeImplementation() { - var html = doc.documentElement; - registerImmediate = function(handle) { - // Create a