Skip to content

Commit

Permalink
fix(FEC-13783): Kava - Application Events - Fixes (#166)
Browse files Browse the repository at this point in the history
Description of the Changes
Application Events - Fixes

Resolves FEC-13783, FEC-13690
Related PRS:
kaltura/playkit-js-transcript#181
kaltura/playkit-js-dual-screen#132

Related Ticket: FEC-13691

---------

Co-authored-by: JonathanTGold <jonathan.gold@[email protected]>
  • Loading branch information
JonathanTGold and JonathanTGold authored Mar 24, 2024
1 parent d2fb35a commit 228ea0c
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@babel/runtime": "^7.23.8",
"@microsoft/api-extractor": "^7.39.1",
"@playkit-js/browserslist-config": "1.0.8",
"@playkit-js/kaltura-player-js": "^3.17.10",
"@playkit-js/kaltura-player-js": "3.17.12-canary.0-d07f1c5",
"@playkit-js/moderation": "3.2.13-canary.0-5376147",
"@playkit-js/playkit-js": "^0.84.6",
"@playkit-js/playkit-js-downloads": "1.1.0-canary.0-60c49dc",
Expand Down
56 changes: 33 additions & 23 deletions src/application-events-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ import { ButtonType } from './enums/button-type';
import { ApplicationEventType } from './enums/application-event-type';
import { PageLoadType } from './enums/page-load-type';
import { PlaykitUIEvents, PluginsEvents } from './applications-events';
import { KalturaApplication } from './enums/kaltura-application';

export function getApplicationEventsModel(eventObj: KavaEvent, model: KavaModel, innerEventPayload: any): any {
const commonModel = {
partnerId: model.getPartnerId(),
entryId: model.getEntryId(),
sessionId: model.getSessionId(),
kalturaApplication: model.getKalturaApplication(),
kalturaApplicationVer: model.getKalturaApplicationVersion(),
application: model.getApplication(),
applicationVer: model.getApplicationVersion(),
virtualEventId: model.getVirtualEventId()
kalturaApplication: KalturaApplication.PLAYER
};

if (model.getVirtualEventId()) {
commonModel['virtualEventId'] = model.getVirtualEventId();
}
if (model.getKalturaApplication()) {
commonModel['application'] = model.getKalturaApplication();
}
if (model.getApplicationVersion()) {
commonModel['applicationVer'] = model.getApplicationVersion();
}
if (model.getKalturaApplicationVersion()) {
commonModel['kalturaApplicationVer'] = model.getKalturaApplicationVersion();
}
if (model.getUserId()) {
commonModel['userId'] = model.getUserId();
}
Expand Down Expand Up @@ -61,7 +70,7 @@ export const ApplicationEventsModel: { [playerEventName: string]: KavaEvent } =
buttonType: ButtonType.Share,
buttonValue: ''
};
let buttonName: string;
let buttonName: string = '';

switch (payload.socialNetworkName) {
case 'twitter':
Expand All @@ -76,8 +85,9 @@ export const ApplicationEventsModel: { [playerEventName: string]: KavaEvent } =
case 'linkedin':
buttonName = 'Share_embed_linkedin_click';
break;
default:
buttonName = 'unknown';
case 'embed':
buttonName = 'Share_embed_embed_click';
break;
}

return { ...model, buttonName };
Expand All @@ -87,9 +97,9 @@ export const ApplicationEventsModel: { [playerEventName: string]: KavaEvent } =
type: 'SHARE_COPY',
getEventModel: (payload: any): any => ({
eventType: ApplicationEventType.BUTTON_CLICKED,
buttonName: 'Share_embed_X_click',
buttonName: 'Share_embed_copy_click',
buttonType: ButtonType.Share,
buttonValue: payload.videoClippingOption
buttonValue: payload['videoClippingOption'] === 'full' ? 'full-length' : payload['videoClippingOption']
})
},
[PluginsEvents.DOWNLOAD_ITEM_CLICKED]: {
Expand Down Expand Up @@ -152,10 +162,10 @@ export const ApplicationEventsModel: { [playerEventName: string]: KavaEvent } =
[PluginsEvents.NAVIGATION_OPEN]: {
type: 'NAVIGATION_OPEN',
getEventModel: (payload: any): any => ({
eventType: ApplicationEventType.BUTTON_CLICKED,
buttonName: 'Navigation_open',
buttonType: ButtonType.Open,
buttonValue: payload['auto'] ? 'auto' : 'manual'
eventType: payload['auto'] ? ApplicationEventType.PAGE_LOAD : ApplicationEventType.BUTTON_CLICKED,
buttonName: payload['auto'] ? 'Navigation_open_auto' : 'Navigation_open_manual',
buttonType: PageLoadType.View,
buttonValue: ''
})
},
[PluginsEvents.NAVIGATION_CLOSE]: {
Expand Down Expand Up @@ -253,10 +263,10 @@ export const ApplicationEventsModel: { [playerEventName: string]: KavaEvent } =
[PluginsEvents.TRANSCRIPT_OPEN]: {
type: 'TRANSCRIPT_OPEN',
getEventModel: (payload: any): any => ({
eventType: ApplicationEventType.BUTTON_CLICKED,
buttonName: 'Transcript_open',
buttonType: ButtonType.Open,
buttonValue: payload['auto'] ? 'auto' : 'manual'
eventType: payload['auto'] ? ApplicationEventType.PAGE_LOAD : ApplicationEventType.BUTTON_CLICKED,
buttonName: payload['auto'] ? 'Transcript_open_auto' : 'Transcript_open_manual',
buttonType: PageLoadType.View,
buttonValue: ''
})
},
[PluginsEvents.TRANSCRIPT_CLOSE]: {
Expand Down Expand Up @@ -308,18 +318,18 @@ export const ApplicationEventsModel: { [playerEventName: string]: KavaEvent } =
type: 'PLAYLIST_OPEN',
getEventModel: (payload: any): any => ({
eventType: payload['auto'] ? ApplicationEventType.PAGE_LOAD : ApplicationEventType.BUTTON_CLICKED,
buttonValue: payload['position'],
buttonType: ButtonType.Open,
buttonName: payload['auto'] ? 'Playlist_side_panel_open_auto' : 'Playlist_side_panel_open_manual'
buttonName: payload['auto'] ? 'Playlist_side_panel_open_auto' : 'Playlist_side_panel_open_manual',
buttonType: PageLoadType.View,
buttonValue: payload['position']
})
},
[PluginsEvents.PLAYLIST_CLOSE]: {
type: 'PLAYLIST_CLOSE',
getEventModel: (payload: any): any => ({
eventType: ApplicationEventType.BUTTON_CLICKED,
buttonValue: payload['position'],
buttonName: 'Playlist_side_panel_close_manual',
buttonType: ButtonType.Close,
buttonName: 'Playlist_side_panel_close_manual'
buttonValue: payload['position']
})
},
[PluginsEvents.SKIP_BUTTON_CLICK]: {
Expand Down
1 change: 1 addition & 0 deletions src/kava-event-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const KavaEventModel = {
if (model.getPlayerJSLoadTime() !== null) {
eventModel.playerJSLoadTime = model.getPlayerJSLoadTime();
}
eventModel['registeredPlugins'] = model.getRegisteredPlugins();
return eventModel;
}
},
Expand Down
11 changes: 11 additions & 0 deletions src/kava-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class KavaModel {
private canPlayTime!: number;
private targetPosition!: number;
private targetBuffer!: number;
private registeredPlugins!: string;
public totalSegmentsDownloadTime: number = 0;
public totalSegmentsDownloadBytes: number = 0;
public maxSegmentDownloadTime: number = 0;
Expand Down Expand Up @@ -154,6 +155,16 @@ class KavaModel {
return this.targetBuffer;
}

/**
* Gets registered plugins list
* @returns {string} - The current list of loaded plugins
* @memberof KavaModel
* @instance
*/
public getRegisteredPlugins(): string {
return this.registeredPlugins;
}

/**
* Gets an audio language.
* @returns {string} - The audio language.
Expand Down
16 changes: 14 additions & 2 deletions src/kava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { KavaConfigObject, KavaEvent } from './types';
import { DownloadEvent, InfoEvent, ModerationEvent, RelatedEvent, ShareEvent } from './temp-imported-plugins-event-names-temp';
import { PluginsEvents } from './applications-events';
import { EventBucketName } from './enums/event-bucket-name';
import { ApplicationEventsModel } from './application-events-model';
import { ApplicationEventsModel, getApplicationEventsModel } from './application-events-model';

const { Error: PKError, Utils } = core;
const DIVIDER: number = 1024;
Expand Down Expand Up @@ -326,6 +326,7 @@ class Kava extends BasePlugin {
this.eventManager.listen(this.player, this.player.Event.Core.MUTE_CHANGE, () => this._updateSoundModeInModel());
this.eventManager.listen(this.player, this.player.Event.Core.ENTER_FULLSCREEN, () => this._onFullScreenChanged(ScreenMode.FULLSCREEN));
this.eventManager.listen(this.player, this.player.Event.Core.EXIT_FULLSCREEN, () => this._onFullScreenChanged(ScreenMode.NOT_IN_FULLSCREEN));
this.eventManager.listen(this.player, this.player.Event.REGISTERED_PLUGINS_LIST_EVENT, (e) => this._onRegisteredPluginsListChange(e.payload));
this.eventManager.listen(this.player, RelatedEvent.RELATED_OPEN, () => this._onRelatedClicked());
this.eventManager.listen(this.player, RelatedEvent.RELATED_SELECTED, () => this._onRelatedSelected());
this.eventManager.listen(this.player, ShareEvent.SHARE_CLICKED, () => this._onShareClicked());
Expand All @@ -343,7 +344,9 @@ class Kava extends BasePlugin {
Object.values(PluginsEvents).forEach((event) => {
this.eventManager.listen(this.player, event, (e: FakeEvent) => {
if (e.type in ApplicationEventsModel) {
this._sendAnalytics(ApplicationEventsModel[e.type], EventBucketName.ApplicationEvents, e.payload);
if (this._isApplicationEventValid(e)) {
this._sendAnalytics(ApplicationEventsModel[e.type], EventBucketName.ApplicationEvents, e.payload);
}
}
});
});
Expand Down Expand Up @@ -789,6 +792,10 @@ class Kava extends BasePlugin {
this._sendAnalytics(screenMode === ScreenMode.FULLSCREEN ? KavaEventModel.ENTER_FULLSCREEN : KavaEventModel.EXIT_FULLSCREEN);
}

private _onRegisteredPluginsListChange(payload: string[]): void {
this._model.updateModel({ registeredPlugins: payload.join(',') });
}

private _updateSessionStartTimeModel(response: any | number): void {
if (!this._model.getSessionStartTime() && response) {
if (typeof response === 'object') {
Expand Down Expand Up @@ -905,6 +912,11 @@ class Kava extends BasePlugin {
return true;
}

private _isApplicationEventValid(event: FakeEvent): boolean {
const model = getApplicationEventsModel(ApplicationEventsModel[event.type], this._model, event.payload);
return !!model.buttonName;
}

private _logMissingParam(missingParam: string): void {
this.logger.warn(`Kava analytics block report because of missing param ${missingParam}`);
}
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/kava-event-model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class FakeModel {
getSourceEntryId() {
return "source_entry_id"
}

getRegisteredPlugins() {
return 'kava,skip,bumper';
}
}

describe('KavaEventModel', () => {
Expand Down Expand Up @@ -161,7 +165,8 @@ describe('KavaEventModel', () => {
KavaEventModel.IMPRESSION.type.should.equal('IMPRESSION');
KavaEventModel.IMPRESSION.index.should.equal(1);
KavaEventModel.IMPRESSION.getEventModel(fakeModel).should.deep.equal({
playerJSLoadTime: fakeModel.getPlayerJSLoadTime()
playerJSLoadTime: fakeModel.getPlayerJSLoadTime(),
registeredPlugins: fakeModel.getRegisteredPlugins()
});
});

Expand Down
40 changes: 24 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1296,16 +1296,16 @@
classnames "^2.3.2"
linkify-it "^4.0.1"

"@playkit-js/kaltura-player-js@^3.17.10":
version "3.17.10"
resolved "https://registry.yarnpkg.com/@playkit-js/kaltura-player-js/-/kaltura-player-js-3.17.10.tgz#bb7d0151a2c3879d497e11d52a386166ace3b9cb"
integrity sha512-vJQ0onQN6Kky8TmBXYsWHcWM/T9811bMxDZgeDvwaRD40pzaPOiUi4aryKXTd1i7Q+tDRpbhuKoUtWqSUXL6WA==
"@playkit-js/[email protected].12-canary.0-d07f1c5":
version "3.17.12-canary.0-d07f1c5"
resolved "https://registry.yarnpkg.com/@playkit-js/kaltura-player-js/-/kaltura-player-js-3.17.12-canary.0-d07f1c5.tgz#298a5cbb8c19525a3af4567a194fb26553f7d2f5"
integrity sha512-5kNulxLZI9kQHIDHKuLd6dfOQYd2pF6UBdzxV0bsPQN6ZF52yVrzpRJ/KJEftTSBAcLIG/dGdqhqFPzFR+MH0g==
dependencies:
"@playkit-js/playkit-js" "0.84.6"
"@playkit-js/playkit-js-dash" "1.36.3"
"@playkit-js/playkit-js" "0.84.7-canary.0-cb0ba18"
"@playkit-js/playkit-js-dash" "1.37.0-canary.0-f849d47"
"@playkit-js/playkit-js-hls" "1.32.11"
"@playkit-js/playkit-js-providers" "2.40.4"
"@playkit-js/playkit-js-ui" "0.78.1"
"@playkit-js/playkit-js-ui" "0.78.3-canary.0-dbecd05"
hls.js "1.4.11"
shaka-player "4.7.0"

Expand All @@ -1318,10 +1318,10 @@
"@playkit-js/playkit-js-ui" "^0.77.3"
"@playkit-js/ui-managers" "^1.3.11"

"@playkit-js/playkit-js-dash@1.36.3":
version "1.36.3"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js-dash/-/playkit-js-dash-1.36.3.tgz#1d0490646d851db704fb899acba8ba14bd320e7b"
integrity sha512-kYzyVdXqIXQd/TyzDwLvaN2tvDhOcaT1u6uoZsRwBQXmm1hKwoBWHnWuUiFoE2AdVZzvi0CFsC4WqMFPKF5o8Q==
"@playkit-js/playkit-js-dash@1.37.0-canary.0-f849d47":
version "1.37.0-canary.0-f849d47"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js-dash/-/playkit-js-dash-1.37.0-canary.0-f849d47.tgz#2ad4a4f96574707658a4854ac621e33df3663c90"
integrity sha512-ZULy7Sfq14VF2Pf7ey4VzWsuYsT8kTSZq5sBzxNnGiYF0Af++4fv4W54Kta91gqWFtOrHEG6Wz3mggHp19UCXg==

"@playkit-js/[email protected]":
version "1.1.0-canary.0-60c49dc"
Expand Down Expand Up @@ -1351,10 +1351,10 @@
react-redux "7.2.1"
redux "4.0.5"

"@playkit-js/[email protected].1":
version "0.78.1"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js-ui/-/playkit-js-ui-0.78.1.tgz#1de4920b87a19355b43657e30f51c322abbae6f3"
integrity sha512-yYs/iyiyusviHibOhAFKV47XZYlzxhfy97sbaChFAQyEnA6kkmOhiljGbCEqwBYYd5XgYNevZaac0igTxySYJw==
"@playkit-js/[email protected].3-canary.0-dbecd05":
version "0.78.3-canary.0-dbecd05"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js-ui/-/playkit-js-ui-0.78.3-canary.0-dbecd05.tgz#0cc229127251c2f473a0cc1c3b1ac864778bd1bb"
integrity sha512-R1RSPYREbvyPhnh9Lmtni3s7ylY5fUyz5vzouuJu+GImQ/MYV/78WB3dfJyzbeD+jMI0DAs2h0KsC86v59KKGA==
dependencies:
preact "10.4.6"
preact-i18n "2.0.0-preactx.2"
Expand All @@ -1371,7 +1371,15 @@
react-redux "^7.2.0"
redux "^4.0.5"

"@playkit-js/[email protected]", "@playkit-js/playkit-js@^0.84.6":
"@playkit-js/[email protected]":
version "0.84.7-canary.0-cb0ba18"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.84.7-canary.0-cb0ba18.tgz#0dffea3400ebf9a1cc0598d90fdd8c22d3c90bb9"
integrity sha512-mKszBVI5an6pyGunP6e7e6YBB4FPgpOeF0Yr6P/kkWeLbZ6X4reDu1YNsdtdhpSaFl9X7Ab+eXdcn1sYyu2cUA==
dependencies:
js-logger "^1.6.0"
ua-parser-js "^1.0.36"

"@playkit-js/playkit-js@^0.84.6":
version "0.84.6"
resolved "https://registry.yarnpkg.com/@playkit-js/playkit-js/-/playkit-js-0.84.6.tgz#1187d142b030794693dc2547130436e967fbbb69"
integrity sha512-p+0GHJ6pWPAxHaUEe3k12zPvkFhdreeAsuZ7p5jdGcqMncq1zYlTU9GjejTqf7fMPNerxKYbPtp7beB+5x+RmA==
Expand Down

0 comments on commit 228ea0c

Please sign in to comment.