Unified SDK for Swift reference

このページはまだあなたの言語に翻訳されていません。 現在取り組んでいますので、後でもう一度確認してください。

This reference documents every public export of AmplitudeUnified and every option you can pass to its initializers, verified against version 0.0.4. That version, resolved with Swift Package Manager, used iOS Swift SDK 1.19.4 (AmplitudeSwift), Experiment iOS SDK 1.20.3, and Session Replay 0.17.0. Every analytics method behaves as the iOS Swift SDK reference describes. For changes between versions, go to the AmplitudeUnified changelog.

swift
import AmplitudeUnified

AmplitudeUnified re-exports AmplitudeSwift, AmplitudeCore, the Experiment module, and, on iOS, AmplitudeSessionReplay. The Unified SDK doesn't add a new client class. It adds an initializer to the iOS Swift SDK's Amplitude class, so you can use every Amplitude method and property.

Exports

Setup

init

Creates Analytics, then adds the Session Replay plugin (iOS only), the Feature Experiment plugin, and the plugin that marks events as sent by the Unified SDK.

On iOS:

swift
convenience init(
    apiKey: String,
    serverZone: AmplitudeCore.ServerZone = .US,
    instanceName: String = "$default_instance",
    analyticsConfig: AnalyticsConfig = .init(),
    experimentConfig: ExperimentPlugin.Config = .init(),
    sessionReplayConfig: SessionReplayPlugin.Config = .init(),
    logger: any Logger = ConsoleLogger()
)

On macOS, tvOS, watchOS, and visionOS, the initializer is the same without sessionReplayConfig.

swift
let amplitude = Amplitude(
    apiKey: "YOUR_API_KEY",
    serverZone: .EU,
    sessionReplayConfig: SessionReplayPlugin.Config(sampleRate: 0.1)
)

To raise the log level after initialization, go to Turn on debug logging.

Objective-C initializers

The Objective-C class is Amplitude. Import Experiment (AmplitudeExperiment with CocoaPods) and AmplitudeSessionReplay as well as AmplitudeUnified. Objective-C has three initializers, and no shorter forms:

The Objective-C initializers require version 0.0.2 or later.

objc
Amplitude *amplitude = [[Amplitude alloc] initWithApiKey:@"YOUR_API_KEY"];

experiment

Returns the Feature Experiment client.

swift
var experiment: ExperimentClient? { get }
func experiment(apiKey: String?) -> ExperimentClient?

The property returns nil when the instance has more than one Feature Experiment plugin. In that case, call experiment(apiKey:) with the plugin's deployment key, or nil for the plugin that uses the project API key. The client is the Experiment iOS SDK client. It doesn't fetch flags at initialization. Call fetch(user:completion:) before variant().

swift
amplitude.experiment?.fetch(user: nil) { client, error in
    let variant = client.variant("checkout-redesign")
}

sessionReplay

Returns the Session Replay client. iOS only.

swift
var sessionReplay: SessionReplay? { get }

In Objective-C, the type is AMPSessionReplay.

swift
amplitude.sessionReplay?.stop()

AnalyticsConfig

The Analytics options for the Swift initializer. Swift requires the arguments in the order this table lists. Each option maps to the iOS Swift SDK Configuration option of the same name. For behavior, go to Configuration options in the iOS Swift SDK.

AnalyticsConfig doesn't include these Configuration options: logLevel, optOut, offline, userId, deviceId, networkTrackingOptions, interactionsOptions, enableDiagnostics, and enableRequestBodyCompression. After initialization, you can set amplitude.optOut and amplitude.configuration.offline. Go to Set options that AnalyticsConfig doesn't include.

AMPAnalyticsConfig

The Objective-C Analytics options. Create it with [[AMPAnalyticsConfig alloc] init], then set its properties. Requires 0.0.2 or later.

Unlike the Swift initializer, the Objective-C initializer honors logLevel. AMPAnalyticsConfig has no storage provider properties.

ExperimentPlugin.Config

The Feature Experiment options. In Objective-C, the class is ExperimentPluginConfig. Create it with [[ExperimentPluginConfig alloc] init], then set its properties. In Swift, pass the arguments in the order this table lists.

For details, go to the Experiment iOS SDK configuration.

SessionReplayPlugin.Config

The Session Replay options. iOS only. In Objective-C, the class is AMPSessionReplayPluginConfig. Its properties are read-only, and its only initializer takes every argument.

For details, go to the Session Replay iOS plugin configuration.

これは役に立ちましたか?

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

このページでは