Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FEC-11971): when in PiP mode user is considered not engaged #115

Merged
merged 5 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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