Skip to content

Commit

Permalink
fix(FEC-11971): when in PiP mode user is considered not engaged (#115)
Browse files Browse the repository at this point in the history
**the issue:**
when in pip mode and switching tabs, user is not considered as "engaged" in realtime dashboard analytics.

**root cause:** 
realtime analytics dashboard is considering "user engagement" when playback is unmuted and tab is focused. there are another 2 scenarios but they include fullscreen mode, which is irrelevant in case of pip mode.
when switching to another tab, kava plugin is sending view event with tabMode=notFocused even when in pip mode. hence, the realtime graph is showing that the user is not engaged.

**solution:**
kava plugin will report tabMode=focused in case we are in pip mode.
Note- changed also viewabilityMode to "in view" in case we are in pip mode. up until now, the viewabilityMode was "not in view" even when entering pip.

Solves FEC-11971
  • Loading branch information
lianbenjamin authored Feb 20, 2022
1 parent 2bd1b17 commit 645f9a6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down Expand Up @@ -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;
Expand Down
80 changes: 80 additions & 0 deletions test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 645f9a6

Please sign in to comment.