@playkit-js/playkit-js-kava 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playkit-js/playkit-js-kava",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "main": "dist/playkit-kava.js",
5
5
  "scripts": {
6
6
  "disabled-preinstall": "npx --yes --prefer-online --registry=https://npm.pkg.github.com --package @kaltura/kaltura-tools@latest kaltura-tools check --root=.",
package/src/kava-model.ts CHANGED
@@ -75,6 +75,8 @@ class KavaModel {
75
75
  public getV2ToV7Redirect!: () => any;
76
76
  public getNumFailedAnalyticReports!: () => number;
77
77
  public getLiveStreamType!: () => number | undefined;
78
+ public getPfPageViewId!: () => string | undefined;
79
+ public getPfSessionId!: () => string | undefined;
78
80
 
79
81
  constructor(model?: object) {
80
82
  if (model) {
@@ -419,11 +421,27 @@ class KavaModel {
419
421
  public getModel(eventObj: KavaEvent, eventBucketName: EventBucketName = EventBucketName.PlayerEvents, eventPayload?: any): any {
420
422
  switch (eventBucketName) {
421
423
  case EventBucketName.PlayerEvents:
422
- return getEventModel(eventObj, this);
424
+ const model = getEventModel(eventObj, this);
425
+ return this._addPathFactoryIds(model);
423
426
  case EventBucketName.ApplicationEvents:
424
427
  return getApplicationEventsModel(eventObj, this, eventPayload);
425
428
  }
426
429
  }
430
+
431
+ private _addPathFactoryIds(model: any): any {
432
+ if (!model) {
433
+ return model;
434
+ }
435
+ const pfPageViewId = this.getPfPageViewId();
436
+ if (pfPageViewId) {
437
+ model.pfPageViewId = pfPageViewId;
438
+ }
439
+ const pfSessionId = this.getPfSessionId();
440
+ if (pfSessionId) {
441
+ model.pfSessionId = pfSessionId;
442
+ }
443
+ return model;
444
+ }
427
445
  }
428
446
 
429
447
  enum SoundMode {
package/src/kava.ts CHANGED
@@ -894,6 +894,8 @@ class Kava extends BasePlugin {
894
894
  this._model.getV2ToV7Redirect = (): boolean => this.player.isV2ToV7Redirected;
895
895
  this._model.getNumFailedAnalyticReports = (): number => this._logFailedLiveEvents.getNumFailedAnalyticReports(this.config.entryId);
896
896
  this._model.getLiveStreamType = (): number | undefined => this._getLiveStreamType();
897
+ this._model.getPfPageViewId = (): string | undefined => this.config.pfPageViewId;
898
+ this._model.getPfSessionId = (): string | undefined => this.config.pfSessionId;
897
899
  }
898
900
 
899
901
  private _getApplication(playerEvent = true): string {
@@ -50,6 +50,8 @@ export type KavaConfigObject = {
50
50
  hostingKalturaApplicationVersion?: string,
51
51
  logLiveAnalyticsFailures?: boolean,
52
52
  numOfLoggedFailedEvents?: number,
53
+ pfPageViewId?: string,
54
+ pfSessionId?: string,
53
55
  };
54
56
 
55
57
  /**
@@ -1,4 +1,5 @@
1
1
  import {KavaModel} from '../../src/kava-model';
2
+ import {EventBucketName} from '../../src/enums/event-bucket-name';
2
3
 
3
4
  const ab = 3,
4
5
  avb = 5,
@@ -98,6 +99,8 @@ describe('KavaModel', () => {
98
99
  model.getHostingKalturaApplication = () => hostingApp;
99
100
  model.getHostingKalturaApplicationVersion = () => av;
100
101
  model.getPlayerSkin = () => ps;
102
+ model.getPfPageViewId = () => undefined;
103
+ model.getPfSessionId = () => undefined;
101
104
  });
102
105
 
103
106
  it('should update the model', function () {
@@ -143,4 +146,48 @@ describe('KavaModel', () => {
143
146
  playerSkin: ps
144
147
  });
145
148
  });
149
+
150
+ describe('PathFactory ids', () => {
151
+ const applicationEvent = {
152
+ type: 'MY_APP_EVENT',
153
+ index: 100,
154
+ getEventModel: () => ({eventType: 1, applicationFeature: 'feature'})
155
+ };
156
+
157
+ it('should not add pfPageViewId and pfSessionId when values are undefined', () => {
158
+ const resultModel = model.getModel(eventModel.MY_EVENT);
159
+ resultModel.should.not.have.any.keys('pfPageViewId', 'pfSessionId');
160
+ });
161
+
162
+ it('should not add pfPageViewId and pfSessionId when values are empty strings', () => {
163
+ model.getPfPageViewId = () => '';
164
+ model.getPfSessionId = () => '';
165
+ const resultModel = model.getModel(eventModel.MY_EVENT);
166
+ resultModel.should.not.have.any.keys('pfPageViewId', 'pfSessionId');
167
+ });
168
+
169
+ it('should add both ids to player events', () => {
170
+ model.getPfPageViewId = () => 'pv-12345';
171
+ model.getPfSessionId = () => 'sess-67890';
172
+ const resultModel = model.getModel(eventModel.MY_EVENT);
173
+ resultModel.pfPageViewId.should.equal('pv-12345');
174
+ resultModel.pfSessionId.should.equal('sess-67890');
175
+ });
176
+
177
+ it('should not add ids to application events', () => {
178
+ model.getPfPageViewId = () => 'pv-12345';
179
+ model.getPfSessionId = () => 'sess-67890';
180
+ const resultModel = model.getModel(applicationEvent, EventBucketName.ApplicationEvents, {});
181
+ resultModel.should.not.have.property('pfPageViewId');
182
+ resultModel.should.not.have.property('pfSessionId');
183
+ });
184
+
185
+ it('should add only the id that is defined', () => {
186
+ model.getPfPageViewId = () => 'pv-12345';
187
+ model.getPfSessionId = () => undefined;
188
+ const resultModel = model.getModel(eventModel.MY_EVENT);
189
+ resultModel.pfPageViewId.should.equal('pv-12345');
190
+ resultModel.should.not.have.property('pfSessionId');
191
+ });
192
+ });
146
193
  });
@@ -224,6 +224,44 @@ describe('KavaPlugin', function () {
224
224
  player.play();
225
225
  });
226
226
 
227
+ it('should send pfPageViewId and pfSessionId in events when set in setup', done => {
228
+ sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
229
+ if (params.eventType === KavaEventModel.IMPRESSION.index) {
230
+ try {
231
+ params.pfPageViewId.should.equal('pv-12345');
232
+ params.pfSessionId.should.equal('sess-67890');
233
+ done();
234
+ } catch (e) {
235
+ done(e);
236
+ }
237
+ }
238
+ return new RequestBuilder();
239
+ });
240
+ const configCopy = JSON.parse(JSON.stringify(config));
241
+ configCopy.plugins.kava.pfPageViewId = 'pv-12345';
242
+ configCopy.plugins.kava.pfSessionId = 'sess-67890';
243
+ setupPlayer(configCopy);
244
+ kava = getKavaPlugin();
245
+ player.play();
246
+ });
247
+
248
+ it('should not send pfPageViewId and pfSessionId in events when not set in setup', done => {
249
+ sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params) => {
250
+ if (params.eventType === KavaEventModel.IMPRESSION.index) {
251
+ try {
252
+ params.should.not.have.any.keys('pfPageViewId', 'pfSessionId');
253
+ done();
254
+ } catch (e) {
255
+ done(e);
256
+ }
257
+ }
258
+ return new RequestBuilder();
259
+ });
260
+ setupPlayer(config);
261
+ kava = getKavaPlugin();
262
+ player.play();
263
+ });
264
+
227
265
  it('should send IMPRESSION event with playerJSLoadTime', done => {
228
266
  sandbox.stub(window.performance, 'getEntriesByType').callsFake(() => {
229
267
  return [