Implement a User Storage Service

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.

How to Implement User 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.

Method NameParamsDescriptionReturns
getuserId, campaignKeyRetrieve stored dataReturns a matching user-campaign data mapping corresponding to User ID passed
setcampaignUserMapStore 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>.Nothing.

Check the following example to know more about how to implement your own User Storage Service.

import vwo
from vwo import logger

class user_storage_service(UserStorageService):
  def get(self, user_id, campaign_test_key):
    # ...code here for getting data
    # return data

  def set(self, campaign_user_map):
    # ...code to persist data

uss = user_storage_service()

settings_file = vwo.get_settings_file(account_id, sdk_key)
vwo_client_instance = vwo.launch(settings_file, user_storage_service = uss)

Format for the userStorageData

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:

userId StringUnique User ID which was provided at the time of calling the SDK API.
campaignKey StringUnique campaign key, provided at the time of campaign creation and passed when calling the SDK API.
variationName StringVariation Name that was assigned to the user having the User ID
goalIdentifier StringList of goals that have already been triggered for the campaign having campaignKey and for User ID, separated by a delimiter _vwo_.
Example: The campaign has three goals but only two have been triggered since now i.e. buy-now-clicked and product-bought goals.
'buy-now-clicked_vwo_product-bought'

Note: This is required in case of track API only. If you aren't calling track API, you can skip this parameter.

🚧

Note:

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',
  campaignKey: 'unique-campaign-key',
  variationName: 'Variation-1'
}