Get Variation Name

After successfully instantiating a VWO class, getVariationName API returns the variation assigned to the specified user if the user qualifies to become part of the specified campaign. This API doesn't activate the campaign i.e. it will not send any impression call to the VWO servers for tracking any data.

Description

The API method:

  • Validates the parameters passed.
  • Checks whether the user is whitelisted.
  • Checks if User Storage Service is provided to know whether the user is returning. If yes, show the previously assigned variation always.
  • Checks if the campaign is part of Mutually Exclusive Group and evaluates all the grouped campaigns to decide whether the user is eligible for the campaign.
  • Checks whether the user is eligible based on the campaign's pre-segmentation conditions.
  • Checks whether the user qualifies to become a part of the campaign based on traffic allocation.
  • Assigns a deterministic variation to the qualified user.
  • Does not send an impression event to the VWO server.

It takes the same parameters and returns the same value as Activate API. The only difference is that this API method does not send a tracking impression to the VWO server. This API method is used to get the variation assigned to the userId.
The behavior of the two API methods, that is, activate and getVariationName is identical otherwise.

Use Get Variation Name API if Activate API has already been triggered to prevent a user from being tracked again. Also, this API is also helpful in retrieving the variation assignment to a particular User Id, respecting all other factors like segmentation, whitelisting, etc. without sending any impression call to the VWO servers.

Parameter definitions

ParameterTypeDescription
campaignKey
Required
StringThe campaign needs to be identified based on the unique test-key provided at the time of campaign creation.
userId
Required
StringThe User ID which uniquely identifies each user.
options
Optional
ObjectPass params for pre-segmentation and whitelisting

customVariables(Object): Custom variables to be matched against Campaign's pre-segmentation.

variationTargetingVariables(Object): Custom variation targeting variables to be matched against Campaign's forced variation/whitelisting conditions.

userStorageData(Object): Pass this so that SDK uses this data instead of calling the User Storage Service's get method to retrieve the stored data. It also helps in implementing the asynchronous nature of the User Storage Service's get method.
Note: This is only supported in Node.js SDK from v1.11.0 onwards.

Returns

The name of the variation in which the user is bucketed, or is null if the user does not qualify for a campaign.

ValueTypeDescription
Variation nameStringWhen a user qualifies for the campaign, variation name is returned.
nullObjectWhen a user is not qualified for a campaign, null is returned.

Usage

// campaignKey: you provide at the time of campaign creation
// userId: how you identify a particular user
// options: (Optional)
//   customVariables: pre-segmentation variables
//   variationTargetingVariables: forced variation variables
var variation = vwoClientInstance.getVariationName(campaignKey, userId, options);

// Campaign having two variations
if (variation === 'Control') {
  // Write code for handling 'Control'
} else if (variation === 'Variation-1') {
  // Write code for handling 'Variation-1'
} else {
  // CODE: User is not qualified for the campaign. Would be due to configuring campaign's percent-traffic less than 100% while creating or updating a FullStack campaign.
}

For passing userStorageData in the options, please follow this doc.

Campaign Activation with User Storage Service

If User Storage Service is provided, campaign activation is mandatory before tracking any goal, getting a variation of a campaign, and getting the value of the feature's variable.

Correct Usage

vwoClientInstance.getVariationName(campaignKey, userId, options);
vwoClientInstance.track(campaignKey, userId, goalIdentifier, options);

Wrong Usage

// Calling track API before activate API
// This will not track the goal as the campaign has not been activated yet.
vwoClientInstance.track(campaignKey, userId, goalIdentifier, options);

// After calling track APi
vwoClientInstance.getVariationName(campaignKey, userId, options);

🚧

Note

Mandatory campaign activation is available from v1.13 onwards.