diff --git a/src/kava.js b/src/kava.js index 53b71d9d..479c7565 100644 --- a/src/kava.js +++ b/src/kava.js @@ -102,7 +102,7 @@ class Kava extends BasePlugin { _updateViewabilityModeInModel(isVisible: boolean): void { this._model.updateModel({ - viewabilityMode: isVisible ? ViewabilityMode.IN_VIEW : ViewabilityMode.NOT_IN_VIEW + viewabilityMode: isVisible || this.player.isInPictureInPicture() ? ViewabilityMode.IN_VIEW : ViewabilityMode.NOT_IN_VIEW }); } @@ -800,10 +800,14 @@ class Kava extends BasePlugin { _updateTabModeInModel(hiddenAttr: string): void { this._model.updateModel({ // $FlowFixMe - tabMode: document[hiddenAttr] ? TabMode.TAB_NOT_FOCUSED : TabMode.TAB_FOCUSED + tabMode: this._isTabHidden(hiddenAttr) && !this.player.isInPictureInPicture() ? TabMode.TAB_NOT_FOCUSED : TabMode.TAB_FOCUSED }); } + _isTabHidden(hiddenAttr: string): boolean { + return document[hiddenAttr]; + } + _initTabMode(): void { let hiddenAttr: string; let visibilityChangeEventName: string; diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index d134515a..8ba5e611 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -1095,6 +1095,86 @@ describe('KavaPlugin', function () { kava = getKavaPlugin(); player.play(); }); + + it('should send VIEW event with tabMode set to focused when in pip and tab is hidden', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { + if (params.eventType === KavaEventModel.VIEW.index) { + try { + params.tabMode.should.equal(TabMode.TAB_FOCUSED); + done(); + } catch (e) { + done(e); + } + } + return new RequestBuilder(); + }); + setupPlayer(config); + sandbox.stub(player, 'isInPictureInPicture').returns(true); + kava = getKavaPlugin(); + sandbox.stub(kava, '_isTabHidden').returns(true); + kava._updateTabModeInModel('hidden'); + player.play(); + }); + + it('should send VIEW event with tabMode set to not focused when not in pip and tab is hidden', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { + if (params.eventType === KavaEventModel.VIEW.index) { + try { + params.tabMode.should.equal(TabMode.TAB_NOT_FOCUSED); + done(); + } catch (e) { + done(e); + } + } + return new RequestBuilder(); + }); + setupPlayer(config); + sandbox.stub(player, 'isInPictureInPicture').returns(false); + kava = getKavaPlugin(); + sandbox.stub(kava, '_isTabHidden').returns(true); + kava._updateTabModeInModel('hidden'); + player.play(); + }); + + it('should send VIEW event with viewabilityMode set to in view when in pip mode and player is not visible', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { + if (params.eventType === KavaEventModel.VIEW.index) { + try { + params.viewabilityMode.should.equal(ViewabilityMode.IN_VIEW); + done(); + } catch (e) { + done(e); + } + } + return new RequestBuilder(); + }); + setupPlayer(config); + sandbox.stub(player, 'isInPictureInPicture').returns(true); + kava = getKavaPlugin(); + kava._updateViewabilityModeInModel(false); + sandbox.stub(kava, '_updateViewabilityModeInModel').callsFake(() => {}); + player.play(); + }); + + it('should send VIEW event with viewabilityMode set to not in view when not in pip mode and player is not visible', done => { + sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { + if (params.eventType === KavaEventModel.VIEW.index) { + try { + params.viewabilityMode.should.equal(ViewabilityMode.NOT_IN_VIEW); + done(); + } catch (e) { + done(e); + } + } + return new RequestBuilder(); + }); + setupPlayer(config); + sandbox.stub(player, 'isInPictureInPicture').returns(false); + kava = getKavaPlugin(); + kava._updateViewabilityModeInModel(false); + sandbox.stub(kava, '_updateViewabilityModeInModel').callsFake(() => {}); + player.play(); + }); }); describe('Start Time', () => {