Skip to content

Commit a6ad7ba

Browse files
Abhi591rohitesh-wingify
authored andcommitted
feat: usage Stats
1 parent 2a78350 commit a6ad7ba

13 files changed

Lines changed: 141 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.15.0] - 2025-12-08
9+
### Added
10+
11+
- Sends usage statistics to VWO servers automatically during SDK initialization
12+
813
## [1.14.0] - 2025-11-24
914

1015
### Added

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License. -->
1919

2020
<groupId>com.vwo.sdk</groupId>
2121
<artifactId>vwo-fme-java-sdk</artifactId>
22-
<version>1.14.0</version>
22+
<version>1.15.0</version>
2323
<packaging>jar</packaging>
2424

2525
<name>VWO FME Java SDK</name>

src/main/java/com/vwo/VWO.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public static VWO init(VWOInitOptions options) {
8484
VWO instance = VWO.setInstance(options);
8585
long initTime = System.currentTimeMillis() - initStartTime;
8686
// send sdk init event
87-
instance.sendSdkInitEvent(initTime);
87+
instance.sendSdkInitAndUsageStatsEvent(initTime);
8888
return instance;
8989
}
9090
}
91-

src/main/java/com/vwo/VWOClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public VWOClient(String settings, VWOBuilder vwoBuilder) {
6363
if (vwoBuilder.getBatchEventQueue() != null) {
6464
vwoBuilder.getBatchEventQueue().setSettings(this.processedSettings);
6565
}
66+
if (!DataTypeUtil.isNull(this.processedSettings.getCollectionPrefix()) && !this.processedSettings.getCollectionPrefix().isEmpty()) {
67+
this.vwoBuilder.getSettingsManager().collectionPrefix = this.processedSettings.getCollectionPrefix();
68+
}
6669
SettingsUtil.processSettings(this.processedSettings, this.vwoBuilder.getLoggerService());
6770
} catch (Exception exception) {
6871
System.err.println("exception occurred while parsing settings " + exception.getMessage());
@@ -73,7 +76,7 @@ public VWOClient(String settings, VWOBuilder vwoBuilder) {
7376
* This method is used to send the sdk init event
7477
* @param settingsInitTime The time taken to initialize the settings
7578
*/
76-
protected void sendSdkInitEvent(long settingsInitTime) {
79+
protected void sendSdkInitAndUsageStatsEvent(long settingsInitTime) {
7780
try {
7881
if ( this.processedSettings == null ) {
7982
throw new IllegalStateException("processedSettings is null");
@@ -89,6 +92,12 @@ protected void sendSdkInitEvent(long settingsInitTime) {
8992
EventUtil.sendSdkInitEvent(this.vwoBuilder.getSettingsManager(), this.vwoBuilder.getSettingsManager().settingsFetchTime, settingsInitTime, EventEnum.VWO_SDK_INIT_EVENT.getValue());
9093
}
9194
}
95+
96+
// get usage stats account id from settings
97+
Integer usageStatsAccountId = this.processedSettings.getUsageStatsAccountId();
98+
if (!DataTypeUtil.isNull(usageStatsAccountId) && usageStatsAccountId != 0) {
99+
EventUtil.sendUsageStatsEvent(this.vwoBuilder.getSettingsManager(), usageStatsAccountId);
100+
}
92101
} catch (Exception exception) {
93102
vwoBuilder.getLoggerService().log(LogLevelEnum.ERROR, "SDK_INIT_EVENT_FAILED", new HashMap<String, Object>() {{
94103
put("err", exception.getMessage());

src/main/java/com/vwo/constants/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Constants {
2828
public static final int DEFAULT_REQUEST_TIME_INTERVAL = 600; // 10 * 60(secs) = 600 secs i.e. 10 minutes
2929
public static final int DEFAULT_EVENTS_PER_REQUEST = 100;
3030
public static final String SDK_NAME = "vwo-fme-java-sdk";
31-
public static final String SDK_VERSION = "1.14.0";
31+
public static final String SDK_VERSION = "1.15.0";
3232
public static final long SETTINGS_EXPIRY = 10000000;
3333
public static final long SETTINGS_TIMEOUT = 50000;
3434

src/main/java/com/vwo/enums/EventEnum.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum EventEnum {
2020
VWO_SYNC_VISITOR_PROP("vwo_syncVisitorProp"),
2121
VWO_SDK_INIT_EVENT("vwo_fmeSdkInit"),
2222
VWO_ERROR("vwo_log"),
23-
VWO_DEBUGGER_EVENT("vwo_sdkDebug");
23+
VWO_DEBUGGER_EVENT("vwo_sdkDebug"),
24+
VWO_USAGE_STATS("vwo_sdkUsageStats");
2425

2526
private final String value;
2627

src/main/java/com/vwo/models/Settings.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class Settings {
2929
private List<Feature> features;
3030
@JsonProperty("accountId")
3131
private Integer accountId;
32+
@JsonProperty("usageStatsAccountId")
33+
private Integer usageStatsAccountId;
3234
@JsonProperty("groups")
3335
private Map<String, Groups> groups;
3436
@JsonProperty("campaignGroups")
@@ -69,6 +71,14 @@ public void setAccountId(Integer accountId) {
6971
this.accountId = accountId;
7072
}
7173

74+
public Integer getUsageStatsAccountId() {
75+
return usageStatsAccountId;
76+
}
77+
78+
public void setUsageStatsAccountId(Integer usageStatsAccountId) {
79+
this.usageStatsAccountId = usageStatsAccountId;
80+
}
81+
7282
public Map<String, Groups> getGroups() {
7383
return groups;
7484
}

src/main/java/com/vwo/services/BatchEventQueue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public void setSettings(Settings settings) {
6868
public void enqueue(EventArchPayload eventData) {
6969
synchronized (LockObject) {
7070
Map<String, Object> payload = VWOClient.objectMapper.convertValue(eventData, Map.class);
71+
payload = NetworkUtil.removeNullValues(payload);
7172
batchQueue.add(payload);
7273
loggerService.log(LogLevelEnum.DEBUG, "Event added to queue. Current queue size: " + batchQueue.size());
7374

src/main/java/com/vwo/services/SettingsManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class SettingsManager {
4848
public boolean isSettingsValidOnInit = false;
4949
public Long settingsFetchTime;
5050
public LoggerService loggerService;
51+
public String collectionPrefix = "";
5152

5253
public SettingsManager(VWOInitOptions options, LoggerService loggerService) {
5354
this.loggerService = loggerService;

src/main/java/com/vwo/utils/EventUtil.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.vwo.utils;
1717

1818
import com.vwo.services.SettingsManager;
19+
import com.vwo.enums.EventEnum;
1920

2021
import java.util.Map;
2122

@@ -52,4 +53,30 @@ public static void sendSdkInitEvent(SettingsManager settingsManager, Long settin
5253
// Send the event immediately
5354
NetworkUtil.sendEventDirectlyToDacdn(settingsManager, properties, payload, eventName);
5455
}
56+
57+
/**
58+
* Sends usage stats event
59+
* This event is triggered when the usage stats is called.
60+
*
61+
* @param usageStatsAccountId The account ID of the usage stats account.
62+
*/
63+
public static void sendUsageStatsEvent(SettingsManager settingsManager, Integer usageStatsAccountId) {
64+
// Create event properties
65+
Map<String, String> properties = NetworkUtil.getEventsBaseProperties(
66+
EventEnum.VWO_USAGE_STATS.getValue(),
67+
null,
68+
null,
69+
usageStatsAccountId
70+
);
71+
72+
// Create payload for usage stats event
73+
Map<String, Object> payload = NetworkUtil.getUsageStatsPayloadData(
74+
settingsManager,
75+
EventEnum.VWO_USAGE_STATS.getValue(),
76+
usageStatsAccountId
77+
);
78+
79+
// Send the event immediately
80+
NetworkUtil.sendEventDirectlyToDacdn(settingsManager, properties, payload, EventEnum.VWO_USAGE_STATS.getValue());
81+
}
5582
}

0 commit comments

Comments
 (0)