diff --git a/lib/adslot.js b/lib/adslot.js index 010ae64..78b1e6e 100644 --- a/lib/adslot.js +++ b/lib/adslot.js @@ -55,6 +55,7 @@ function (_React$Component) { _this.slotShouldRefresh = _this.slotShouldRefresh.bind(_assertThisInitialized(_assertThisInitialized(_this))); _this.slotRenderEnded = _this.slotRenderEnded.bind(_assertThisInitialized(_assertThisInitialized(_this))); _this.slotIsViewable = _this.slotIsViewable.bind(_assertThisInitialized(_assertThisInitialized(_this))); + _this.slotVisibilityChanged = _this.slotVisibilityChanged.bind(_assertThisInitialized(_assertThisInitialized(_this))); _this.state = { slotId: _this.props.slotId || null }; @@ -124,6 +125,8 @@ function (_React$Component) { _manager.default.attachSlotRenderEnded(this.slotRenderEnded); _manager.default.attachSlotIsViewable(this.slotIsViewable); + + _manager.default.attachSlotVisibilityChanged(this.slotVisibilityChanged); } }, { key: "registerSlot", @@ -144,6 +147,8 @@ function (_React$Component) { _manager.default.detachSlotRenderEnded(this.slotRenderEnded); _manager.default.detachSlotIsViewable(this.slotIsViewable); + + _manager.default.detachSlotVisibilityChanged(this.slotVisibilityChanged); } }, { key: "slotRenderEnded", @@ -163,6 +168,15 @@ function (_React$Component) { } } } + }, { + key: "slotVisibilityChanged", + value: function slotVisibilityChanged(eventData) { + if (eventData.slotId === this.getSlotId()) { + if (this.props.onSlotVisibilityChanged !== undefined) { + this.props.onSlotVisibilityChanged(eventData); + } + } + } }, { key: "slotShouldRefresh", value: function slotShouldRefresh() { @@ -210,6 +224,7 @@ _defineProperty(AdSlot, "propTypes", { targetingArguments: _propTypes.default.object, onSlotRender: _propTypes.default.func, onSlotIsViewable: _propTypes.default.func, + onSlotVisibilityChanged: _propTypes.default.func, shouldRefresh: _propTypes.default.func, slotId: _propTypes.default.string }); diff --git a/lib/manager.js b/lib/manager.js index b4d2960..b8a5c77 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -142,6 +142,14 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { event: event }); }); + pubadsService.addEventListener('slotVisibilityChanged', function (event) { + var slotId = event.slot.getSlotElementId(); + + _this.emit('slotVisibilityChanged', { + slotId: slotId, + event: event + }); + }); pubadsService.setRequestNonPersonalizedAds(_this.personalizedAdsEnabled() ? 0 : 1); var targetingArguments = _this.getTargetingArguments(); // set global targetting arguments @@ -423,6 +431,12 @@ var DFPManager = Object.assign(new _events.EventEmitter().setMaxListeners(0), { detachSlotRenderEnded: function detachSlotRenderEnded(cb) { this.removeListener('slotRenderEnded', cb); }, + attachSlotVisibilityChanged: function attachSlotVisibilityChanged(cb) { + this.on('slotVisibilityChanged', cb); + }, + detachSlotVisibilityChanged: function detachSlotVisibilityChanged(cb) { + this.removeListener('slotVisibilityChanged', cb); + }, attachSlotIsViewable: function attachSlotIsViewable(cb) { this.on('impressionViewable', cb); }, diff --git a/package-lock.json b/package-lock.json index 3d49ab4..3c106a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-dfp", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1e7c06e..8f57d20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-dfp", - "version": "0.11.1", + "version": "0.11.2", "homepage": "https://github.com/jaanauati/react-dfp/", "author": { "name": "Jonatan Alexis Anauati",