Skip to content

Commit

Permalink
fix(usage-stats): update usage stats keys, test cases and flag to log…
Browse files Browse the repository at this point in the history
… or not
  • Loading branch information
sanyamjain65 authored and softvar committed Jun 10, 2021
1 parent b75d7f9 commit c142e7d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 62 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.17.2] - 2021-06-10

### Changed

- Update name of usage metrics keys. Start sending `_l` flag to notify VWO server whether to log or not.


## [1.17.1] - 2021-05-27

Expand Down
22 changes: 13 additions & 9 deletions dist/vwo-javascript-sdk.js

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

2 changes: 1 addition & 1 deletion dist/vwo-javascript-sdk.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/vwo-javascript-sdk.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vwo-javascript-sdk.min.js.map

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions lib/services/UsageStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class UsageStats {
* @param {Object} config config passed at the time of instantiation.
*/
collectUsageStats(config) {
this.data['is_eb'] = Number(!!config.batchEvents);
this.data['is_i'] = Number(!!config.integrations);
this.data['is_ss'] = Number(!!config.userStorageService);
this.data['is_cl'] = Number(!(config.logger instanceof LogManager));
this.data['is_ll'] = Number(config.logging && config.logging.level);
this.data['tru'] = Number(config.shouldTrackReturningUser);
this.data['eb'] = Number(!!config.batchEvents);
this.data['ig'] = Number(!!config.integrations);
this.data['ss'] = Number(!!config.userStorageService);
this.data['cl'] = Number(!(config.logger instanceof LogManager));
this.data['ll'] = Number(config.logging && config.logging.level);
this.data['tr'] = Number(config.shouldTrackReturningUser);
this.data['gt'] = Number(!!config.goalTypeToTrack);
this.data['poll'] = Number(!!config.pollingInterval);
this.data['pi'] = Number(!!config.pollingInterval);

Object.keys(this.data).forEach(function(key) {
if (!this.data[key]) {
Expand All @@ -47,6 +47,9 @@ class UsageStats {
* @returns collected usage stats data
*/
getUsageStats() {
if (Object.keys(this.data).length > 0) {
this.data['_l'] = 1;
}
return this.data;
}
}
Expand Down
91 changes: 49 additions & 42 deletions test/services/UsageStats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ describe('UsageStats', () => {
logging: logger
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBeUndefined();
});

it('when vwo is launched along with userStorageService config', () => {
Expand All @@ -57,13 +58,14 @@ describe('UsageStats', () => {
userStorageService
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBeUndefined();
});

it('when vwo is launched along with integrations config', () => {
Expand All @@ -78,13 +80,14 @@ describe('UsageStats', () => {
}
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBeUndefined();
});

it('when vwo is launched along with shouldTrackReturningUser as true config', () => {
Expand All @@ -100,13 +103,14 @@ describe('UsageStats', () => {
shouldTrackReturningUser: true
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBeUndefined();
});

it('when vwo is launched along with goalTypeToTrack config', () => {
Expand All @@ -123,13 +127,14 @@ describe('UsageStats', () => {
goalTypeToTrack: GoalTypeEnum.CUSTOM
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBeUndefined();
});

it('when vwo is launched along with polling config', done => {
Expand All @@ -151,13 +156,14 @@ describe('UsageStats', () => {
sdkKey: 'po87170ad94079aa190bc7c9b85d26mm'
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBeUndefined();
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBeUndefined();

done();
});
Expand Down Expand Up @@ -185,13 +191,14 @@ describe('UsageStats', () => {
}
});

expect(vwoClientInstance.usageStats.getUsageStats()['is_ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_i']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tru']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ss']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['cl']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['_l']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['ig']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['tr']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['gt']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['poll']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['is_eb']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['pi']).toBe(1);
expect(vwoClientInstance.usageStats.getUsageStats()['eb']).toBe(1);

done();
});
Expand Down

0 comments on commit c142e7d

Please sign in to comment.