Skip to content

Commit

Permalink
fix(usage-stats): updatee usage stats keys, test cases and flag to lo…
Browse files Browse the repository at this point in the history
…g or not
  • Loading branch information
sanyamjain65 authored and softvar committed Jun 10, 2021
1 parent 172127d commit 6a192dd
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 65 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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-28

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License. -->

<groupId>com.vwo.sdk</groupId>
<artifactId>vwo-java-sdk</artifactId>
<version>1.17.1</version>
<version>1.17.2</version>
<packaging>jar</packaging>

<name>VWO Java Server Side SDK</name>
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/vwo/VWO.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private Builder withSettingFile(String settingFileString) {
*/
public Builder withPollingInterval(Integer pollingInterval) {
this.pollingInterval = pollingInterval;
usageStats.put("poll", 1);
usageStats.put("pi", 1);
return this;
}

Expand All @@ -514,7 +514,7 @@ public Builder withSdkKey(String sdkKey) {
*/
public Builder withUserStorage(Storage.User userStorage) {
this.userStorage = userStorage;
usageStats.put("is_ss", 1);
usageStats.put("ss", 1);
return this;
}

Expand All @@ -537,9 +537,9 @@ public Builder withDevelopmentMode(boolean developmentMode) {
*/
public Builder withCustomLogger(VWOLogger customLogger) {
this.customLogger = customLogger;
usageStats.put("is_cl", 1);
usageStats.put("cl", 1);
if (!VWOLogger.level.equals(VWOEnums.LOGGER_LEVEL.ERROR.value())) {
usageStats.put("is_ll", 1);
usageStats.put("ll", 1);
}

return this;
Expand All @@ -566,20 +566,20 @@ public Builder withGoalTypeToTrack(GoalEnums.GOAL_TYPES value) {
public Builder withShouldTrackReturningUser(boolean value) {
this.shouldTrackReturningUser = value;
if (shouldTrackReturningUser) {
usageStats.put("tru", 1);
usageStats.put("tr", 1);
}
return this;
}

public Builder withBatchEvents(BatchEventData batchEvents) {
this.batchEvents = batchEvents;
usageStats.put("is_eb", 1);
usageStats.put("eb", 1);
return this;
}

public Builder withIntegrations(IntegrationEventListener integrations) {
this.integrations = integrations;
usageStats.put("is_i", 1);
usageStats.put("ig", 1);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vwo/enums/UriEnums.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public enum UriEnums {

PROTOCOL("https"),
SDK_VERSION("1.17.1"),
SDK_VERSION("1.17.2"),
SDK_NAME("java"),
BASE_URL("dev.visualwebsiteoptimizer.com"),
SETTINGS_URL("/server-side/settings"),
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/vwo/services/http/HttpRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ public Builder withEnvironment(String sdkKey) {

public Builder withUsageStats(Map<String, Integer> usageStats) {
this.usageStats = usageStats;
if (!this.usageStats.isEmpty()) {
this.usageStats.put("_l", 1);
}
return this;
}

Expand Down
146 changes: 90 additions & 56 deletions src/test/java/com/vwo/tests/unit/UsageStatsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import com.vwo.enums.VWOEnums;
import com.vwo.logger.VWOLogger;
import com.vwo.models.BatchEventData;
import com.vwo.models.Campaign;
import com.vwo.models.Variation;
import com.vwo.services.batch.FlushInterface;
import com.vwo.services.http.HttpParams;
import com.vwo.services.http.HttpRequestBuilder;
import com.vwo.services.integrations.IntegrationEventListener;
import com.vwo.services.storage.Storage;
import com.vwo.tests.data.Settings;
Expand All @@ -45,28 +49,28 @@ public void withoutConfig() {
public void withStorageServiceOnly() {
VWO vwo = VWO.launch(Settings.AB_TRAFFIC_100_WEIGHT_50_50).withUserStorage(getUSerStorage()).build();
assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertNull(vwo.getUsageStats().get("is_i"));
assertNull(vwo.getUsageStats().get("is_eb"));
assertNull(vwo.getUsageStats().get("is_cl"));
assertNull(vwo.getUsageStats().get("is_ll"));
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertNull(vwo.getUsageStats().get("ig"));
assertNull(vwo.getUsageStats().get("eb"));
assertNull(vwo.getUsageStats().get("cl"));
assertNull(vwo.getUsageStats().get("ll"));
assertNull(vwo.getUsageStats().get("gt"));
assertNull(vwo.getUsageStats().get("tru"));
assertNull(vwo.getUsageStats().get("poll"));
assertNull(vwo.getUsageStats().get("tr"));
assertNull(vwo.getUsageStats().get("pi"));
}

@Test
public void alongWithCustomLogger() {
VWO vwo = VWO.launch(Settings.AB_TRAFFIC_100_WEIGHT_50_50).withUserStorage(getUSerStorage()).withCustomLogger(getCustomLogger()).build();
assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertEquals(vwo.getUsageStats().get("is_cl"), 1);
assertEquals(vwo.getUsageStats().get("is_ll"), 1);
assertNull(vwo.getUsageStats().get("is_i"));
assertNull(vwo.getUsageStats().get("is_eb"));
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertEquals(vwo.getUsageStats().get("cl"), 1);
assertEquals(vwo.getUsageStats().get("ll"), 1);
assertNull(vwo.getUsageStats().get("ig"));
assertNull(vwo.getUsageStats().get("eb"));
assertNull(vwo.getUsageStats().get("gt"));
assertNull(vwo.getUsageStats().get("tru"));
assertNull(vwo.getUsageStats().get("poll"));
assertNull(vwo.getUsageStats().get("tr"));
assertNull(vwo.getUsageStats().get("pi"));
}

@Test
Expand All @@ -77,14 +81,14 @@ public void alongWithGoalTypeToTrack() {
.withGoalTypeToTrack(GoalEnums.GOAL_TYPES.ALL)
.build();
assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertEquals(vwo.getUsageStats().get("is_cl"), 1);
assertEquals(vwo.getUsageStats().get("is_ll"), 1);
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertEquals(vwo.getUsageStats().get("cl"), 1);
assertEquals(vwo.getUsageStats().get("ll"), 1);
assertEquals(vwo.getUsageStats().get("gt"), 1);
assertNull(vwo.getUsageStats().get("is_i"));
assertNull(vwo.getUsageStats().get("is_eb"));
assertNull(vwo.getUsageStats().get("tru"));
assertNull(vwo.getUsageStats().get("poll"));
assertNull(vwo.getUsageStats().get("ig"));
assertNull(vwo.getUsageStats().get("eb"));
assertNull(vwo.getUsageStats().get("tr"));
assertNull(vwo.getUsageStats().get("pi"));
}

@Test
Expand All @@ -97,14 +101,14 @@ public void alongWithPolling() {
.withSdkKey("sdk_key")
.build();
assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertEquals(vwo.getUsageStats().get("is_cl"), 1);
assertEquals(vwo.getUsageStats().get("is_ll"), 1);
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertEquals(vwo.getUsageStats().get("cl"), 1);
assertEquals(vwo.getUsageStats().get("ll"), 1);
assertEquals(vwo.getUsageStats().get("gt"), 1);
assertEquals(vwo.getUsageStats().get("poll"), 1);
assertNull(vwo.getUsageStats().get("is_i"));
assertNull(vwo.getUsageStats().get("is_eb"));
assertNull(vwo.getUsageStats().get("tru"));
assertEquals(vwo.getUsageStats().get("pi"), 1);
assertNull(vwo.getUsageStats().get("ig"));
assertNull(vwo.getUsageStats().get("eb"));
assertNull(vwo.getUsageStats().get("tr"));
}

@Test
Expand All @@ -119,14 +123,14 @@ public void alongWithIntegrations() {
.build();

assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertEquals(vwo.getUsageStats().get("is_cl"), 1);
assertEquals(vwo.getUsageStats().get("is_ll"), 1);
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertEquals(vwo.getUsageStats().get("cl"), 1);
assertEquals(vwo.getUsageStats().get("ll"), 1);
assertEquals(vwo.getUsageStats().get("gt"), 1);
assertEquals(vwo.getUsageStats().get("poll"), 1);
assertEquals(vwo.getUsageStats().get("is_i"), 1);
assertNull(vwo.getUsageStats().get("is_eb"));
assertNull(vwo.getUsageStats().get("tru"));
assertEquals(vwo.getUsageStats().get("pi"), 1);
assertEquals(vwo.getUsageStats().get("ig"), 1);
assertNull(vwo.getUsageStats().get("eb"));
assertNull(vwo.getUsageStats().get("tr"));
}

@Test
Expand All @@ -142,14 +146,14 @@ public void alongWithShouldTrackReturningUser() {
.build();

assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertEquals(vwo.getUsageStats().get("is_cl"), 1);
assertEquals(vwo.getUsageStats().get("is_ll"), 1);
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertEquals(vwo.getUsageStats().get("cl"), 1);
assertEquals(vwo.getUsageStats().get("ll"), 1);
assertEquals(vwo.getUsageStats().get("gt"), 1);
assertEquals(vwo.getUsageStats().get("poll"), 1);
assertEquals(vwo.getUsageStats().get("is_i"), 1);
assertEquals(vwo.getUsageStats().get("tru"), 1);
assertNull(vwo.getUsageStats().get("is_eb"));
assertEquals(vwo.getUsageStats().get("pi"), 1);
assertEquals(vwo.getUsageStats().get("ig"), 1);
assertEquals(vwo.getUsageStats().get("tr"), 1);
assertNull(vwo.getUsageStats().get("eb"));
}

@Test
Expand All @@ -166,14 +170,14 @@ public void alongWithEventBatching() {
.build();

assertFalse(vwo.getUsageStats().isEmpty());
assertEquals(vwo.getUsageStats().get("is_ss"), 1);
assertEquals(vwo.getUsageStats().get("is_cl"), 1);
assertEquals(vwo.getUsageStats().get("is_ll"), 1);
assertEquals(vwo.getUsageStats().get("ss"), 1);
assertEquals(vwo.getUsageStats().get("cl"), 1);
assertEquals(vwo.getUsageStats().get("ll"), 1);
assertEquals(vwo.getUsageStats().get("gt"), 1);
assertEquals(vwo.getUsageStats().get("poll"), 1);
assertEquals(vwo.getUsageStats().get("is_i"), 1);
assertEquals(vwo.getUsageStats().get("tru"), 1);
assertEquals(vwo.getUsageStats().get("is_eb"), 1);
assertEquals(vwo.getUsageStats().get("pi"), 1);
assertEquals(vwo.getUsageStats().get("ig"), 1);
assertEquals(vwo.getUsageStats().get("tr"), 1);
assertEquals(vwo.getUsageStats().get("eb"), 1);
}

@Test
Expand All @@ -191,14 +195,44 @@ public void alongWithDevelopmentMode() {
.build();

assertTrue(vwo.getUsageStats().isEmpty());
assertNull(vwo.getUsageStats().get("is_ss"));
assertNull(vwo.getUsageStats().get("is_cl"));
assertNull(vwo.getUsageStats().get("is_ll"));
assertNull(vwo.getUsageStats().get("ss"));
assertNull(vwo.getUsageStats().get("cl"));
assertNull(vwo.getUsageStats().get("ll"));
assertNull(vwo.getUsageStats().get("gt"));
assertNull(vwo.getUsageStats().get("poll"));
assertNull(vwo.getUsageStats().get("is_i"));
assertNull(vwo.getUsageStats().get("tru"));
assertNull(vwo.getUsageStats().get("is_eb"));
assertNull(vwo.getUsageStats().get("pi"));
assertNull(vwo.getUsageStats().get("ig"));
assertNull(vwo.getUsageStats().get("tr"));
assertNull(vwo.getUsageStats().get("eb"));
}

@Test
public void dacdnFlagTruthyTest() {
VWO vwo = VWO.launch(Settings.AB_TRAFFIC_100_WEIGHT_50_50)
.withUserStorage(getUSerStorage())
.withCustomLogger(getCustomLogger())
.withSdkKey("sdk_key")
.build();

Campaign campaign = new Campaign();
campaign.setId(231);
Variation variation = new Variation();
variation.setId(1);
HttpParams httpParams = HttpRequestBuilder.getUserParams(vwo.getSettingFile(), campaign, "userId", variation, vwo.getUsageStats());
assertTrue(httpParams.getQueryParams().containsKey("_l"));
}

@Test
public void dacdnFlagFalsyTest() {
VWO vwo = VWO.launch(Settings.AB_TRAFFIC_100_WEIGHT_50_50)
.withSdkKey("sdk_key")
.build();

Campaign campaign = new Campaign();
campaign.setId(231);
Variation variation = new Variation();
variation.setId(1);
HttpParams httpParams = HttpRequestBuilder.getUserParams(vwo.getSettingFile(), campaign, "userId", variation, vwo.getUsageStats());
assertFalse(httpParams.getQueryParams().containsKey("_l"));
}

public static BatchEventData getBatchingData() {
Expand Down

0 comments on commit 6a192dd

Please sign in to comment.