-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add analytics service and trackEvent action.
- Loading branch information
Dan Ziv
authored
Jun 5, 2018
1 parent
28eda39
commit 8660b76
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
src/k-provider/ovp/services/analytics/analytics-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
test/src/k-provider/ovp/services/analytics-service.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters