Skip to content

Commit 3d670da

Browse files
sakshamg1304rohitesh-wingify
authored andcommitted
feat: send health check event
1 parent 2876424 commit 3d670da

14 files changed

Lines changed: 238 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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.10.0] - 2025-08-04
9+
10+
### Added
11+
12+
- Added support for sending a one-time initialization event to the server to verify correct SDK setup.
13+
814
## [1.9.2] - 2025-07-24
915

1016
### 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.9.2</version>
22+
<version>1.10.0</version>
2323
<packaging>jar</packaging>
2424

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

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
package com.vwo;
1717

1818
import com.vwo.models.user.VWOInitOptions;
19+
import com.vwo.enums.EventEnum;
1920
import com.vwo.utils.LogMessageUtil;
21+
import com.vwo.utils.EventUtil;
2022

21-
import java.util.Objects;
23+
import com.fasterxml.jackson.databind.JsonNode;
24+
import com.fasterxml.jackson.core.JsonProcessingException;
2225

2326

2427
public class VWO extends VWOClient {
@@ -82,8 +85,36 @@ public static VWO init(VWOInitOptions options) {
8285
String message = LogMessageUtil.buildMessage("Account ID is required to initialize VWO. Please provide the accountId in the options.", null);
8386
System.err.println(message);
8487
}
85-
88+
//start timer
89+
long initStartTime = System.currentTimeMillis();
8690
instance = VWO.setInstance(options);
91+
long initTime = System.currentTimeMillis() - initStartTime;
92+
93+
// if wasInitializedEarlier in sdkMetaInfo in settings is false or is absent and settings is valid on init, then send sdk init event
94+
String settings = vwoBuilder.getOriginalSettings();
95+
if (settings != null && !settings.isEmpty()) {
96+
try {
97+
JsonNode settingsJsonNode = VWOClient.objectMapper.readTree(settings);
98+
99+
boolean wasInitializedEarlier = false; // default value
100+
JsonNode sdkMetaInfoNode = settingsJsonNode.get("sdkMetaInfo");
101+
if (sdkMetaInfoNode != null) {
102+
JsonNode wasInitializedEarlierNode = sdkMetaInfoNode.get("wasInitializedEarlier");
103+
if (wasInitializedEarlierNode != null) {
104+
wasInitializedEarlier = wasInitializedEarlierNode.asBoolean();
105+
}
106+
}
107+
108+
boolean isSettingsValidOnInit = vwoBuilder.getSettingsService().isSettingsValidOnInit;
109+
110+
if (!wasInitializedEarlier && isSettingsValidOnInit) {
111+
EventUtil.sendSdkInitEvent(vwoBuilder.getSettingsService().getSettingsFetchTime(), initTime, EventEnum.VWO_SDK_INIT_EVENT.getValue());
112+
}
113+
} catch (JsonProcessingException e) {
114+
String message = LogMessageUtil.buildMessage("Error parsing settings JSON: " + e.getMessage(), null);
115+
System.err.println(message);
116+
}
117+
}
87118
return instance;
88119
}
89120
}

src/main/java/com/vwo/VWOBuilder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,21 @@ private void checkAndPoll() {
299299
}
300300

301301
/**
302-
* Initializes batching based on options.
303-
* @return The instance of this builder.
302+
* Gets the original settings string
303+
* @return The original settings string
304304
*/
305+
public String getOriginalSettings() {
306+
return this.originalSettings;
307+
}
308+
309+
/**
310+
* Gets the settings service instance
311+
* @return The settings service instance
312+
*/
313+
public SettingsManager getSettingsService() {
314+
return this.settingFileManager;
315+
}
316+
305317
public VWOBuilder initBatching() {
306318
// Check if gatewayService is provided and skip SDK batching if so
307319
if (SettingsManager.getInstance().isGatewayServiceProvided) {

src/main/java/com/vwo/api/SetAttributeAPI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ private static void createAndSendImpressionForSetAttribute(
5252
) {
5353
// Get base properties for the event
5454
Map<String, String> properties = NetworkUtil.getEventsBaseProperties(
55-
settings,
5655
EventEnum.VWO_SYNC_VISITOR_PROP.getValue(),
5756
encodeURIComponent(context.getUserAgent()),
5857
context.getIpAddress()

src/main/java/com/vwo/api/TrackEventAPI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ private static void createAndSendImpressionForTrack(
8383
) {
8484
// Get base properties for the event
8585
Map<String, String> properties = NetworkUtil.getEventsBaseProperties(
86-
settings,
8786
eventName,
8887
encodeURIComponent(context.getUserAgent()),
8988
context.getIpAddress()

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

Lines changed: 2 additions & 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.9.2";
31+
public static final String SDK_VERSION = "1.10.0";
3232
public static final long SETTINGS_EXPIRY = 10000000;
3333
public static final long SETTINGS_TIMEOUT = 50000;
3434

@@ -43,4 +43,5 @@ public class Constants {
4343
public static final String VWO_META_MEG_KEY = "_vwo_meta_meg_";
4444

4545
public static final int DEFAULT_POLL_INTERVAL = 600000; // 10 minutes
46+
public static final String FME = "fme";
4647
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
public enum EventEnum {
1919
VWO_VARIATION_SHOWN("vwo_variationShown"),
20-
VWO_SYNC_VISITOR_PROP("vwo_syncVisitorProp");
20+
VWO_SYNC_VISITOR_PROP("vwo_syncVisitorProp"),
21+
VWO_SDK_INIT_EVENT("vwo_fmeSdkInit"),
22+
VWO_ERROR("vwo_log");
2123

2224
private final String value;
2325

src/main/java/com/vwo/models/request/Props.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public class Props {
3939
private Boolean isCustomEvent;
4040
@JsonProperty("vwoMeta")
4141
private Map<String, Object> vwoMeta;
42+
@JsonProperty("product")
43+
private String product;
44+
@JsonProperty("data")
45+
private Map<String, Object> data;
4246

4347
@JsonIgnore
4448
private Map<String,Object> additionalProperties = new HashMap<String,Object>();
@@ -100,4 +104,11 @@ public void setVwoMeta(Map<String, Object> vwoMeta) {
100104
this.vwoMeta = vwoMeta;
101105
}
102106

107+
public void setData(Map<String, Object> data) {
108+
this.data = data;
109+
}
110+
111+
public void setProduct(String product) {
112+
this.product = product;
113+
}
103114
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@
3333

3434
// public class SettingsManager implements ISettingsManager {
3535
public class SettingsManager {
36-
private String sdkKey;
37-
private Integer accountId;
36+
public String sdkKey;
37+
public Integer accountId;
3838
private int expiry;
3939
private int networkTimeout;
4040
public String hostname;
4141
public int port;
4242
public String protocol = "https";
4343
public boolean isGatewayServiceProvided = false;
44+
public boolean isSettingsValidOnInit = false;
45+
private Long settingsFetchTime;
4446
private static SettingsManager instance;
4547

4648
public SettingsManager(VWOInitOptions options) {
@@ -85,6 +87,14 @@ public static SettingsManager getInstance() {
8587
return instance;
8688
}
8789

90+
/**
91+
* Gets the settings fetch time
92+
* @return The settings fetch time in milliseconds
93+
*/
94+
public Long getSettingsFetchTime() {
95+
return this.settingsFetchTime;
96+
}
97+
8898
/**
8999
* Fetches settings from the server
90100
*/
@@ -126,6 +136,9 @@ public String fetchSettings(Boolean isViaWebhook) {
126136
}
127137

128138
try {
139+
// Set fetch time
140+
long startTime = System.currentTimeMillis();
141+
129142
RequestModel request = new RequestModel(hostname, "GET", endpoint, options, null, null, this.protocol, port);
130143
request.setTimeout(networkTimeout);
131144

@@ -138,6 +151,7 @@ public String fetchSettings(Boolean isViaWebhook) {
138151
});
139152
return null;
140153
}
154+
this.settingsFetchTime = System.currentTimeMillis() - startTime;
141155
return response.getData();
142156
} catch (Exception e) {
143157
LoggerService.log(LogLevelEnum.ERROR, "SETTINGS_FETCH_ERROR", new HashMap<String, String>() {
@@ -166,6 +180,7 @@ public String getSettings(Boolean forceFetch) {
166180
}
167181
boolean settingsValid = new SettingsSchema().isSettingsValid(VWOClient.objectMapper.readValue(settings, Settings.class));
168182
if (settingsValid) {
183+
this.isSettingsValidOnInit = true;
169184
return settings;
170185
} else {
171186
LoggerService.log(LogLevelEnum.ERROR, "SETTINGS_SCHEMA_INVALID", null);

0 commit comments

Comments
 (0)