Initialization

To create a VWO Client instance, you need to initialize the VWO FME Android 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.interfaces.IVwoInitCallback
import com.vwo.models.user.VWOContext
import com.vwo.models.user.VWOInitOptions

// Set SDK Key and Account ID
val vwoInitOptions = VWOInitOptions()
vwoInitOptions.sdkKey = SDK_KEY
vwoInitOptions.accountId = ACCOUNT_ID

// Initialize VWO SDK
VWO.init(vwoInitOptions, object : IVwoInitCallback {
    override fun vwoInitSuccess(vwo: VWO, message: String) {
        // VWO SDK initialized
    }
 
    override fun vwoInitFailed(message: String) {
        // VWO SDK failed to initialize
    }
})
import com.vwo.VWO;
import com.vwo.interfaces.IVwoInitCallback;
import com.vwo.models.user.VWOContext;
import com.vwo.models.user.VWOInitOptions;

// Set SDK Key and Account ID
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey(SDK_KEY);
vwoInitOptions.setAccountId(ACCOUNT_ID);

// Initialize VWO SDK
VWO.init(vwoInitOptions, new IVwoInitCallback() {
    @Override
    public void vwoInitSuccess(@NonNull VWO vwo, @NonNull String message) {
        // VWO SDK Initialized  
    }
 
    @Override
    public void vwoInitFailed(@NonNull String message) {
        // VWO SDK failed to initialize
    }
});

The init() method is called with the sdkKeyand accountId. 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

Type

Description

accountId Required

Integer

VWO Account ID for authentication.

sdkKey Required

String

A unique environment key is provided to you inside the Websites & Apps section in the VWO application, under Default Project.

pollInterval Optional

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

storage Optional

Object

Custom storage connector for persisting user decisions and campaign data.

logger Optional

Object

An optional logger object that defines the logging behavior. For more details, please check - Logger

integrations Optional

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

cachedSettingsExpiryTime Optional

Integer

Controls the duration (in milliseconds) the SDK uses cached settings before fetching new ones.

batchMinSize Optional

Integer

Uploads are triggered when the batch reaches this minimum size.

batchUploadTimeInterval Optional

Integer

Specifies the time interval (in milliseconds) for periodic batch uploads.

context Optional

Context

Android application context. When provided, SDK will use internal storage for persisting user decisions and campaign data.

Poll Interval (Keeping VWO client up-to-date)

When you initialize the vwoClient on your mobile, 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 on your mobile, 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.

val vwoInitOptions = VWOInitOptions()
vwoInitOptions.sdkKey = SDK_KEY
vwoInitOptions.accountId = ACCOUNT_ID
vwoInitOptions.pollInterval = POLL_INTERVAL // in milliseconds

// Initialize VWO SDK
VWO.init(vwoInitOptions, object : IVwoInitCallback {
    override fun vwoInitSuccess(vwo: VWO, message: String) {
        // VWO SDK initialized
    }
 
    override fun vwoInitFailed(message: String) {
        // VWO SDK failed to initialize
    }
})
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey(SDK_KEY);
vwoInitOptions.setAccountId(ACCOUNT_ID);
vwoInitOptions.setPollInterval(POLL_INTERVAL); // in milliseconds

// Initialize VWO SDK
VWO.init(vwoInitOptions, new IVwoInitCallback() {
    @Override
    public void vwoInitSuccess(@NonNull VWO vwo, @NonNull String message) {
        // VWO SDK Initialized  
    }
 
    @Override
    public void vwoInitFailed(@NonNull String message) {
        // VWO SDK failed to initialize
    }
});

Logger

VWO by default logs all ERROR level messages to your device console. To gain more control over VWO's logging behavior, you can use the logger parameter in the init configuration.

vwoInitOptions.logger = mutableMapOf<String, Any>().apply {
  put("level", "INFO") // DEBUG, INFO, ERROR, TRACE, WARN
}
Map<String, Object> loggerOptions = new HashMap<>();
loggerOptions.put("level", "INFO");  // DEBUG, INFO, ERROR, TRACE, WARN

vwoInitOptions.setLogger(loggerOptions);

Please click here for more advanced logger options.

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.

val vwoInitOptions = VWOInitOptions()

vwoInitOptions.sdkKey = SDK_KEY
vwoInitOptions.accountId = ACCOUNT_ID

val integrations = object : IntegrationCallback {
    override fun execute(properties: Map<String, Any>) {
        // your function definition 
    }
}
vwoInitOptions.integrations = integrations

// Initialize VWO SDK
VWO.init(vwoInitOptions, object : IVwoInitCallback {
    override fun vwoInitSuccess(vwo: VWO, message: String) {
        // VWO SDK initialized
    }
 
    override fun vwoInitFailed(message: String) {
        // VWO SDK failed to initialize
    }
})
IntegrationCallback integrations = new IntegrationCallback() {
            @Override
            public void execute(Map<String, Object> properties) {
                // your function definition 
            }
        };

VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey("sdkKey");
vwoInitOptions.setAccountId(12345);
vwoInitOptions.setIntegrations(integrations);

// Initialize VWO SDK
VWO.init(vwoInitOptions, new IVwoInitCallback() {
    @Override
    public void vwoInitSuccess(@NonNull VWO vwo, @NonNull String message) {
        // VWO SDK Initialized  
    }
 
    @Override
    public void vwoInitFailed(@NonNull String message) {
        // VWO SDK failed to initialize
    }
});

Please click here to learn more about Integrations.

Cached Settings Expiry Time

The cachedSettingsExpiryTime parameter allows you to specify how long the cached settings should be considered valid before fetching new settings from the VWO server. This helps in managing the freshness of the configuration data.

Usage:

// Initialize VWOInitOptions with a custom cached settings expiry time
val vwoInitOptions = VWOInitOptions()
vwoInitOptions.sdkKey = SDK_KEY
vwoInitOptions.accountId = ACCOUNT_ID
vwoInitOptions.cachedSettingsExpiryTime = 600000

// Create VWO instance with the vwoInitOptions
init(vwoInitOptions, object : IVwoInitCallback {
    override fun vwoInitSuccess(vwoClient: VWO, message: String) {
        [email protected] = vwoClient
    }

    override fun vwoInitFailed(message: String) {
        //Initialization failed
    }
})
// Initialize VWOInitOptions with a custom cached settings expiry time
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey(SDK_KEY);
vwoInitOptions.setAccountId(ACCOUNT_ID);
vwoInitOptions.setCachedSettingsExpiryTime(600000);

// Create VWO instance with the vwoInitOptions
init(vwoInitOptions, new IVwoInitCallback() {
    @Override
    public void vwoInitSuccess(@NonNull VWO vwoClient, @NonNull String message) {
        MyActivity.this.vwoClient = vwoClient;
    }

    @Override
    public void vwoInitFailed(@NonNull String message) {
        //Initialization failed
    }
});

Event Batching Configuration

The VWO SDK supports storing impression events while the device is offline, ensuring no data loss. These events are batched and seamlessly synchronized with VWO servers once the device reconnects to the internet. Additionally, online event batching allows synchronization of impression events while the device is online. This feature can be configured by setting either the minimum batch size or the batch upload time interval during SDK initialization.

NOTE: The uploading of events will get triggered based on whichever condition is met first if using both options.

See Event Batching documentation for additional information.

ParameterDescriptionRequiredTypeExample
batchMinSizeMinimum size of the batch to upload.NoInteger10
batchUploadTimeIntervalBatch upload time interval in milliseconds. Please specify at least a few minutes.NoInteger300000

Usage:

// Initialize VWOInitOptions with batch configuration
val vwoInitOptions = VWOInitOptions()
vwoInitOptions.sdkKey = SDK_KEY
vwoInitOptions.accountId = ACCOUNT_ID
vwoInitOptions.batchMinSize = 10
vwoInitOptions.batchUploadTimeInterval = 300000

// Create VWO instance with the vwoInitOptions
init(vwoInitOptions, object : IVwoInitCallback {
    override fun vwoInitSuccess(vwoClient: VWO, message: String) {
        [email protected] = vwoClient
    }

    override fun vwoInitFailed(message: String) {
        //Initialization failed
    }
})
// Initialize VWOInitOptions with batch configuration
VWOInitOptions vwoInitOptions = new VWOInitOptions();
vwoInitOptions.setSdkKey(SDK_KEY);
vwoInitOptions.setAccountId(ACCOUNT_ID);
vwoInitOptions.setBatchMinSize(10);
vwoInitOptions.setBatchUploadTimeInterval(300000);

// Create VWO instance with the vwoInitOptions
init(vwoInitOptions, new IVwoInitCallback() {
    @Override
    public void vwoInitSuccess(@NonNull VWO vwoClient, @NonNull String message) {
        MyActivity.this.vwoClient = vwoClient;
    }

    @Override
    public void vwoInitFailed(@NonNull String message) {
        //Initialization failed
    }
});