User Storage Service (USS) is a caching layer to persist data about your users. This is helpful in ensuring that variation assignments are always sticky even if you update the campaign settings.
For example, you can create an implementation that reads and saves user-campaign data mapping from backend services such as Redis, Memcache, MongoDB, or any other storage service.
User Storage Service is optional while instantiating the VWO SDK. However, to ensure sticky variation assignments, we recommend implementing one.
User Storage Service should expose two methods: get and set.
|Retrieve stored data
|Returns a matching user-campaign data mapping corresponding to User ID passed
|Store user-campaign data mapping. It has information like user with User ID become part of a campaign having campaign-key as <Campaign_Key> and got the assigned variation <Variation_Name>.
Check the following example to know more about how to implement your own User Storage Service.
# Abstract class encapsulating user storage service functionality.
# Override with your own implementation for storing
# And retrieving the user.
# Abstract method, must be defined to fetch the
# User storage dict corresponding to the user_id.
# @param[String] :user_id ID for user that needs to be retrieved.
# @return[Hash] :user_storage_obj Object representing the user.
def get(user_id, campaign_key)
# example code to fetch it from DB column
# Abstract method, must be to defined to save
# The user dict sent to this method.
# @param[Hash] :user_storage_obj Object representing the user.
# example code to save it in DB
User.update_attributes(vwo_id: user_data.userId, vwo_user: JSON.generate(user_data))
# Now use it to initiate VWO client instance
vwo_client_instance = VWO.new(account_id, sdk_key, custom_logger, UserStorage.new)
userStorageData is a map where data is being stored with respect to a unique user ID and a unique campaign key.
The following keys are expected in the map:
|Unique User ID which was provided at the time of calling the SDK API.
|Unique campaign key, provided at the time of campaign creation and passed when calling the SDK API.
|Variation Name that was assigned to the user having the User ID
|List of goals that have already been triggered for the campaign having campaignKey and for User ID, separated by a delimiter
Example: The campaign has three goals but only two have been triggered since now i.e. buy-now-clicked and product-bought goals.
Note: This is required in case of track API only. If you aren't calling track API, you can skip this parameter.
VWO SDK validates the variationName and checks whether the variation exists in the campaign having the campaignkey or not. If the variation is found, SDK will use without looking into the User Storage service. If the variation of not found, SDK will jump onto the process of checking whether the user is eligible for the campaign or not and returns accordingly from the SDK API.
Below is an example:
userId: 'User ID',
Updated 5 months ago