The default Client used to fetch variations from Experiment's servers.

Hierarchy

  • ExperimentClient

Implements

Constructors

Methods

  • Clear all variants in the cache and storage.

    Returns void

  • 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.

    Parameters

    • key: string

      The flag/experiment key to track an exposure for.

    Returns void

    See

    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.

    Parameters

    Returns Promise<ExperimentClient>

    Promise that resolves when the request for variants completes.

    See

    • ExperimentUser
    • ExperimentUserProvider
  • Copy in and set the user within the experiment client.

    Parameters

    Returns void

  • 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

    Parameters

    Returns Client

    Deprecated

    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.

    Parameters

    Returns Promise<void>

    See

    • fetchOnStart
    • pollOnStart
    • fetch
    • variant
  • Stop the local flag configuration poller.

    Returns void

  • 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.

    Parameters

    • key: string

      The key to get the variant for.

    • Optional fallback: string | Variant

      The highest priority fallback.

    Returns Variant

    See

    • ExperimentConfig
    • ExposureTrackingProvider