UNPKG

@amplitude/experiment-js-client

Version:
168 lines (165 loc) 6.37 kB
import { ExperimentAnalyticsProvider } from './types/analytics'; import { ExposureTrackingProvider } from './types/exposure'; import { ExperimentUserProvider } from './types/provider'; import { Source } from './types/source'; import { HttpClient } from './types/transport'; import { Variant, Variants } from './types/variant'; /** * @category Configuration */ export interface ExperimentConfig { /** * Debug all assignment requests in the UI Debugger and log additional * information to the console. This should be false for production builds. */ debug?: boolean; /** * The name of the instance being initialized. Used for initializing separate * instances of experiment or linking the experiment SDK to a specific * instance of the amplitude analytics SDK. */ instanceName?: string; /** * The default fallback variant for all {@link ExperimentClient.variant} * calls. */ fallbackVariant?: Variant; /** * Initial values for variants. This is useful for bootstrapping the * client with fallbacks and values evaluated from server-side rendering. * @see Variants */ initialVariants?: Variants; /** * Initial values for flags. This is useful for bootstrapping the * client with fallbacks for flag configs. */ initialFlags?: string; /** * Determines the primary source of variants and variants before falling back. * @see Source */ source?: Source; /** * The domain from which to request variants using remote evaluation. */ serverUrl?: string; /** * The domain to request flag configurations used in local evaluation from. */ flagsServerUrl?: string; /** * The amplitude data center to fetch flags and variants from. If set, * automatically sets the {@link serverUrl} and {@link flagsServerUrl} * configurations. */ serverZone?: string; /** * The request timeout, in milliseconds, when fetching variants. */ fetchTimeoutMillis?: number; /** * Set to true to retry fetch requests in the background if the initial * requests fails or times out. */ retryFetchOnFailure?: boolean; /** * When set to true, the client will throw errors if requests fail for any * reason (including timeouts, network errors, or server errors), rather than * silently handling the error. This applies to both the initial fetch during * start() and subsequent fetch() calls. Background retries will still be * started if configured via retryFetchOnFailure. * * When false (default), errors are handled silently and retries may occur * in the background based on the retryFetchOnFailure configuration. */ throwOnError?: boolean; /** * If true, automatically tracks exposure events though the * `ExperimentAnalyticsProvider`. If no analytics provider is set, this * option does nothing. */ automaticExposureTracking?: boolean; /** * Enable or disable local evaluation flag configuration polling on `start()`. */ pollOnStart?: boolean; /** * The interval to poll local evaluation flag configurations on `start()`. * Only used if `pollOnStart` is `true`. Minimum 60000. */ flagConfigPollingIntervalMillis?: number; /** * Explicitly enable or disable calling {@link fetch()} on {@link start()}: * * - `true`: fetch will always be called on start. * - `false`: fetch will never be called on start. * - `undefined`: fetch will always be called on start. */ fetchOnStart?: boolean; /** * This config only matters if you are using the amplitude analytics SDK * integration initialized by calling * `Experiment.initializeWithAmplitudeAnalytics()`. * * If true, the `ExperimentClient` will automatically fetch variants when the * user's identity changes. The user's identity includes user_id, device_id * and any user properties which are `set`, `unset` or `clearAll`ed via a call * to `identify()`. * * Note: Non-idempotent identify operations `setOnce`, `add`, `append`, and * `prepend` are not counted towards the user identity changing. */ automaticFetchOnAmplitudeIdentityChange?: boolean; /** * Sets a user provider that will inject identity information into the user * for {@link fetch()} requests. The user provider will only set user fields * in outgoing requests which are null or undefined. * * See {@link ExperimentUserProvider} for more details */ userProvider?: ExperimentUserProvider; /** * Provides a analytics implementation for standard experiment events * generated by the client (e.g. {@link ExposureEvent}). * * @deprecated Use exposureTrackingProvider instead */ analyticsProvider?: ExperimentAnalyticsProvider; /** * Provides the ability to track exposure events through a 3rd party analytics * implementation. */ exposureTrackingProvider?: ExposureTrackingProvider; /** * (Advanced) Use your own http client. */ httpClient?: HttpClient; } /** Defaults for Experiment Config options | **Option** | **Default** | |------------------|-----------------------------------| | **debug** | `false` | | **instanceName** | `$default_instance` | | **fallbackVariant** | `null` | | **initialVariants** | `null` | | **initialFlags** | `undefined` | | **source** | `Source.LocalStorage` | | **serverUrl** | `"https://api.lab.amplitude.com"` | | **flagsServerUrl** | `"https://flag.lab.amplitude.com"` | | **serverZone** | `"US"` | | **assignmentTimeoutMillis** | `10000` | | **retryFailedAssignment** | `true` | | **automaticExposureTracking** | `true` | | **pollOnStart** | `true` | | **flagConfigPollingIntervalMillis** | `300000` | | **fetchOnStart** | `true` | | **automaticFetchOnAmplitudeIdentityChange** | `false` | | **userProvider** | `null` | | **analyticsProvider** | `null` | | **exposureTrackingProvider** | `null` | * * @category Configuration */ export declare const Defaults: ExperimentConfig;