From fce4c9d75438662db85809d35e3fbdf37a6697d4 Mon Sep 17 00:00:00 2001 From: bretthadley Date: Tue, 5 May 2020 13:37:25 +0100 Subject: [PATCH 1/8] add onGPTScriptLoadError event tro catch when browsers block things --- js/dfpslotsprovider.js | 17 ++++++++++++++++- js/manager.js | 9 ++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/js/dfpslotsprovider.js b/js/dfpslotsprovider.js index fb069c6..6998941 100644 --- a/js/dfpslotsprovider.js +++ b/js/dfpslotsprovider.js @@ -51,6 +51,7 @@ export default class DFPSlotsProvider extends React.Component { mobileScaling: PropTypes.number, }), ]), + onGPTScriptLoadError: PropTypes.func }; static defaultProps = { @@ -84,6 +85,7 @@ export default class DFPSlotsProvider extends React.Component { this.getContextValue = this.getContextValue.bind(this); this.loadAlreadyCalled = false; this.loadCallbackAttached = false; + this.gptLoadErrorCallbackAttached = false; this.shouldReloadAds = false; this.totalSlots = 0; this.contextValue = {}; @@ -97,6 +99,8 @@ export default class DFPSlotsProvider extends React.Component { if (this.props.autoLoad && !this.loadAdsIfPossible()) { this.attachLoadCallback(); } + + this.attachGPTLoadErrorCallback(); } shouldComponentUpdate(nextProps) { @@ -163,7 +167,6 @@ export default class DFPSlotsProvider extends React.Component { DFPManager.configureSingleRequest(this.props.singleRequest); DFPManager.configureDisableInitialLoad(this.props.disableInitialLoad); DFPManager.configureLazyLoad( - !!this.props.lazyLoad, typeof this.props.lazyLoad === 'boolean' ? null : this.props.lazyLoad, ); DFPManager.setAdSenseAttributes(this.props.adSenseAttributes); @@ -179,6 +182,18 @@ export default class DFPSlotsProvider extends React.Component { return false; } + attachGPTLoadErrorCallback() { + if(this.gptLoadErrorCallbackAttached === false) { + DFPManager.attachGPTLoadErrorCallback(function(data) { + if(this.props.onGPTScriptLoadError) { + this.props.onGPTScriptLoadError() + } + }) + + this.gptLoadErrorCallbackAttached = true; + } + } + // pretty strait-forward interface that children ad slots use to register // with their DFPSlotProvider parent node. newSlotCallback() { diff --git a/js/manager.js b/js/manager.js index df54b90..2d1eaab 100644 --- a/js/manager.js +++ b/js/manager.js @@ -151,7 +151,10 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), { getGoogletag() { if (googleGPTScriptLoadPromise === null) { - googleGPTScriptLoadPromise = Utils.loadGPTScript(); + googleGPTScriptLoadPromise = Utils.loadGPTScript() + .catch((error) => { + this.emit('gptScriptLoadError', { error }) + }); } return googleGPTScriptLoadPromise; }, @@ -424,6 +427,10 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), { return registeredSlots; }, + attachGPTLoadError(cb) { + this.on('gptScriptLoadError', cb); + }, + attachSlotRenderEnded(cb) { this.on('slotRenderEnded', cb); }, From dbbf844f62681e12715ef3a8eae0c5f132bfb839 Mon Sep 17 00:00:00 2001 From: bretthadley Date: Tue, 5 May 2020 13:54:33 +0100 Subject: [PATCH 2/8] build it --- lib/adslot.js | 122 +++++++++++++++++--------------- lib/dfpslotsprovider.js | 151 +++++++++++++++++++++++----------------- lib/index.js | 8 +-- lib/manager.js | 83 ++++++++++++---------- 4 files changed, 202 insertions(+), 162 deletions(-) diff --git a/lib/adslot.js b/lib/adslot.js index 5468f17..ea72fac 100644 --- a/lib/adslot.js +++ b/lib/adslot.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = exports.AdSlot = void 0; +exports["default"] = exports.AdSlot = void 0; var _react = _interopRequireDefault(require("react")); @@ -13,13 +13,15 @@ var _manager = _interopRequireDefault(require("./manager")); var _dfpslotsprovider = require("./dfpslotsprovider"); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } -function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -27,46 +29,50 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var dynamicAdCount = 0; -var AdSlot = -/*#__PURE__*/ -function (_React$Component) { +var AdSlot = /*#__PURE__*/function (_React$Component) { _inherits(AdSlot, _React$Component); + var _super = _createSuper(AdSlot); + function AdSlot(props) { var _this; _classCallCheck(this, AdSlot); - _this = _possibleConstructorReturn(this, _getPrototypeOf(AdSlot).call(this, props)); - _this.doRegisterSlot = _this.doRegisterSlot.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.generateSlotId = _this.generateSlotId.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.getSlotId = _this.getSlotId.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.mapContextToAdSlotProps = _this.mapContextToAdSlotProps.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.slotShouldRefresh = _this.slotShouldRefresh.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.slotRenderEnded = _this.slotRenderEnded.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.slotRegisterCallback = _this.slotRegisterCallback.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.slotIsViewable = _this.slotIsViewable.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.slotVisibilityChanged = _this.slotVisibilityChanged.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.getClasses = _this.getClasses.bind(_assertThisInitialized(_assertThisInitialized(_this))); + _this = _super.call(this, props); + _this.doRegisterSlot = _this.doRegisterSlot.bind(_assertThisInitialized(_this)); + _this.generateSlotId = _this.generateSlotId.bind(_assertThisInitialized(_this)); + _this.getSlotId = _this.getSlotId.bind(_assertThisInitialized(_this)); + _this.mapContextToAdSlotProps = _this.mapContextToAdSlotProps.bind(_assertThisInitialized(_this)); + _this.slotShouldRefresh = _this.slotShouldRefresh.bind(_assertThisInitialized(_this)); + _this.slotRenderEnded = _this.slotRenderEnded.bind(_assertThisInitialized(_this)); + _this.slotRegisterCallback = _this.slotRegisterCallback.bind(_assertThisInitialized(_this)); + _this.slotIsViewable = _this.slotIsViewable.bind(_assertThisInitialized(_this)); + _this.slotVisibilityChanged = _this.slotVisibilityChanged.bind(_assertThisInitialized(_this)); + _this.getClasses = _this.getClasses.bind(_assertThisInitialized(_this)); _this.state = { slotId: _this.props.slotId || null, className: _this.props.className || '' }; - _this.adElementRef = _react.default.createRef ? _react.default.createRef() : function (element) { + _this.adElementRef = _react["default"].createRef ? _react["default"].createRef() : function (element) { _this.adElementRef = element; }; return _this; @@ -132,19 +138,19 @@ function (_React$Component) { }, { key: "doRegisterSlot", value: function doRegisterSlot() { - _manager.default.registerSlot(_objectSpread({}, this.mapContextToAdSlotProps(), this.props, this.state, { + _manager["default"].registerSlot(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, this.mapContextToAdSlotProps()), this.props), this.state), {}, { slotShouldRefresh: this.slotShouldRefresh })); if (this.props.fetchNow === true) { - _manager.default.load(this.getSlotId()); + _manager["default"].load(this.getSlotId()); } - _manager.default.attachSlotRenderEnded(this.slotRenderEnded); + _manager["default"].attachSlotRenderEnded(this.slotRenderEnded); - _manager.default.attachSlotIsViewable(this.slotIsViewable); + _manager["default"].attachSlotIsViewable(this.slotIsViewable); - _manager.default.attachSlotVisibilityChanged(this.slotVisibilityChanged); + _manager["default"].attachSlotVisibilityChanged(this.slotVisibilityChanged); this.slotRegisterCallback(); } @@ -162,13 +168,13 @@ function (_React$Component) { }, { key: "unregisterSlot", value: function unregisterSlot() { - _manager.default.unregisterSlot(_objectSpread({}, this.mapContextToAdSlotProps(), this.props, this.state)); + _manager["default"].unregisterSlot(_objectSpread(_objectSpread(_objectSpread({}, this.mapContextToAdSlotProps()), this.props), this.state)); - _manager.default.detachSlotRenderEnded(this.slotRenderEnded); + _manager["default"].detachSlotRenderEnded(this.slotRenderEnded); - _manager.default.detachSlotIsViewable(this.slotIsViewable); + _manager["default"].detachSlotIsViewable(this.slotIsViewable); - _manager.default.detachSlotVisibilityChanged(this.slotVisibilityChanged); + _manager["default"].detachSlotVisibilityChanged(this.slotVisibilityChanged); } }, { key: "slotRenderEnded", @@ -176,7 +182,7 @@ function (_React$Component) { if (eventData.slotId === this.getSlotId()) { if (this.props.onSlotRender !== undefined) { // now that slot has rendered we have access to the ref - var params = _objectSpread({}, eventData, { + var params = _objectSpread(_objectSpread({}, eventData), {}, { adElementRef: this.adElementRef }); @@ -220,7 +226,7 @@ function (_React$Component) { var r = true; if (this.props.shouldRefresh !== undefined) { - r = this.props.shouldRefresh(_objectSpread({}, this.mapContextToAdSlotProps(), this.props, { + r = this.props.shouldRefresh(_objectSpread(_objectSpread(_objectSpread({}, this.mapContextToAdSlotProps()), this.props), {}, { slotId: this.getSlotId() })); } @@ -239,35 +245,35 @@ function (_React$Component) { props.id = slotId; } - return _react.default.createElement("div", { + return /*#__PURE__*/_react["default"].createElement("div", { className: this.getClasses().join(' ').trim() - }, _react.default.createElement("div", _extends({ + }, /*#__PURE__*/_react["default"].createElement("div", _extends({ ref: this.adElementRef }, props))); } }]); return AdSlot; -}(_react.default.Component); +}(_react["default"].Component); exports.AdSlot = AdSlot; _defineProperty(AdSlot, "propTypes", { - dfpNetworkId: _propTypes.default.string, - adUnit: _propTypes.default.string, - sizes: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.number), _propTypes.default.string])), - renderOutOfThePage: _propTypes.default.bool, - sizeMapping: _propTypes.default.arrayOf(_propTypes.default.object), - fetchNow: _propTypes.default.bool, - adSenseAttributes: _propTypes.default.object, - targetingArguments: _propTypes.default.object, - onSlotRender: _propTypes.default.func, - onSlotRegister: _propTypes.default.func, - onSlotIsViewable: _propTypes.default.func, - onSlotVisibilityChanged: _propTypes.default.func, - shouldRefresh: _propTypes.default.func, - slotId: _propTypes.default.string, - className: _propTypes.default.string + dfpNetworkId: _propTypes["default"].string, + adUnit: _propTypes["default"].string, + sizes: _propTypes["default"].arrayOf(_propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].number), _propTypes["default"].string])), + renderOutOfThePage: _propTypes["default"].bool, + sizeMapping: _propTypes["default"].arrayOf(_propTypes["default"].object), + fetchNow: _propTypes["default"].bool, + adSenseAttributes: _propTypes["default"].object, + targetingArguments: _propTypes["default"].object, + onSlotRender: _propTypes["default"].func, + onSlotRegister: _propTypes["default"].func, + onSlotIsViewable: _propTypes["default"].func, + onSlotVisibilityChanged: _propTypes["default"].func, + shouldRefresh: _propTypes["default"].func, + slotId: _propTypes["default"].string, + className: _propTypes["default"].string }); _defineProperty(AdSlot, "defaultProps", { @@ -277,15 +283,15 @@ _defineProperty(AdSlot, "defaultProps", { if (_dfpslotsprovider.Context === null) { // React < 16.3 AdSlot.contextTypes = { - dfpNetworkId: _propTypes.default.string, - dfpAdUnit: _propTypes.default.string, - dfpSizeMapping: _propTypes.default.arrayOf(_propTypes.default.object), - dfpTargetingArguments: _propTypes.default.object, - newSlotCallback: _propTypes.default.func + dfpNetworkId: _propTypes["default"].string, + dfpAdUnit: _propTypes["default"].string, + dfpSizeMapping: _propTypes["default"].arrayOf(_propTypes["default"].object), + dfpTargetingArguments: _propTypes["default"].object, + newSlotCallback: _propTypes["default"].func }; } else { AdSlot.contextType = _dfpslotsprovider.Context; } var _default = AdSlot; -exports.default = _default; \ No newline at end of file +exports["default"] = _default; \ No newline at end of file diff --git a/lib/dfpslotsprovider.js b/lib/dfpslotsprovider.js index d60a048..bdec0bf 100644 --- a/lib/dfpslotsprovider.js +++ b/lib/dfpslotsprovider.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = exports.Context = void 0; +exports["default"] = exports.Context = void 0; var _react = _interopRequireDefault(require("react")); @@ -11,9 +11,9 @@ var _propTypes = _interopRequireDefault(require("prop-types")); var _manager = _interopRequireDefault(require("./manager")); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -21,20 +21,24 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } - -function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } - function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } + function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } + +function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } + function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // React.createContext is undefined for React < 16.3 -var Context = _react.default.createContext ? _react.default.createContext({ +var Context = _react["default"].createContext ? _react["default"].createContext({ dfpNetworkId: null, dfpAdUnit: null, dfpSizeMapping: null, @@ -43,25 +47,26 @@ var Context = _react.default.createContext ? _react.default.createContext({ }) : null; exports.Context = Context; -var DFPSlotsProvider = -/*#__PURE__*/ -function (_React$Component) { +var DFPSlotsProvider = /*#__PURE__*/function (_React$Component) { _inherits(DFPSlotsProvider, _React$Component); + var _super = _createSuper(DFPSlotsProvider); + function DFPSlotsProvider(props) { var _this; _classCallCheck(this, DFPSlotsProvider); - _this = _possibleConstructorReturn(this, _getPrototypeOf(DFPSlotsProvider).call(this, props)); - _this.loadAdsIfPossible = _this.loadAdsIfPossible.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.newSlotCallback = _this.newSlotCallback.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.applyConfigs = _this.applyConfigs.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.shouldReloadConfig = _this.shouldReloadConfig.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.attachLoadCallback = _this.attachLoadCallback.bind(_assertThisInitialized(_assertThisInitialized(_this))); - _this.getContextValue = _this.getContextValue.bind(_assertThisInitialized(_assertThisInitialized(_this))); + _this = _super.call(this, props); + _this.loadAdsIfPossible = _this.loadAdsIfPossible.bind(_assertThisInitialized(_this)); + _this.newSlotCallback = _this.newSlotCallback.bind(_assertThisInitialized(_this)); + _this.applyConfigs = _this.applyConfigs.bind(_assertThisInitialized(_this)); + _this.shouldReloadConfig = _this.shouldReloadConfig.bind(_assertThisInitialized(_this)); + _this.attachLoadCallback = _this.attachLoadCallback.bind(_assertThisInitialized(_this)); + _this.getContextValue = _this.getContextValue.bind(_assertThisInitialized(_this)); _this.loadAlreadyCalled = false; _this.loadCallbackAttached = false; + _this.gptLoadErrorCallbackAttached = false; _this.shouldReloadAds = false; _this.totalSlots = 0; _this.contextValue = {}; @@ -83,6 +88,8 @@ function (_React$Component) { if (this.props.autoLoad && !this.loadAdsIfPossible()) { this.attachLoadCallback(); } + + this.attachGPTLoadErrorCallback(); } }, { key: "shouldComponentUpdate", @@ -107,7 +114,7 @@ function (_React$Component) { if (this.props.autoLoad) { if (this.loadAlreadyCalled) { if (this.shouldReloadAds) { - _manager.default.reload(); + _manager["default"].reload(); } } else if (!this.loadAdsIfPossible()) { this.attachLoadCallback(); @@ -146,29 +153,42 @@ function (_React$Component) { }, { key: "applyConfigs", value: function applyConfigs() { - _manager.default.configurePersonalizedAds(this.props.personalizedAds); + _manager["default"].configurePersonalizedAds(this.props.personalizedAds); - _manager.default.configureSingleRequest(this.props.singleRequest); + _manager["default"].configureSingleRequest(this.props.singleRequest); - _manager.default.configureDisableInitialLoad(this.props.disableInitialLoad); + _manager["default"].configureDisableInitialLoad(this.props.disableInitialLoad); - _manager.default.configureLazyLoad(!!this.props.lazyLoad, typeof this.props.lazyLoad === 'boolean' ? null : this.props.lazyLoad); + _manager["default"].configureLazyLoad(typeof this.props.lazyLoad === 'boolean' ? null : this.props.lazyLoad); - _manager.default.setAdSenseAttributes(this.props.adSenseAttributes); + _manager["default"].setAdSenseAttributes(this.props.adSenseAttributes); - _manager.default.setCollapseEmptyDivs(this.props.collapseEmptyDivs); + _manager["default"].setCollapseEmptyDivs(this.props.collapseEmptyDivs); } }, { key: "attachLoadCallback", value: function attachLoadCallback() { if (this.loadCallbackAttached === false) { - _manager.default.on('slotRegistered', this.loadAdsIfPossible); + _manager["default"].on('slotRegistered', this.loadAdsIfPossible); this.loadCallbackAttached = true; return true; } return false; + } + }, { + key: "attachGPTLoadErrorCallback", + value: function attachGPTLoadErrorCallback() { + if (this.gptLoadErrorCallbackAttached === false) { + _manager["default"].attachGPTLoadErrorCallback(function (data) { + if (this.props.onGPTScriptLoadError) { + this.props.onGPTScriptLoadError(); + } + }); + + this.gptLoadErrorCallbackAttached = true; + } } // pretty strait-forward interface that children ad slots use to register // with their DFPSlotProvider parent node. @@ -185,10 +205,10 @@ function (_React$Component) { value: function loadAdsIfPossible() { var r = false; - if (Object.keys(_manager.default.getRegisteredSlots()).length >= this.totalSlots) { - _manager.default.removeListener('slotRegistered', this.loadAdsIfPossible); + if (Object.keys(_manager["default"].getRegisteredSlots()).length >= this.totalSlots) { + _manager["default"].removeListener('slotRegistered', this.loadAdsIfPossible); - _manager.default.load(); + _manager["default"].load(); this.loadAlreadyCalled = true; this.loadCallbackAttached = false; @@ -227,47 +247,48 @@ function (_React$Component) { return children; } - return _react.default.createElement(Context.Provider, { + return /*#__PURE__*/_react["default"].createElement(Context.Provider, { value: this.getContextValue() }, children); } }]); return DFPSlotsProvider; -}(_react.default.Component); +}(_react["default"].Component); -exports.default = DFPSlotsProvider; +exports["default"] = DFPSlotsProvider; _defineProperty(DFPSlotsProvider, "propTypes", { - children: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.array]).isRequired, - autoLoad: _propTypes.default.bool, - autoReload: _propTypes.default.shape({ - dfpNetworkId: _propTypes.default.bool, - personalizedAds: _propTypes.default.bool, - singleRequest: _propTypes.default.bool, - disableInitialLoad: _propTypes.default.bool, - adUnit: _propTypes.default.bool, - sizeMapping: _propTypes.default.bool, - adSenseAttributes: _propTypes.default.bool, - targetingArguments: _propTypes.default.bool, - collapseEmptyDivs: _propTypes.default.bool, - lazyLoad: _propTypes.default.bool + children: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].array]).isRequired, + autoLoad: _propTypes["default"].bool, + autoReload: _propTypes["default"].shape({ + dfpNetworkId: _propTypes["default"].bool, + personalizedAds: _propTypes["default"].bool, + singleRequest: _propTypes["default"].bool, + disableInitialLoad: _propTypes["default"].bool, + adUnit: _propTypes["default"].bool, + sizeMapping: _propTypes["default"].bool, + adSenseAttributes: _propTypes["default"].bool, + targetingArguments: _propTypes["default"].bool, + collapseEmptyDivs: _propTypes["default"].bool, + lazyLoad: _propTypes["default"].bool }), - dfpNetworkId: _propTypes.default.string.isRequired, - personalizedAds: _propTypes.default.bool, - singleRequest: _propTypes.default.bool, - disableInitialLoad: _propTypes.default.bool, - adUnit: _propTypes.default.string, - sizeMapping: _propTypes.default.arrayOf(_propTypes.default.object), - adSenseAttributes: _propTypes.default.object, - targetingArguments: _propTypes.default.object, - collapseEmptyDivs: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.object]), - adSenseAttrs: _propTypes.default.object, - lazyLoad: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.shape({ - fetchMarginPercent: _propTypes.default.number, - renderMarginPercent: _propTypes.default.number, - mobileScaling: _propTypes.default.number - })]) + dfpNetworkId: _propTypes["default"].string.isRequired, + personalizedAds: _propTypes["default"].bool, + singleRequest: _propTypes["default"].bool, + disableInitialLoad: _propTypes["default"].bool, + adUnit: _propTypes["default"].string, + sizeMapping: _propTypes["default"].arrayOf(_propTypes["default"].object), + adSenseAttributes: _propTypes["default"].object, + targetingArguments: _propTypes["default"].object, + collapseEmptyDivs: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].object]), + adSenseAttrs: _propTypes["default"].object, + lazyLoad: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].shape({ + fetchMarginPercent: _propTypes["default"].number, + renderMarginPercent: _propTypes["default"].number, + mobileScaling: _propTypes["default"].number + })]), + onGPTScriptLoadError: _propTypes["default"].func }); _defineProperty(DFPSlotsProvider, "defaultProps", { @@ -294,10 +315,10 @@ _defineProperty(DFPSlotsProvider, "defaultProps", { if (Context === null) { // React < 16.3 DFPSlotsProvider.childContextTypes = { - dfpNetworkId: _propTypes.default.string, - dfpAdUnit: _propTypes.default.string, - dfpSizeMapping: _propTypes.default.arrayOf(_propTypes.default.object), - dfpTargetingArguments: _propTypes.default.object, - newSlotCallback: _propTypes.default.func + dfpNetworkId: _propTypes["default"].string, + dfpAdUnit: _propTypes["default"].string, + dfpSizeMapping: _propTypes["default"].arrayOf(_propTypes["default"].object), + dfpTargetingArguments: _propTypes["default"].object, + newSlotCallback: _propTypes["default"].func }; } \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index b2e94c1..966b2fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,11 +11,11 @@ var _adslot = _interopRequireDefault(require("./adslot")); var _dfpslotsprovider = _interopRequireDefault(require("./dfpslotsprovider")); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } -var DFPManager = _manager.default; +var DFPManager = _manager["default"]; exports.DFPManager = DFPManager; -var AdSlot = _adslot.default; +var AdSlot = _adslot["default"]; exports.AdSlot = AdSlot; -var DFPSlotsProvider = _dfpslotsprovider.default; +var DFPSlotsProvider = _dfpslotsprovider["default"]; exports.DFPSlotsProvider = DFPSlotsProvider; \ No newline at end of file diff --git a/lib/manager.js b/lib/manager.js index 05ac54d..5ed0f69 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -3,19 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; +exports["default"] = void 0; var _events = require("events"); var Utils = _interopRequireWildcard(require("./utils")); -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } +function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } -function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; 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; } + +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } var loadPromise = null; var googleGPTScriptLoadPromise = null; @@ -163,8 +167,14 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { } }, getGoogletag: function getGoogletag() { + var _this2 = this; + if (googleGPTScriptLoadPromise === null) { - googleGPTScriptLoadPromise = Utils.loadGPTScript(); + googleGPTScriptLoadPromise = Utils.loadGPTScript()["catch"](function (error) { + _this2.emit('gptScriptLoadError', { + error: error + }); + }); } return googleGPTScriptLoadPromise; @@ -173,7 +183,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { this.collapseEmptyDivs = collapse; }, load: function load() { - var _this2 = this; + var _this3 = this; for (var _len = arguments.length, slots = new Array(_len), _key = 0; _key < _len; _key++) { slots[_key] = arguments[_key]; @@ -183,7 +193,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { loadPromise = this.doLoad.apply(this, slots); } else { loadPromise = loadPromise.then(function () { - return _this2.doLoad.apply(_this2, slots); + return _this3.doLoad.apply(_this3, slots); }); } }, @@ -212,11 +222,11 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { return this.gptLoadAds(availableSlots); }, gptLoadAds: function gptLoadAds(slotsToInitialize) { - var _this3 = this; + var _this4 = this; return new Promise(function (resolve) { - _this3.getGoogletag().then(function (googletag) { - _this3.configureInitialOptions(googletag); + _this4.getGoogletag().then(function (googletag) { + _this4.configureInitialOptions(googletag); slotsToInitialize.forEach(function (currentSlotId) { registeredSlots[currentSlotId].loading = false; @@ -234,7 +244,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { if (gptSlot !== null) { slot.gptSlot = gptSlot; - var slotTargetingArguments = _this3.getSlotTargetingArguments(currentSlotId); + var slotTargetingArguments = _this4.getSlotTargetingArguments(currentSlotId); if (slotTargetingArguments !== null) { Object.keys(slotTargetingArguments).forEach(function (varName) { @@ -244,7 +254,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { }); } - var slotAdSenseAttributes = _this3.getSlotAdSenseAttributes(currentSlotId); + var slotAdSenseAttributes = _this4.getSlotAdSenseAttributes(currentSlotId); if (slotAdSenseAttributes !== null) { Object.keys(slotAdSenseAttributes).forEach(function (varName) { @@ -265,12 +275,12 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { }); }); - _this3.configureOptions(googletag); + _this4.configureOptions(googletag); googletag.cmd.push(function () { googletag.enableServices(); - if (!_this3.disableInitialLoadIsEnabled()) { + if (!_this4.disableInitialLoadIsEnabled()) { slotsToInitialize.forEach(function (theSlotId) { googletag.display(theSlotId); }); @@ -284,22 +294,22 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { // configure those gpt parameters that need to be set before pubsads service // initialization. configureInitialOptions: function configureInitialOptions(googletag) { - var _this4 = this; + var _this5 = this; googletag.cmd.push(function () { - if (_this4.disableInitialLoadIsEnabled()) { + if (_this5.disableInitialLoadIsEnabled()) { googletag.pubads().disableInitialLoad(); } }); }, configureOptions: function configureOptions(googletag) { - var _this5 = this; + var _this6 = this; googletag.cmd.push(function () { var pubadsService = googletag.pubads(); - pubadsService.setRequestNonPersonalizedAds(_this5.personalizedAdsEnabled() ? 0 : 1); + pubadsService.setRequestNonPersonalizedAds(_this6.personalizedAdsEnabled() ? 0 : 1); - var targetingArguments = _this5.getTargetingArguments(); // set global targetting arguments + var targetingArguments = _this6.getTargetingArguments(); // set global targetting arguments Object.keys(targetingArguments).forEach(function (varName) { @@ -308,16 +318,16 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { } }); // set global adSense attributes - var adSenseAttributes = _this5.getAdSenseAttributes(); + var adSenseAttributes = _this6.getAdSenseAttributes(); Object.keys(adSenseAttributes).forEach(function (key) { pubadsService.set(key, adSenseAttributes[key]); }); - if (_this5.lazyLoadIsEnabled()) { + if (_this6.lazyLoadIsEnabled()) { var args = []; - var config = _this5.getLazyLoadConfig(); + var config = _this6.getLazyLoadConfig(); if (config !== null) { args.push(config); @@ -326,12 +336,12 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { pubadsService.enableLazyLoad.call(args); } - if (_this5.singleRequestIsEnabled()) { + if (_this6.singleRequestIsEnabled()) { pubadsService.enableSingleRequest(); } - if (_this5.collapseEmptyDivs === true || _this5.collapseEmptyDivs === false) { - pubadsService.collapseEmptyDivs(_this5.collapseEmptyDivs); + if (_this6.collapseEmptyDivs === true || _this6.collapseEmptyDivs === false) { + pubadsService.collapseEmptyDivs(_this6.collapseEmptyDivs); } }); }, @@ -373,10 +383,10 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { } }, gptRefreshAds: function gptRefreshAds(slots) { - var _this6 = this; + var _this7 = this; return this.getGoogletag().then(function (googletag) { - _this6.configureOptions(googletag); + _this7.configureOptions(googletag); googletag.cmd.push(function () { var pubadsService = googletag.pubads(); @@ -387,14 +397,14 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { }); }, reload: function reload() { - var _this7 = this; + var _this8 = this; return this.destroyGPTSlots.apply(this, arguments).then(function () { - return _this7.load(); + return _this8.load(); }); }, destroyGPTSlots: function destroyGPTSlots() { - var _this8 = this; + var _this9 = this; for (var _len4 = arguments.length, slotsToDestroy = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { slotsToDestroy[_key4] = arguments[_key4]; @@ -414,7 +424,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { slots.push(slot); } - _this8.getGoogletag().then(function (googletag) { + _this9.getGoogletag().then(function (googletag) { googletag.cmd.push(function () { if (managerAlreadyInitialized === true) { if (slotsToDestroy.length > 0) { @@ -437,7 +447,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { }); }, registerSlot: function registerSlot(_ref) { - var _this9 = this; + var _this10 = this; var slotId = _ref.slotId, dfpNetworkId = _ref.dfpNetworkId, @@ -468,7 +478,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { }); if (autoLoad === true && loadPromise !== null) { - loadPromise = loadPromise.catch().then(function () { + loadPromise = loadPromise["catch"]().then(function () { var slot = registeredSlots[slotId]; if (typeof slot !== 'undefined') { @@ -476,7 +486,7 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { gptSlot = slot.gptSlot; if (loading === false && !gptSlot) { - _this9.load(slotId); + _this10.load(slotId); } } }); @@ -491,6 +501,9 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { getRegisteredSlots: function getRegisteredSlots() { return registeredSlots; }, + attachGPTLoadError: function attachGPTLoadError(cb) { + this.on('gptScriptLoadError', cb); + }, attachSlotRenderEnded: function attachSlotRenderEnded(cb) { this.on('slotRenderEnded', cb); }, @@ -511,4 +524,4 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { } }); var _default = DFPManager; -exports.default = _default; \ No newline at end of file +exports["default"] = _default; \ No newline at end of file From 971c300185b22a46d41a91bba1780fcff3cdb632 Mon Sep 17 00:00:00 2001 From: bretthadley Date: Tue, 5 May 2020 14:01:47 +0100 Subject: [PATCH 3/8] fix lint issues --- js/dfpslotsprovider.js | 12 ++++++------ js/manager.js | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/js/dfpslotsprovider.js b/js/dfpslotsprovider.js index 6998941..ed19b03 100644 --- a/js/dfpslotsprovider.js +++ b/js/dfpslotsprovider.js @@ -51,7 +51,7 @@ export default class DFPSlotsProvider extends React.Component { mobileScaling: PropTypes.number, }), ]), - onGPTScriptLoadError: PropTypes.func + onGPTScriptLoadError: PropTypes.func, }; static defaultProps = { @@ -183,12 +183,12 @@ export default class DFPSlotsProvider extends React.Component { } attachGPTLoadErrorCallback() { - if(this.gptLoadErrorCallbackAttached === false) { - DFPManager.attachGPTLoadErrorCallback(function(data) { - if(this.props.onGPTScriptLoadError) { - this.props.onGPTScriptLoadError() + if (this.gptLoadErrorCallbackAttached === false) { + DFPManager.attachGPTLoadErrorCallback(function handleGPTLoadError(data) { + if (this.props.onGPTScriptLoadError) { + this.props.onGPTScriptLoadError(data); } - }) + }); this.gptLoadErrorCallbackAttached = true; } diff --git a/js/manager.js b/js/manager.js index 2d1eaab..3227e79 100644 --- a/js/manager.js +++ b/js/manager.js @@ -152,9 +152,9 @@ const DFPManager = Object.assign(new EventEmitter().setMaxListeners(0), { getGoogletag() { if (googleGPTScriptLoadPromise === null) { googleGPTScriptLoadPromise = Utils.loadGPTScript() - .catch((error) => { - this.emit('gptScriptLoadError', { error }) - }); + .catch((error) => { + this.emit('gptScriptLoadError', { error }); + }); } return googleGPTScriptLoadPromise; }, From 4a71e58db733656e45d2d88d6566bc5bbfcc471f Mon Sep 17 00:00:00 2001 From: bretthadley Date: Tue, 5 May 2020 15:16:03 +0100 Subject: [PATCH 4/8] typo fix --- js/dfpslotsprovider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/dfpslotsprovider.js b/js/dfpslotsprovider.js index ed19b03..0341c93 100644 --- a/js/dfpslotsprovider.js +++ b/js/dfpslotsprovider.js @@ -184,7 +184,7 @@ export default class DFPSlotsProvider extends React.Component { attachGPTLoadErrorCallback() { if (this.gptLoadErrorCallbackAttached === false) { - DFPManager.attachGPTLoadErrorCallback(function handleGPTLoadError(data) { + DFPManager.attachGPTLoadError(function handleGPTLoadError(data) { if (this.props.onGPTScriptLoadError) { this.props.onGPTScriptLoadError(data); } From 520b1363ce8eb9b0418cbfaa13b2fec100ab64ed Mon Sep 17 00:00:00 2001 From: bretthadley Date: Tue, 5 May 2020 15:22:24 +0100 Subject: [PATCH 5/8] build --- lib/dfpslotsprovider.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/dfpslotsprovider.js b/lib/dfpslotsprovider.js index bdec0bf..d2a12b9 100644 --- a/lib/dfpslotsprovider.js +++ b/lib/dfpslotsprovider.js @@ -181,9 +181,9 @@ var DFPSlotsProvider = /*#__PURE__*/function (_React$Component) { key: "attachGPTLoadErrorCallback", value: function attachGPTLoadErrorCallback() { if (this.gptLoadErrorCallbackAttached === false) { - _manager["default"].attachGPTLoadErrorCallback(function (data) { + _manager["default"].attachGPTLoadError(function handleGPTLoadError(data) { if (this.props.onGPTScriptLoadError) { - this.props.onGPTScriptLoadError(); + this.props.onGPTScriptLoadError(data); } }); From 9f58eae13fc4cd8a362d2af84d87d33140b8a2c6 Mon Sep 17 00:00:00 2001 From: bretthadley Date: Tue, 5 May 2020 15:24:03 +0100 Subject: [PATCH 6/8] v0.17.4 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7893a44..8735628 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "react-dfp", - "version": "0.17.2", + "name": "@redbrain/react-dfp", + "version": "0.17.4", "homepage": "https://github.com/jaanauati/react-dfp/", "author": { "name": "Jonatan Alexis Anauati", From b9d9eb3353455d31ecc6b7518f6560c08ff411d2 Mon Sep 17 00:00:00 2001 From: bretthadley Date: Wed, 6 May 2020 09:15:47 +0100 Subject: [PATCH 7/8] samsung 11 issue fix. --- js/dfpslotsprovider.js | 2 +- lib/dfpslotsprovider.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/dfpslotsprovider.js b/js/dfpslotsprovider.js index 0341c93..19ff782 100644 --- a/js/dfpslotsprovider.js +++ b/js/dfpslotsprovider.js @@ -185,7 +185,7 @@ export default class DFPSlotsProvider extends React.Component { attachGPTLoadErrorCallback() { if (this.gptLoadErrorCallbackAttached === false) { DFPManager.attachGPTLoadError(function handleGPTLoadError(data) { - if (this.props.onGPTScriptLoadError) { + if (this.props && this.props.onGPTScriptLoadError !== undefined) { this.props.onGPTScriptLoadError(data); } }); diff --git a/lib/dfpslotsprovider.js b/lib/dfpslotsprovider.js index d2a12b9..8f6892e 100644 --- a/lib/dfpslotsprovider.js +++ b/lib/dfpslotsprovider.js @@ -182,7 +182,7 @@ var DFPSlotsProvider = /*#__PURE__*/function (_React$Component) { value: function attachGPTLoadErrorCallback() { if (this.gptLoadErrorCallbackAttached === false) { _manager["default"].attachGPTLoadError(function handleGPTLoadError(data) { - if (this.props.onGPTScriptLoadError) { + if (this.props && this.props.onGPTScriptLoadError !== undefined) { this.props.onGPTScriptLoadError(data); } }); From e9c84e9402826913a4503fb5bb5f085a1b3819ba Mon Sep 17 00:00:00 2001 From: bretthadley Date: Wed, 6 May 2020 09:26:08 +0100 Subject: [PATCH 8/8] derp. --- js/dfpslotsprovider.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/dfpslotsprovider.js b/js/dfpslotsprovider.js index 19ff782..acba8e6 100644 --- a/js/dfpslotsprovider.js +++ b/js/dfpslotsprovider.js @@ -83,6 +83,7 @@ export default class DFPSlotsProvider extends React.Component { this.shouldReloadConfig = this.shouldReloadConfig.bind(this); this.attachLoadCallback = this.attachLoadCallback.bind(this); this.getContextValue = this.getContextValue.bind(this); + this.attachGPTLoadErrorCallback = this.attachGPTLoadErrorCallback.bind(this); this.loadAlreadyCalled = false; this.loadCallbackAttached = false; this.gptLoadErrorCallbackAttached = false;