From cda7469ea36e2c39bc4322517a81e86aa82115b5 Mon Sep 17 00:00:00 2001 From: Yuvalke <48407737+Yuvalke@users.noreply.github.com> Date: Thu, 25 Jul 2019 10:21:22 +0300 Subject: [PATCH] fix(FEC-9247): add userId to kava reports (#45) add userId to report from kava config --- docs/configuration-api.md | 143 +++++++++++++++++--------------- flow-typed/types/kava-config.js | 4 +- src/kava-event-model.js | 3 + src/kava-model.js | 1 + src/kava.js | 1 + test/src/kava-model.spec.js | 7 +- test/src/kava.spec.js | 75 +++++++++-------- 7 files changed, 130 insertions(+), 104 deletions(-) diff --git a/docs/configuration-api.md b/docs/configuration-api.md index 5f31c111..e717bc3a 100644 --- a/docs/configuration-api.md +++ b/docs/configuration-api.md @@ -32,32 +32,34 @@ - [Parameters][28] - [destroy][29] - [reset][30] - - [getEventModel][31] - - [Parameters][32] - - [Examples][33] - - [EventType][34] - - [sendAnalytics][35] - - [Parameters][36] - - [Examples][37] - - [defaultConfig][38] - - [isValid][39] + - [loadMedia][31] + - [getEventModel][32] + - [Parameters][33] + - [Examples][34] + - [EventType][35] + - [sendAnalytics][36] + - [Parameters][37] + - [Examples][38] + - [defaultConfig][39] + - [isValid][40] ## KavaConfigObject -Type: [Object][40] +Type: [Object][41] ### Properties -- `serviceUrl` **[string][41]?** The Kaltura API server. -- `viewEventCountdown` **[number][42]?** The interval in seconds that VIEW event will be sent. -- `resetSessionCountdown` **[number][42]?** The interval in seconds that Kava session will be reset. -- `dvrThreshold` **[number][42]?** Threshold in seconds from the live edge. -- `applicationVersion` **[string][41]?** Used to send the application version from which the user is playing the entry. -- `playbackContext` **[string][41]?** Used to send the id of the category from which the user is playing the entry. -- `tamperAnalyticsHandler` **[Function][43]?** An optional handler to implement. Can be used to manipulate the model data before analytics event sent, or to cancel a certain analytics request. -- `customVar1` **[Object][40]?** Custom objects field. -- `customVar2` **[Object][40]?** Custom objects field. -- `customVar3` **[Object][40]?** Custom objects field. +- `serviceUrl` **[string][42]?** The Kaltura API server. +- `viewEventCountdown` **[number][43]?** The interval in seconds that VIEW event will be sent. +- `resetSessionCountdown` **[number][43]?** The interval in seconds that Kava session will be reset. +- `dvrThreshold` **[number][43]?** Threshold in seconds from the live edge. +- `applicationVersion` **[string][42]?** Used to send the application version from which the user is playing the entry. +- `playbackContext` **[string][42]?** Used to send the id of the category from which the user is playing the entry. +- `tamperAnalyticsHandler` **[Function][44]?** An optional handler to implement. Can be used to manipulate the model data before analytics event sent, or to cancel a certain analytics request. +- `customVar1` **[Object][41]?** Custom objects field. +- `customVar2` **[Object][41]?** Custom objects field. +- `customVar3` **[Object][41]?** Custom objects field. +- `userId` **[string][42]?** custom user id . ### Examples @@ -77,7 +79,7 @@ Type: [Object][40] #### Parameters -- `model` **[Object][40]** Event model +- `model` **[Object][41]** Event model #### Examples @@ -92,85 +94,85 @@ tamperAnalyticsHandler: function (model) { } ``` -Returns **[boolean][44]** Should send the request or not. +Returns **[boolean][45]** Should send the request or not. ## KavaEventType ### VIEW -Type: [string][41] +Type: [string][42] ### IMPRESSION -Type: [string][41] +Type: [string][42] ### PLAY_REQUEST -Type: [string][41] +Type: [string][42] ### PLAY -Type: [string][41] +Type: [string][42] ### RESUME -Type: [string][41] +Type: [string][42] ### PAUSE -Type: [string][41] +Type: [string][42] ### BUFFER_START -Type: [string][41] +Type: [string][42] ### BUFFER_END -Type: [string][41] +Type: [string][42] ### REPLAY -Type: [string][41] +Type: [string][42] ### SEEK -Type: [string][41] +Type: [string][42] ### PLAY_REACHED_25_PERCENT -Type: [string][41] +Type: [string][42] ### PLAY_REACHED_50_PERCENT -Type: [string][41] +Type: [string][42] ### PLAY_REACHED_75_PERCENT -Type: [string][41] +Type: [string][42] ### PLAY_REACHED_100_PERCENT -Type: [string][41] +Type: [string][42] ### SOURCE_SELECTED -Type: [string][41] +Type: [string][42] ### AUDIO_SELECTED -Type: [string][41] +Type: [string][42] ### FLAVOR_SWITCH -Type: [string][41] +Type: [string][42] ### CAPTIONS -Type: [string][41] +Type: [string][42] ### ERROR -Type: [string][41] +Type: [string][42] ## Kava @@ -178,9 +180,9 @@ Kaltura Advanced Analytics plugin. ### Parameters -- `name` **[string][41]** The plugin name. +- `name` **[string][42]** The plugin name. - `player` **Player** The player instance. -- `config` **[KavaConfigObject][45]** The plugin config. +- `config` **[KavaConfigObject][46]** The plugin config. ### destroy @@ -194,13 +196,19 @@ Reset the plugin. Returns **void** +### loadMedia + +loadMedia of the plugin. + +Returns **void** + ### getEventModel Gets the model object for a certain event. #### Parameters -- `event` **[string][41]** Event name. +- `event` **[string][42]** Event name. #### Examples @@ -210,11 +218,11 @@ const viewModel = kava.getEventModel(kava.EventType.VIEW); kava.sendAnalytics(viewModel); ``` -Returns **[Object][40]** Model object. +Returns **[Object][41]** Model object. ### EventType -Returns **[KavaEventType][46]** The kava events list. +Returns **[KavaEventType][47]** The kava events list. ### sendAnalytics @@ -222,7 +230,7 @@ Sends KAVA analytics event to analytics service. #### Parameters -- `model` **[Object][40]** Event model. +- `model` **[Object][41]** Event model. #### Examples @@ -236,17 +244,17 @@ player.plugins.kava.sendAnalytics({...}) }); ``` -Returns **[Promise][47]** Promise to indicate request succeed or failed. +Returns **[Promise][48]** Promise to indicate request succeed or failed. ### defaultConfig Default config of the plugin. -Type: [Object][40] +Type: [Object][41] ### isValid -Returns **[boolean][44]** Whether the plugin is valid in the current environment. +Returns **[boolean][45]** Whether the plugin is valid in the current environment. [1]: #kavaconfigobject [2]: #properties @@ -278,20 +286,21 @@ Returns **[boolean][44]** Whether the plugin is valid in the current environment [28]: #parameters-1 [29]: #destroy [30]: #reset -[31]: #geteventmodel -[32]: #parameters-2 -[33]: #examples-2 -[34]: #eventtype -[35]: #sendanalytics -[36]: #parameters-3 -[37]: #examples-3 -[38]: #defaultconfig -[39]: #isvalid -[40]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[42]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number -[43]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function -[44]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean -[45]: #kavaconfigobject -[46]: #kavaeventtype -[47]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise +[31]: #loadmedia +[32]: #geteventmodel +[33]: #parameters-2 +[34]: #examples-2 +[35]: #eventtype +[36]: #sendanalytics +[37]: #parameters-3 +[38]: #examples-3 +[39]: #defaultconfig +[40]: #isvalid +[41]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[42]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[43]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number +[44]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[45]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean +[46]: #kavaconfigobject +[47]: #kavaeventtype +[48]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise diff --git a/flow-typed/types/kava-config.js b/flow-typed/types/kava-config.js index 5d678547..abe0e2a3 100644 --- a/flow-typed/types/kava-config.js +++ b/flow-typed/types/kava-config.js @@ -12,6 +12,7 @@ * @property {Object} [customVar1] - Custom objects field. * @property {Object} [customVar2] - Custom objects field. * @property {Object} [customVar3] - Custom objects field. + * @property {string} [userId] - custom user id . * @example * // Default config * { @@ -25,6 +26,7 @@ */ type _KavaConfigObject = { serviceUrl?: string, + tamperAnalyticsHandler?: Function, viewEventCountdown?: number, resetSessionCountdown?: number, dvrThreshold?: number, @@ -33,7 +35,7 @@ type _KavaConfigObject = { customVar3?: Object, applicationVersion?: string, playbackContext?: string, - tamperAnalyticsHandler?: Function + userId?: string }; /** diff --git a/src/kava-event-model.js b/src/kava-event-model.js index 3e1dbd4b..32ade4cf 100644 --- a/src/kava-event-model.js +++ b/src/kava-event-model.js @@ -306,6 +306,9 @@ export function getEventModel(eventObj: KavaEvent, model: KavaModel): Object { if (model.getApplicationVersion()) { commonModel.applicationVersion = model.getApplicationVersion(); } + if (model.getUserId()) { + commonModel.userId = model.getUserId(); + } const eventModel = eventObj.getEventModel(model); return Object.assign(eventModel, commonModel); } diff --git a/src/kava-model.js b/src/kava-model.js index 751e435f..771b3ba5 100644 --- a/src/kava-model.js +++ b/src/kava-model.js @@ -52,6 +52,7 @@ class KavaModel { getPlaybackType: Function; getPlaybackContext: Function; getApplicationVersion: Function; + getUserId: Function; getCanPlayTime: Function; constructor(model?: Object) { diff --git a/src/kava.js b/src/kava.js index 28346258..38399942 100644 --- a/src/kava.js +++ b/src/kava.js @@ -680,6 +680,7 @@ class Kava extends BasePlugin { this._model.getPlaybackType = () => this._getPlaybackType(); this._model.getPlaybackContext = () => this.config.playbackContext; this._model.getApplicationVersion = () => this.config.applicationVersion; + this._model.getUserId = () => this.config.userId; } _getPosition(): number { diff --git a/test/src/kava-model.spec.js b/test/src/kava-model.spec.js index eff53d0c..2fbaa010 100644 --- a/test/src/kava-model.spec.js +++ b/test/src/kava-model.spec.js @@ -28,7 +28,8 @@ const ab = 3, jt = 1213, tp = '12', pc = 'pc', - av = 'av'; + av = 'av', + usi = '1234'; describe('KavaModel', () => { let model; @@ -79,6 +80,7 @@ describe('KavaModel', () => { model.getPlaybackType = () => pback; model.getPlaybackContext = () => pc; model.getApplicationVersion = () => av; + model.getUserId = () => usi; }); it('should update the model', function() { @@ -111,7 +113,8 @@ describe('KavaModel', () => { sessionStartTime: sst, customVar2: cv2, playbackContext: pc, - applicationVersion: av + applicationVersion: av, + userId: usi }); }); }); diff --git a/test/src/kava.spec.js b/test/src/kava.spec.js index 7bdf9418..3148d650 100644 --- a/test/src/kava.spec.js +++ b/test/src/kava.spec.js @@ -108,7 +108,8 @@ describe('KavaPlugin', function() { playlistId: '12345678', entryType: 'Vod', sessionId: 'c15be273-0f1b-10a3-4fc9-d7a53eebee85:b66abd37-e2e2-a22e-86ac-7859592e754b', - ks: 'Njk0ZmI4MzBiOTJiMGZhN2NmNTAwYWQyZGM2M2Y0YjkxMGRiZGI3MXwxMDkxOzEwOTE7MTUxNzkyMjgxMzswOzE1MTc4MzY0MTMuMTM4OzA7dmlldzoqLHdpZGdldDoxOzs=' + ks: 'Njk0ZmI4MzBiOTJiMGZhN2NmNTAwYWQyZGM2M2Y0YjkxMGRiZGI3MXwxMDkxOzEwOTE7MTUxNzkyMjgxMzswOzE1MTc4MzY0MTMuMTM4OzA7dmlldzoqLHdpZGdldDoxOzs=', + userId: '1234' } }, session: { @@ -148,6 +149,7 @@ describe('KavaPlugin', function() { params.clientVer.should.equal(config.plugins.kava.playerVersion); params.clientTag.should.equal('html5:v' + config.plugins.kava.playerVersion); params.position.should.exist; + params.userId.should.equal(config.plugins.kava.userId); } it('should send IMPRESSION event', done => { @@ -480,40 +482,45 @@ describe('KavaPlugin', function() { sandbox.stub(window.navigator.connection, 'effectiveType').value('2g'); sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => { - if (params.eventType === KavaEventModel.VIEW.index) { - validateCommonParams(params, KavaEventModel.VIEW.index); - params.should.have.all.keys( - 'audioLanguage', - 'bufferTime', - 'bufferTimeSum', - 'actualBitrate', - 'averageBitrate', - 'captionsLanguage', - 'clientTag', - 'clientVer', - 'deliveryType', - 'droppedFramesRatio', - 'entryId', - 'eventIndex', - 'eventType', - 'ks', - 'partnerId', - 'playTimeSum', - 'playbackType', - 'playlistId', - 'position', - 'referrer', - 'sessionId', - 'soundMode', - 'tabMode', - 'networkConnectionType' - ); - params.networkConnectionType.should.equal('2g'); - params.tabMode.should.equal(TabMode.TAB_FOCUSED); - params.soundMode.should.equal(SoundMode.SOUND_ON); - done(); + try { + if (params.eventType === KavaEventModel.VIEW.index) { + validateCommonParams(params, KavaEventModel.VIEW.index); + params.should.have.all.keys( + 'audioLanguage', + 'bufferTime', + 'bufferTimeSum', + 'actualBitrate', + 'averageBitrate', + 'captionsLanguage', + 'clientTag', + 'clientVer', + 'deliveryType', + 'droppedFramesRatio', + 'entryId', + 'eventIndex', + 'eventType', + 'ks', + 'partnerId', + 'playTimeSum', + 'playbackType', + 'playlistId', + 'position', + 'referrer', + 'sessionId', + 'soundMode', + 'tabMode', + 'networkConnectionType', + 'userId' + ); + params.networkConnectionType.should.equal('2g'); + params.tabMode.should.equal(TabMode.TAB_FOCUSED); + params.soundMode.should.equal(SoundMode.SOUND_ON); + done(); + } + return new RequestBuilder(); + } catch (err) { + done(err); } - return new RequestBuilder(); }); setupPlayer(config); player.play();