Initialization
To create a VWO Client instance, you need to initialize the VWO FME Java SDK. This client instance serves as the core interface for conducting feature management and experimentation(A/B and personalization) within your application.
Usage
import com.vwo.VWO;
import com.vwo.models.user.VWOInitOptions;
// Initialize VWO SDK
VWOInitOptions vwoInitOptions = new VWOInitOptions();
// Set SDK Key and Account ID
vwoInitOptions.setSdkKey("sdk-key"); //SDK Key
vwoInitOptions.setAccountId(123); //account ID
// create VWO instance with the vwoInitOptions
VWO vwoClient = VWO.init(vwoInitOptions);
An object of VWOInitOptions
is created to store the SDK configuration details.
The init()
function is called with the vwoInitOptions
object. It initializes and returns a VWO Client ObjectvwoClient
, which can be used to perform feature
This client object allows you to run experiments, track events, and enable/disable feature flags.
Parameter Definitions
Parameter | Usage | Type | Description |
---|---|---|---|
accountId Required | vwoInitOptions.setAccountId(123); | Integer | Your VWO application's Account ID. |
sdkKey Required | vwoInitOptions.setSdkKey("sdk-key"); | String | A unique environment key is provided to you inside the Websites & Apps section in the VWO application, under Default Project. |
pollInterval Optional | vwoInitOptions.setPollInterval(60); | Integer | Time (in milliseconds) at which VWO should check with the server for any updates to the feature flag or rules in the VWO Dashboard. Useful to keep your VWO Client instance up-to-date with any changes made in the VWO Application. For more details, please check -Polling |
logger Optional | vwoInitOptions.setLogger(logger); | Object | An optional logger object that defines the logging behavior. For more details, please check -Logger |
storage Optional | vwoInitOptions.setStorage(storage) | Object | Storage Service, if required, can be implemented using this parameter. For more details, please check - Storage Service |
gatewayService Optional | vwoInitOptions.setGatewayService(new HashMap<String, Object>() { { put("url", "<https://your.host.com:port")>; } }); | Object | If using the FME Gateway Service , this object will specify the location and port of where the gateway service is deployed on your servers. |
integrations Optional | vwoInitOptions.setIntegrations(integrations); | Object | A callback function that receives data which can be pushed to any external tool that you need to integrate with. For more details, please check - Integrations |
Poll Interval (Keeping VWO client up-to-date)
When you initialize the vwoClient on your server, it pulls the latest configurations you've done in the VWO application.
If/when you make any changes to the feature flags or rules within VWO after the vwoClient has been initialized in your server, there needs to be some way to update your vwoClient with the latest settings from VWO. This can be done via polling.
The poll interval is an optional parameter that allows the SDK to automatically fetch and update settings from the VWO server at specified intervals. Setting this parameter ensures your application always uses the latest configuration.
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setPollInterval(60000); // Set the poll interval to 60 seconds
VWO vwoInstance = VWO.init(vwoInitOptions);
Logger
VWO by default logs all ERROR level messages to your server console. To gain more control over VWO's logging behavior, you can use the logger parameter in the init configuration.
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setAccountId(123456);
vwoInitOptions.setSdkKey("32-alpha-numeric-sdk-key");
Map<String, Object> logger = new HashMap<>();
logger.put("level", "DEBUG");
vwoInitOptions.setLogger(logger);
VWO vwoInstance = VWO.init(vwoInitOptions);
Please click here for more advanced logger options.
Storage
By default, the SDK operates in stateless mode, evaluating flags on each getFlag call. To improve performance and consistency, you can use a custom storage mechanism to cache decisions, ensuring stable user experiences and reducing application load.
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setAccountId(123456);
vwoInitOptions.setSdkKey("32-alpha-numeric-sdk-key");
vwoInitOptions.setStorage(storageObject)
VWO vwoInstance = VWO.init(vwoInitOptions);
Please click storage to learn more about storage implementation.
Gateway Service
The VWO FME Gateway Service enhances Feature Management and Experimentation (FME) SDKs by enabling pre-segmentation based on user location and user agent. It ensures minimal latency and improved security. The service can be customized via the gateway_service parameter during initialization.
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setAccountId(123456);
vwoInitOptions.setSdkKey("32-alpha-numeric-sdk-key");
Map<String, Object> gatewayService = new HashMap<>();
gatewayService.put("url", "http://custom.gateway.com");
vwoInitOptions.setGatewayService(gatewayService);
VWO vwoInstance = VWO.init(vwoInitOptions);
Please click GatewayService to learn more about gateway service.
Integrations
VWO FME SDKs provide seamless integration with third-party tools like analytics platforms, monitoring services, customer data platforms (CDPs), and messaging systems. This is achieved through a simple yet powerful callback mechanism that receives VWO-specific properties and can forward them to any third-party tool of your choice.
IntegrationCallback integrations = new IntegrationCallback() {
@Override
public void execute(Map<String, Object> properties) {
// your function definition
}
};
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey("32-alpha-numeric-sdk-key");
vwoInitOptions.setAccountId(12345);
vwoInitOptions.setIntegrations(integrations);
VWO vwoInstance = VWO.init(vwoInitOptions);
Please click here to learn more about Integrations,.
Updated 5 days ago