User Context
To pass additional information about the current user (including a mandatory User ID), you must create a VWOContext Object and use the available functions to set different properties onto this userContext object.
The userContext object must be passed as an argument whenever you call the getFlag() or trackEvent() functions.
userContext Properties
Parameter | Type | Description |
---|---|---|
id Required | String | Unique user ID for the current user. 'id' is the only required property in userContext. This ID should be a unique identifier for the current user which you need to pass to VWO. Read more here . |
userAgent Optional | String | The userAgent object for the current user, can be used for targeting & segmentation. |
ipAddress Optional | String | IP Address of the current user, can be used for targeting & segmentation. |
customVariables Optional | Object | Any additional details of the current user that you want to push to VWO can be added here as key-value pairs, can be used for targeting & pre-segmentation. |
Usage
// Create VWOContext object
VWOContext context = new VWOContext();
// Set User ID - mandatory
context.setId("user-id");
// Set IP Address
context.setIpAddress("1.1.1.1");
// Set User Agent
context.setUserAgent("visitor_user_agent");
// Set Custom Variables
Map<String, ?> customVariables = new HashMap<String, Object>() {
{
put("age", 25);
}
};
context.setCustomVariables(customVariables);
// Pass userContext as a mandatory argument when calling getFlag or trackEvent
const featureFlag1 = await vwoClient.getFlag('feature_key', userContext);
vwoClient.trackEvent('event-name', userContext, eventProperties);
Updated 3 months ago
What’s Next