Creates a new ExperimentClient instance.
In most cases you will want to use the initialize
factory method in
Experiment.
The Client key for the Experiment project
See ExperimentConfig for config options
Add a plugin to the experiment client.
the plugin to add.
Returns all variants for the user.
The primary source of variants is based on the Source configured in the ExperimentConfig.
Track an exposure event for the variant associated with the flag/experiment key.
This method requires that an ExposureTrackingProvider be configured when this client is initialized, either manually, or through the Amplitude Analytics SDK integration from set up using Experiment.initializeWithAmplitudeAnalytics.
The flag/experiment key to track an exposure for.
ExposureTrackingProvider
Assign the given user to the SDK and asynchronously fetch all variants from the server. Subsequent calls may omit the user from the argument to use the user from the previous call.
If an ExperimentUserProvider has been set, the argument user will be merged with the provider user, preferring user fields from the argument user and falling back on the provider for fields which are null or undefined.
If configured, fetch retries the request in the background on failure. Variants received from a successful retry are stored in local storage for access.
If you are using the initialVariants
config option to preload this SDK
from the server, you generally do not need to call fetch
.
The user to fetch variants for.
Optional
options: FetchOptionsOptions for this specific fetch call.
Promise that resolves when the request for variants completes.
Get a copy of the internal ExperimentUser object if it is set.
a copy of the internal user object if set.
Get the user provider set by setUserProvider or null if the user provider has not been set.
The user provider set by setUserProvider or null.
use ExperimentConfig.userProvider instead
Copy in and set the user within the experiment client.
the user to set within the experiment client.
Sets a user provider that will inject identity information into the user for () requests. The user provider will only set user fields in outgoing requests which are null or undefined.
See ExperimentUserProvider for more details
use ExperimentConfig.userProvider instead
Start the SDK by getting flag configurations from the server and fetching variants for the user. The promise returned by this function resolves when local flag configurations have been updated, and the () result has been received (if the request was made).
To force this function not to fetch variants, set the fetchOnStart
configuration option to false
when initializing the SDK.
Finally, this function will start polling for flag configurations at a
fixed interval. To disable polling, set the pollOnStart
configuration option to false
on initialization.
Optional
user: ExperimentUserThe user to set in the SDK.
Returns the variant for the provided key.
Access the variant from Source, falling back on the given fallback, then the configured fallbackVariant.
If an ExposureTrackingProvider is configured and the
automaticExposureTracking configuration option is true
, this
function will call the provider with an Exposure event. The
exposure event does not count towards your event volume within Amplitude.
The key to get the variant for.
Optional
fallback: string | VariantThe highest priority fallback.
The default Client used to fetch variations from Experiment's servers.