### Experiment Client Initialization and Access Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Experiment/index.html Provides methods to get an instance of the ExperimentClient and initialize the SDK with an API key and configuration. ```APIDOC ## Experiment SDK Methods ### `getInstance()` Gets a singleton instance of the ExperimentClient. #### Method `public static func getInstance() -> ExperimentClient?` ### `getInstance(_:)` Gets a named singleton instance of the ExperimentClient. #### Method `public static func getInstance(_ name: String) -> ExperimentClient?` ### `initialize(apiKey:config:)` Initializes the Experiment SDK with the provided API key and configuration. #### Method `public static func initialize(apiKey: String, config: ExperimentConfig) -> ExperimentClient` #### Parameters - **apiKey** (String) - Required - The API key for Amplitude. - **config** (ExperimentConfig) - Required - The configuration object for the Experiment SDK. ``` -------------------------------- ### ExperimentClient Protocol Methods Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentClient/index.html This section details the methods available on the ExperimentClient protocol, including starting and setting user information, retrieving user data, fetching experiment variants, and refetching all experiments. ```APIDOC ## `start(user:completion:)` ### Description Starts a new experiment session with the provided user information and an optional completion handler. ### Method `start` ### Parameters - **user** (`ExperimentUser`) - Required - The user object to associate with the session. - **completion** (`(() -> Void)?`) - Optional - A closure to be executed upon completion of the start operation. ### Return Value `Void` ``` ```APIDOC ## `setUser(user:completion:)` ### Description Sets or updates the user information for the current experiment session, with an optional completion handler. ### Method `setUser` ### Parameters - **user** (`ExperimentUser`) - Required - The user object to set. - **completion** (`(() -> Void)?`) - Optional - A closure to be executed upon completion of the set user operation. ### Return Value `Void` ``` ```APIDOC ## `getUser()` ### Description Retrieves the current user information associated with the experiment session. ### Method `getUser` ### Return Value `ExperimentUser?` - The current user object, or nil if no user is set. ``` ```APIDOC ## `getUserWithContext()` ### Description Retrieves the current user information along with any associated context. ### Method `getUserWithContext` ### Return Value `ExperimentUser` - The current user object with context. ``` ```APIDOC ## `getVariant(_:fallback:)` ### Description Retrieves a specific experiment variant for a given flag key. If the variant is not found, it returns a fallback value if provided. ### Method `getVariant` ### Parameters - **flagKey** (`String`) - Required - The key of the experiment flag. - **fallback** (`Variant?`) - Optional - A fallback `Variant` to return if the flag is not found. ### Return Value `Variant?` - The experiment variant, or nil if not found and no fallback is provided. ``` ```APIDOC ## `getVariant(_:fallback:)` ### Description Retrieves a specific experiment variant for a given flag key, returning a default `Variant` if the flag is not found or if the fallback string is used. ### Method `getVariant` ### Parameters - **flagKey** (`String`) - Required - The key of the experiment flag. - **fallback** (`String`) - Required - A fallback string to be converted into a `Variant` if the flag is not found. ### Return Value `Variant` - The experiment variant. ``` ```APIDOC ## `getVariants()` ### Description Retrieves all available experiment variants for the current user. ### Method `getVariants` ### Return Value `[String:Variant]` - A dictionary where keys are flag keys and values are the corresponding `Variant` objects. ``` ```APIDOC ## `refetchAll(completion:)` ### Description Forces a refetch of all experiment configurations and variants for the current user, with an optional completion handler. ### Method `refetchAll` ### Parameters - **completion** (`(() -> Void)?`) - Optional - A closure to be executed upon completion of the refetch operation. ### Return Value `Void` ``` ```APIDOC ## `setContextProvider(_:)` ### Description Sets a context provider to supply additional context information for experiments. ### Method `setContextProvider` ### Parameters - **contextProvider** (`ContextProvider`) - Required - The context provider to set. ### Return Value `ExperimentClient` - The `ExperimentClient` instance with the context provider set. ``` -------------------------------- ### Conventional Commit for Patch Release Source: https://github.com/amplitude/experiment-ios-client/blob/main/CONTRIBUTING.md Commits with 'fix' or 'perf' in the title will result in a patch release. This example shows a 'fix' type commit addressing a bug. ```git fix: null check bug ``` -------------------------------- ### Conventional Commit for Feature Release Source: https://github.com/amplitude/experiment-ios-client/blob/main/CONTRIBUTING.md A 'feat' type commit in the title, without 'BREAKING CHANGES' in the body, will result in a minor release. This example demonstrates a feature addition. ```git feat(cookies): some changes ``` -------------------------------- ### Conventional Commit with Breaking Changes Source: https://github.com/amplitude/experiment-ios-client/blob/main/CONTRIBUTING.md Commits with 'BREAKING CHANGES' in the body trigger a major release. This example shows a 'feat' type commit that also introduces breaking changes. ```git feat(cookies): Create new cookie format BREAKING CHANGES: Breaks old cookie format ``` -------------------------------- ### DefaultExperimentClient Methods Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/DefaultExperimentClient/index.html This section outlines the various methods available on the DefaultExperimentClient for managing user experiments and fetching experiment data. ```APIDOC ## start(user:completion:) ### Description Starts the experiment client with the given user. ### Method `public func start(user: ExperimentUser, completion: (() -> Void)? = nil) -> Void` ### Parameters * **user** (`ExperimentUser`) - The user object to start the client with. * **completion** (`(() -> Void)?`) - An optional completion handler to be called after the client starts. ``` ```APIDOC ## setUser(user:completion:) ### Description Sets the current user for the experiment client. ### Method `public func setUser(user: ExperimentUser, completion: (() -> Void)? = nil) -> Void` ### Parameters * **user** (`ExperimentUser`) - The user object to set. * **completion** (`(() -> Void)?`) - An optional completion handler to be called after the user is set. ``` ```APIDOC ## getUser() ### Description Retrieves the current user associated with the experiment client. ### Method `public func getUser() -> ExperimentUser?` ### Returns * `ExperimentUser?` - The current user object, or nil if no user is set. ``` ```APIDOC ## getUserWithContext() ### Description Retrieves the current user with associated context. ### Method `public func getUserWithContext() -> ExperimentUser` ### Returns * `ExperimentUser` - The current user object with context. ``` ```APIDOC ## refetchAll(completion:) ### Description Refetches all experiment configurations in the background. ### Method `public func refetchAll(completion: (() -> Void)? = nil) -> Void` ### Parameters * **completion** (`(() -> Void)?`) - An optional completion handler to be called after refetching. ``` ```APIDOC ## fetchAll(completion:) ### Description Fetches all experiment configurations. ### Method `public func fetchAll(completion: (() -> Void)? = nil)` ### Parameters * **completion** (`(() -> Void)?`) - A completion handler to be called after fetching. ``` ```APIDOC ## getVariant(_:fallback:) ### Description Retrieves the variant for a specific flag key with a fallback value. ### Method `public func getVariant(_ flagKey: String, fallback: String) -> Variant` ### Parameters * **flagKey** (`String`) - The key of the flag to retrieve the variant for. * **fallback** (`String`) - The fallback value to return if the flag is not found or an error occurs. ``` ```APIDOC ## getVariant(_:fallback:) ### Description Retrieves the variant for a specific flag key with an optional fallback variant. ### Method `public func getVariant(_ flagKey: String, fallback: Variant?) -> Variant?` ### Parameters * **flagKey** (`String`) - The key of the flag to retrieve the variant for. * **fallback** (`Variant?`) - An optional fallback variant to return if the flag is not found or an error occurs. ``` ```APIDOC ## getVariants() ### Description Retrieves all available variants for the current user. ### Method `public func getVariants() -> [String: Variant]` ### Returns * `[String: Variant]` - A dictionary of all available variants. ``` ```APIDOC ## setContextProvider(_:) ### Description Sets a context provider for the experiment client. ### Method `public func setContextProvider(_ contextProvider: ContextProvider) -> ExperimentClient` ### Parameters * **contextProvider** (`ContextProvider`) - The context provider to set. ``` -------------------------------- ### AmplitudeContextProvider Initializer Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/AmplitudeContextProvider/index.html Initializes the AmplitudeContextProvider with an Amplitude instance. ```APIDOC ## Initializers ### `init(_:​)` public init(_ amplitude:Amplitude) Initializes the AmplitudeContextProvider with an Amplitude instance. ``` -------------------------------- ### Variant Initializers Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Provides documentation for the initializers of the Variant struct. ```APIDOC ## Initializers ### `init(_:payload:)` Initializes a new Variant with a value and an optional payload. #### Parameters - `value` (String) - The string value of the variant. - `payload` (Any?) - An optional payload associated with the variant. ### `init(from:)` Initializes a new Variant by decoding it from a decoder. #### Parameters - `decoder` (Decoder) - The decoder to use for decoding. ``` ```APIDOC ## Initializers ### `init(_:payload:)` ```swift public init(_ value: String, payload: Any? = nil) ``` ### `init(from:)` ```swift public init(from decoder: Decoder) throws ``` ``` -------------------------------- ### AmplitudeContextProvider Methods Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/AmplitudeContextProvider/index.html Methods for retrieving various context information from the device and user. ```APIDOC ## Methods ### `get​Device​Id()` public func getDeviceId() -> String? Retrieves the device ID. ``` ```APIDOC ### `get​User​Id()` public func getUserId() -> String? Retrieves the user ID. ``` ```APIDOC ### `get​Version()` public func getVersion() -> String? Retrieves the application version. ``` ```APIDOC ### `get​Language()` public func getLanguage() -> String? Retrieves the device language. ``` ```APIDOC ### `get​Platform()` public func getPlatform() -> String? Retrieves the device platform (e.g., iOS, Android). ``` ```APIDOC ### `get​Os()` public func getOs() -> String? Retrieves the device operating system version. ``` ```APIDOC ### `get​Device​Manufacturer()` public func getDeviceManufacturer() -> String? Retrieves the device manufacturer. ``` ```APIDOC ### `get​Device​Model()` public func getDeviceModel() -> String? Retrieves the device model. ``` -------------------------------- ### ExperimentConfig Initializer Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentConfig/index.html Initializes an ExperimentConfig object with various configuration parameters. Default values are used if not specified. ```APIDOC ## init(debug:debugAssignmentRequests:fallbackVariant:initialFlags:instanceName:serverUrl:) ### Description Initializes an ExperimentConfig object with optional configuration parameters. ### Parameters #### Initializer Parameters - **debug** (Bool) - Optional - Controls debug mode. Defaults to `ExperimentConfig.Defaults.Debug`. - **debugAssignmentRequests** (Bool) - Optional - Controls debug assignment requests. Defaults to `ExperimentConfig.Defaults.DebugAssignmentRequests`. - **fallbackVariant** (Variant?) - Optional - The fallback variant to use. Defaults to `ExperimentConfig.Defaults.FallbackVariant`. - **initialFlags** ([String: Variant]) - Optional - A dictionary of initial flags. Defaults to `ExperimentConfig.Defaults.InitialFlags`. - **instanceName** (String) - Optional - The name of the experiment instance. Defaults to `ExperimentConfig.Defaults.InstanceName`. - **serverUrl** (String) - Optional - The URL of the experiment server. Defaults to `ExperimentConfig.Defaults.ServerUrl`. ``` -------------------------------- ### ContextProvider Protocol Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ContextProvider/index.html The ContextProvider protocol outlines the methods required to access various context details. ```APIDOC ## Protocol ContextProvider public protocol ContextProvider ### Description The ContextProvider protocol defines a set of methods that allow access to device and user-specific information. ### Requirements #### getDeviceId() func getDeviceId() -> String? Retrieves the unique device identifier. #### getUserId() func getUserId() -> String? Retrieves the current user identifier. #### getVersion() func getVersion() -> String? Retrieves the application version. #### getLanguage() func getLanguage() -> String? Retrieves the current language setting. #### getPlatform() func getPlatform() -> String? Retrieves the platform identifier (e.g., iOS, Android). #### getOs() func getOs() -> String? Retrieves the operating system name and version. #### getDeviceManufacturer() func getDeviceManufacturer() -> String? Retrieves the manufacturer of the device. #### getDeviceModel() func getDeviceModel() -> String? Retrieves the model of the device. ``` -------------------------------- ### ExperimentUser.Builder Methods Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentUser_Builder/index.html The ExperimentUser.Builder class provides methods to set various properties of an ExperimentUser before building it. ```APIDOC ## `set​User​Id(_:​)` ### Description Sets the user ID for the experiment. ### Method `setUserId(_ userId: String?) -> Builder` ## `set​Device​Id(_:​)` ### Description Sets the device ID for the experiment. ### Method `setDeviceId(_ deviceId: String?) -> Builder` ## `set​Country(_:​)` ### Description Sets the country for the user. ### Method `setCountry(_ country: String?) -> Builder` ## `set​Region(_:​)` ### Description Sets the region for the user. ### Method `setRegion(_ region: String?) -> Builder` ## `set​City(_:​)` ### Description Sets the city for the user. ### Method `setCity(_ city: String?) -> Builder` ## `set​Language(_:​)` ### Description Sets the language for the user. ### Method `setLanguage(_ language: String?) -> Builder` ## `set​Platform(_:​)` ### Description Sets the platform for the user. ### Method `setPlatform(_ platform: String?) -> Builder` ## `set​Version(_:​)` ### Description Sets the version information for the user. ### Method `setVersion(_ version: String?) -> Builder` ## `set​Dma(_:​)` ### Description Sets the Designated Market Area (DMA) for the user. ### Method `setDma(_ dma: String?) -> Builder` ## `set​Os(_:​)` ### Description Sets the operating system for the user. ### Method `setOs(_ os: String?) -> Builder` ## `set​Device​Family(_:​)` ### Description Sets the device family for the user. ### Method `setDeviceFamily(_ deviceFamily: String?) -> Builder` ## `set​Device​Type(_:​)` ### Description Sets the device type for the user. ### Method `setDeviceType(_ deviceType: String?) -> Builder` ## `set​Device​Manufacturer(_:​)` ### Description Sets the device manufacturer for the user. ### Method `setDeviceManufacturer(_ deviceManufacturer: String?) -> Builder` ## `set​Device​Model(_:​)` ### Description Sets the device model for the user. ### Method `setDeviceModel(_ deviceModel: String?) -> Builder` ## `set​Carrier(_:​)` ### Description Sets the carrier information for the user. ### Method `setCarrier(_ carrier: String?) -> Builder` ## `set​Library(_:​)` ### Description Sets the library information associated with the user. ### Method `setLibrary(_ library: String?) -> Builder` ## `set​User​Properties(_:​)` ### Description Sets multiple user properties at once. ### Method `setUserProperties(_ userProperties: [String: String]?) -> Builder` ## `set​User​Property(_:​value:​)` ### Description Sets a single user property with a key and value. ### Method `setUserProperty(_ property: String, value: String) -> Builder` ## `copy​User(_:​)` ### Description Copies an existing ExperimentUser object to the builder. ### Method `copyUser(_ user: ExperimentUser) -> Builder` ## `build()` ### Description Builds and returns the configured ExperimentUser object. ### Method `build() -> ExperimentUser` ``` -------------------------------- ### toDictionary() Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentUser/index.html Converts the ExperimentUser object into a dictionary format. ```APIDOC ## toDictionary() ### Description Converts the `ExperimentUser` object into a dictionary representation, which can be useful for serialization or logging. ### Method `public func toDictionary() -> [String:Any]` ### Returns A dictionary containing the user's properties. ``` -------------------------------- ### Constants Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentConfig_Constants/index.html Provides static constants for the Experiment configuration. ```APIDOC ## Constants ### Description Provides static constants for the Experiment configuration. ### Properties #### `Version` * **Type**: String * **Value**: "1.1.0" * **Description**: The version of the experiment client library. #### `Library` * **Type**: String * **Value**: "experiment-ios" * **Description**: The identifier for the experiment library. ``` -------------------------------- ### Variant Initializer with Value and Payload Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Initializes a Variant with a string value and an optional Any payload. Use this to create a Variant instance. ```swift public init(_ value: String, payload: Any? = nil) ``` -------------------------------- ### ExperimentUserProvider Protocol Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/index.html Protocol for providing a user to an ExperimentClient to be merged without overwriting prior to fetching variants for the user. Fields are only sent in the fetch request if the user object passed into fetch or stored by the ExperimentClient does not define those fields. ```APIDOC ## ExperimentUserProvider Protocol ### Description Provides a user to an ExperimentClient to be merged without overwriting prior to fetching variants for the user. In otherwords, fields are only sent in the fetch request if the user object passed into fetch or stored by the ExperimentClient does not define those fields. ### Protocol ExperimentUserProvider ``` -------------------------------- ### Variant Decoder Initializer Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Initializes a Variant from a Decoder. This is part of the Codable conformance. ```swift public init(from decoder: Decoder) throws ``` -------------------------------- ### ExperimentConfig.Defaults Properties Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentConfig_Defaults/index.html These properties define the default configuration values for the Experiment SDK. ```APIDOC ## ExperimentConfig.Defaults Properties ### `Debug` `public static let Debug: Bool = false` ### `DebugAssignmentRequests` `public static let DebugAssignmentRequests: Bool = false` ### `FallbackVariant` `public static let FallbackVariant: Variant? = nil` ### `InitialFlags` `public static let InitialFlags: [String: Variant] = [:]` ### `InstanceName` `public static let InstanceName: String = ""` ### `ServerUrl` `public static let ServerUrl: String = "https://api.lab.amplitude.com" ``` -------------------------------- ### ExperimentConfig Properties Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentConfig/index.html Exposes configuration properties of the ExperimentConfig object. ```APIDOC ## ExperimentConfig Properties ### Description These properties represent the configuration settings for the ExperimentConfig. ### Properties - **debug** (Bool) - Indicates if debug mode is enabled. - **debugAssignmentRequests** (Bool) - Indicates if debug assignment requests are enabled. - **fallbackVariant** (Variant?) - The fallback variant configured for experiments. - **initialFlags** ([String: Variant]) - A dictionary containing initial experiment flags. - **instanceName** (String) - The name of the experiment instance. - **serverUrl** (String) - The URL of the server where experiments are fetched. ``` -------------------------------- ### Variant Methods Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Documents the methods available on the Variant struct. ```APIDOC ## Methods ### `encode(to:)` Encodes the Variant to a given encoder. #### Parameters - `encoder` (Encoder) - The encoder to use for encoding. ``` ```APIDOC ## Methods ### `encode(to:)` ```swift public func encode(to encoder: Encoder) throws ``` ``` -------------------------------- ### ExperimentUser Properties Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/ExperimentUser/index.html The ExperimentUser object contains various properties to define user attributes for experimentation. ```APIDOC ## ExperimentUser Properties ### Description Represents a user within the Amplitude Experimentation platform, holding attributes used for targeting and segmentation. ### Properties * **deviceId** (String?): The unique identifier for the device. * **userId** (String?): The unique identifier for the user. * **version** (String?): The version of the application or SDK. * **country** (String?): The country of the user. * **region** (String?): The region of the user. * **dma** (String?): The Designated Market Area of the user. * **city** (String?): The city of the user. * **language** (String?): The preferred language of the user. * **platform** (String?): The operating system platform (e.g., iOS, Android). * **os** (String?): The specific operating system name and version. * **deviceFamily** (String?): The family of the device (e.g., iPhone, iPad). * **deviceType** (String?): The type of the device (e.g., Phone, Tablet). * **deviceManufacturer** (String?): The manufacturer of the device. * **deviceModel** (String?): The model of the device. * **carrier** (String?): The mobile carrier of the user. * **library** (String?): Information about the Amplitude SDK library being used. * **userProperties** (Dictionary?): A dictionary of custom user properties. ``` -------------------------------- ### ExperimentAnalyticsProvider Protocol Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/index.html Protocol for providing an analytics implementation for standard experiment events generated by the client (e.g. `ExposureEvent`). ```APIDOC ## ExperimentAnalyticsProvider Protocol ### Description Provides a analytics implementation for standard experiment events generated by the client (e.g. `ExposureEvent`). ### Protocol ExperimentAnalyticsProvider ``` -------------------------------- ### Variant Properties Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Details the properties available on the Variant struct. ```APIDOC ## Properties ### `value` The string value of the variant. - **Type**: String ### `payload` An optional payload associated with the variant. - **Type**: Any? ``` ```APIDOC ## Properties ### `value` ```swift public let value: String ``` ### `payload` ```swift public let payload: Any? ``` ``` -------------------------------- ### ExperimentAnalyticsEvent Protocol Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/index.html Protocol for analytics events generated from the experiment SDK client. These events are sent to the implementation provided by an `ExperimentAnalyticsProvider`. ```APIDOC ## ExperimentAnalyticsEvent Protocol ### Description Analytics event for tracking events generated from the experiment SDK client. These events are sent to the implementation provided by an `ExperimentAnalyticsProvider`. ### Protocol ExperimentAnalyticsEvent ``` -------------------------------- ### Variant Encode Method Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Encodes the Variant to an Encoder. This is part of the Codable conformance. ```swift public func encode(to encoder: Encoder) throws ``` -------------------------------- ### Variant Struct Definition Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html Defines the Variant struct, which conforms to Codable. It holds a string value and an optional payload. ```swift public struct Variant: Codable ``` -------------------------------- ### Conventional Commit for No Release Source: https://github.com/amplitude/experiment-ios-client/blob/main/CONTRIBUTING.md Commits that do not fit the criteria for feature or fix releases, such as documentation updates, will not trigger an automated release. ```git docs: update website ``` -------------------------------- ### Variant Value Property Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html The string value of the Variant. This property is read-only. ```swift public let value: String ``` -------------------------------- ### ExposureEvent Class Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/index.html Represents an event for tracking a user's exposure to a variant. This event will not count towards your analytics event volume. ```APIDOC ## ExposureEvent Class ### Description Event for tracking a user's exposure to a variant. This event will not count towards your analytics event volume. ### Class ExposureEvent ``` -------------------------------- ### Variant Payload Property Source: https://github.com/amplitude/experiment-ios-client/blob/main/docs/Variant/index.html The optional Any payload associated with the Variant. This property is read-only. ```swift public let payload: Any? ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.