Skip to content

Commit

Permalink
feat(FEC-10615): support sending Kava beacons as POST (#86)
Browse files Browse the repository at this point in the history
add `requestMethod` config (`GET` by default) and send it to `OVPAnalyticsService.trackEvent`

Depends on kaltura/playkit-js-providers#125

Solves FEC-10615
  • Loading branch information
yairans authored Oct 29, 2020
1 parent 4c4e5cd commit 5a9452c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/configuration-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Type: [Object][41]
### Properties

- `serviceUrl` **[string][42]?** The Kaltura API server.
- `requestMethod` **[string][42]?** The http method to be used for sending the beacons, GET or POST, the default is GET.
- `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.
Expand All @@ -68,6 +69,7 @@ Type: [Object][41]
// Default config
{
serviceUrl: '//analytics.kaltura.com/api_v3/index.php',
requestMethod: 'GET',
viewEventCountdown: 30,
resetSessionCountdown: 30,
dvrThreshold: 120,
Expand Down
2 changes: 2 additions & 0 deletions flow-typed/types/kava-http-method-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @flow
declare type KavaHttpMethodType = {[stream: string]: string};
7 changes: 7 additions & 0 deletions src/http-method-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow
const HttpMethodType: KavaHttpMethodType = {
GET: 'GET',
POST: 'POST'
};

export {HttpMethodType};
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const NAME = __NAME__;

export {Kava as Plugin};
export {KavaEventType as EventType} from './kava-event-model';
export {HttpMethodType} from './http-method-type';
export {VERSION, NAME};

const pluginName: string = 'kava';
Expand Down
4 changes: 3 additions & 1 deletion src/kava.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {KavaEventModel, KavaEventType} from './kava-event-model';
import {KavaRateHandler} from './kava-rate-handler';
import {KavaTimer} from './kava-timer';
import {ErrorPosition, KavaModel, SoundMode, TabMode, ScreenMode} from './kava-model';
import {HttpMethodType} from './http-method-type';

const {Error: PKError, FakeEvent, Utils} = core;
const DIVIDER: number = 1024;
Expand Down Expand Up @@ -49,6 +50,7 @@ class Kava extends BasePlugin {
*/
static defaultConfig: Object = {
serviceUrl: `${Utils.Http.protocol}//analytics.kaltura.com/api_v3/index.php`,
requestMethod: HttpMethodType.GET,
viewEventCountdown: 10,
resetSessionCountdown: 30,
dvrThreshold: 120,
Expand Down Expand Up @@ -206,7 +208,7 @@ class Kava extends BasePlugin {
*/
sendAnalytics(model: Object): Promise<*> {
return new Promise((resolve, reject) => {
OVPAnalyticsService.trackEvent(this.config.serviceUrl, model)
OVPAnalyticsService.trackEvent(this.config.serviceUrl, model, this.config.requestMethod)
.doHttpRequest()
.then(
response => {
Expand Down
22 changes: 21 additions & 1 deletion test/src/kava.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as TestUtils from './utils/test-utils';
import {OVPAnalyticsService, RequestBuilder} from 'playkit-js-providers/dist/playkit-analytics-service';
import {KavaEventModel} from '../../src/kava-event-model';
import {ErrorPosition, SoundMode, TabMode, ScreenMode} from '../../src/kava-model';
import {HttpMethodType} from '../../src/http-method-type';

const {FakeEvent, CustomEventType} = core;
const targetId = 'player-placeholder_kava.spec';
Expand Down Expand Up @@ -885,7 +886,11 @@ describe('KavaPlugin', function () {
})
);
player.dispatchEvent(
new FakeEvent(CustomEventType.FRAG_LOADED, {miliSeconds: FRAG2_DOWNLOAD_TIME, bytes: FRAG2_BYTES, url: 'http://www.somesite.com/movie2.ts'})
new FakeEvent(CustomEventType.FRAG_LOADED, {
miliSeconds: FRAG2_DOWNLOAD_TIME,
bytes: FRAG2_BYTES,
url: 'http://www.somesite.com/movie2.ts'
})
);
let performanceOverserList = {};
performanceOverserList.getEntries = () => {
Expand Down Expand Up @@ -1068,6 +1073,21 @@ describe('KavaPlugin', function () {
kava = getKavaPlugin();
kava._onPlaybackRateChanged();
});

it('should send IMPRESSION event as POST', done => {
sandbox.stub(OVPAnalyticsService, 'trackEvent').callsFake((serviceUrl, params, requestMethod) => {
try {
requestMethod.should.be.equal(HttpMethodType.POST);
done();
} catch (e) {
done(e);
}
});
config.plugins.kava.requestMethod = HttpMethodType.POST;
setupPlayer(config);
kava = getKavaPlugin();
player.play();
});
});

describe('Server Response', () => {
Expand Down

0 comments on commit 5a9452c

Please sign in to comment.