NubrickSDK

NubrickSDK は iOS SDK のエントリポイントです。初期化、イベント送信、埋め込み、Remote Config、ユーザープロパティ更新を静的メソッドで扱います。

circle-exclamation

定義

public enum NubrickSDK {
    @MainActor
    public static func initialize(
        projectId: String,
        onEvent: (@Sendable (_ event: ComponentEvent) -> Void)? = nil,
        httpRequestInterceptor: NubrickHttpRequestInterceptor? = nil,
        onDispatch: ((_ event: NubrickEvent) -> Void)? = nil,
        trackCrashes: Bool = true
    )

    public nonisolated static func dispatch(_ event: NubrickEvent)

    @MainActor public static func overlayViewController() -> UIViewController
    @MainActor public static func overlay() -> some View

    @MainActor
    public static func embedding(
        _ id: String,
        arguments: NubrickArguments? = nil,
        onEvent: ((_ event: ComponentEvent) -> Void)? = nil,
        onSizeChange: ((_ width: NubrickSize, _ height: NubrickSize) -> Void)? = nil
    ) -> some View

    @MainActor
    public static func embedding<V: View>(
        _ id: String,
        arguments: NubrickArguments? = nil,
        onEvent: ((_ event: ComponentEvent) -> Void)? = nil,
        @ViewBuilder content: @escaping (_ phase: SwiftUIEmbeddingPhase) -> V,
        onSizeChange: ((_ width: NubrickSize, _ height: NubrickSize) -> Void)? = nil
    ) -> some View

    @MainActor
    public static func embeddingUIView(
        _ id: String,
        arguments: NubrickArguments? = nil,
        onEvent: ((_ event: ComponentEvent) -> Void)? = nil,
        onSizeChange: ((_ width: NubrickSize, _ height: NubrickSize) -> Void)? = nil
    ) -> UIView

    @MainActor
    public static func embeddingUIView(
        _ id: String,
        arguments: NubrickArguments? = nil,
        onEvent: ((_ event: ComponentEvent) -> Void)? = nil,
        content: @escaping (_ phase: UIKitEmbeddingPhase) -> UIView,
        onSizeChange: ((_ width: NubrickSize, _ height: NubrickSize) -> Void)? = nil
    ) -> UIView

    public static func remoteConfig(
        _ id: String,
        phase: @escaping (@Sendable (_ phase: RemoteConfigPhase) -> Void)
    )

    @MainActor
    public static func remoteConfigAsView<V: View>(
        _ id: String,
        @ViewBuilder phase: @escaping ((_ phase: RemoteConfigPhase) -> V)
    ) -> some View

    @MainActor public static func setUserProperties(_ properties: [String: Any])
    @MainActor public static func setUserProperty(_ key: String, value: Any)
    @MainActor public static func setUserId(_ id: String)
    @MainActor public static func getUserProperty(_ key: String) -> String?
    @MainActor public static func getUserId() -> String?
    @MainActor public static func getUserProperties() -> [String: String]
}

public typealias NubrickArguments = [String: any Sendable]
public typealias NubrickHttpRequestInterceptor = @Sendable (_ request: URLRequest) -> URLRequest

@frozen
public enum NubrickSize: Sendable {
    case fixed(CGFloat)
    case fill
}

初期化

イベント送信

埋め込み(SwiftUI)

フェーズを使う場合:

埋め込み(UIKit)

埋め込みサイズの取得

onSizeChange を使うと、埋め込みコンポーネントの実サイズを取得できます。 このコールバックは、実際の埋め込みページが読み込まれたときだけ呼ばれます。loading / notFound / failed では呼ばれません。

NubrickSize の意味:

  • .fixed(value) は、エディタで固定サイズが設定されていることを表します。

  • .fill は、その軸に固定サイズがなく、ホスト側のレイアウトに従うことを表します。

Remote Config

ユーザープロパティ

circle-exclamation
circle-info

このプロパティは、

  • どのユーザーがエクスペリメントのターゲットとなるかをフィルタリングする

  • エクスペリメント内のユーザー毎の動的な変数として表示する

ために使用されます。

ビルトインのユーザープロパティ

デフォルトで、以下のビルトインプロパティが設定されています:

Key
Description

userId

User id (uuid by default)

languageCode

language code (e.g. en for English, fr for French)

regionCode

region code (e.g. US for United States, GB for United Kingdom)

sdkVersion

nubrick sdk version

osName

os name (e.g. iOS, iPadOS)

osVersion

os version (e.g. 15.3.2)

appId

your app bundle identifier

appVersion

your app version (e.g. CFBundleShortVersionString for Apple platforms)

cfBundleVersion

your apple app CFBundleVersion

補足

  • setUserProperties / setUserProperty の値は String, Bool, Int, Double, Date などを渡せます。

  • getUserProperties() は、アプリが設定したカスタム値と userId を取得できます。

  • 失敗系の状態は Phases を参照してください。

Last updated