Skip to content

Commit

Permalink
feat: analytics service (#48)
Browse files Browse the repository at this point in the history
Add analytics service and trackEvent action.
  • Loading branch information
Dan Ziv authored Jun 5, 2018
1 parent 28eda39 commit 8660b76
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dist/playkit-analytics-service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/playkit-analytics-service.js.map

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/k-provider/ovp/services/analytics/analytics-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@flow
import OVPService from '../ovp-service'
import RequestBuilder from '../../../../util/request-builder'
import OVPConfiguration from '../../config'
import {param} from '../../../../util/param'

const SERVICE_NAME: string = "analytics";

export default class OVPAnalyticsService extends OVPService {

/**
* Creates an instance of RequestBuilder for analytics.trackEvent
* @function trackEvent
* @param {string} serviceUrl - The service base url
* @param {Object} params - The event params
* @returns {RequestBuilder} - The request builder
* @static
*/
static trackEvent(serviceUrl: string, params: Object): RequestBuilder {
const ovpParams = OVPConfiguration.get();
const serviceParams = {};
Object.assign(serviceParams, ovpParams.serviceParams, params);
const request = new RequestBuilder();
request.service = SERVICE_NAME;
request.action = "trackEvent";
request.method = "GET";
request.tag = "analytics-trackEvent";
request.params = serviceParams;
request.url = serviceUrl + '?service=' + request.service + '&action=' + request.action + '&' + param(request.params);
return request;
}
}
18 changes: 18 additions & 0 deletions src/k-provider/ovp/services/analytics/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow
import RequestBuilder from '../../../../util/request-builder'
import OVPConfiguration from '../../config'
import OVPAnalyticsService from './analytics-service'

declare var __VERSION__: string;
declare var __NAME__: string;

const NAME = __NAME__ + '-analytics-service';
const VERSION = __VERSION__;

export {
OVPAnalyticsService,
OVPConfiguration,
RequestBuilder,
NAME,
VERSION
};
25 changes: 25 additions & 0 deletions test/src/k-provider/ovp/services/analytics-service.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import OVPAnalyticsService from '../../../../../src/k-provider/ovp/services/analytics/analytics-service'
import RequestBuilder from '../../../../../src/util/request-builder'
import OVPConfiguration from '../../../../../src/k-provider/ovp/config'
import {param} from '../../../../../src/util/param'

describe('analytics service - trackEvent', function () {
const ovpParams = OVPConfiguration.get();
const eventParams = {
param1: 'param1',
param2: 'param2',
param3: 'param3'
};

it('should be proper values', function () {
const serviceUrl = 'http://my/url';
const request = OVPAnalyticsService.trackEvent(serviceUrl, eventParams);
(request instanceof RequestBuilder).should.be.true;
request.service.should.be.equal('analytics');
request.action.should.be.equal('trackEvent');
request.method.should.be.equal('GET');
request.url.should.be.equal(serviceUrl + '?service=' + request.service + '&action=' + request.action + '&' + param(request.params));
request.tag.should.be.equal('analytics-trackEvent');
request.params.should.deep.equal(Object.assign({}, ovpParams.serviceParams, eventParams));
});
});
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Object.assign(providersConfig.output, {
});

Object.assign(servicesConfig.entry, {
"analytics": "k-provider/ovp/services/analytics/index.js",
"stats": "k-provider/ovp/services/stats/index.js",
"bookmark": "k-provider/ott/services/bookmark/index.js"
});
Expand Down

0 comments on commit 8660b76

Please sign in to comment.