Legacy — API & Configuration (old SDK)

Reference for the Sophonz iOS SDK Options class, key APIs, and initialization examples.

API Introduction & Configuration

Options Class

The Options class is used to configure the SDK during initialization. Each parameter is described below.

@objc(SophonzOptions) public final class Options: NSObject {
 
    /// App key (issued from the Sophonz Console)
    public let appKey: String
 
    /// Collector endpoint URL for data transmission
    public let endpoints: Sophonz.Endpoints?
 
    /// Data collection sampling rate (0.0 – 1.0)
    /// 0.0: no collection / 1.0: 100% collection (default: 1.0)
    public var sampleRate: Double
 
    /// Whether to send the device ID (UUID) to the Collector
    /// The device ID is a UUID generated and stored in the Keychain.
    public var isDeviceIdEnable: Bool
 
    /// Project identifier (visible in the console)
    public var project: String?
 
    /// Controls SDK data collection via API response
    public var sdkCollectControl: Sophonz.SDKCollectControl?
 
    /// Automatic user tap (click) event collection
    public var tapOption: Sophonz.TapOption?
 
    /// HTTP request Header and Body collection
    /// If not set, XHR requests are collected but Headers and Body are not.
    public var xhrOption: Sophonz.XHROption?
 
    /// WebView session data source configuration
    /// true: use data sent by Native (default)
    /// false: use data generated by the WebView itself
    /// Note: no additional configuration is needed for pure Native apps.
    public var webviewOption: Sophonz.WebviewOption?
 
    /// Deployment environment distinction
    /// Set only when the production and test environments share the same server.
    public var deployEnvironment: SophonzDeployEnvironment
}

Parameter summary

ParameterTypeDescription
appKeyStringApp key (required)
endpointsSophonz.Endpoints?Collector endpoint URL
projectString?Project identifier
sampleRateDoubleCollection rate (0.0–1.0, default 1.0)
isDeviceIdEnableBoolWhether to send device UUID
deployEnvironmentSophonzDeployEnvironmentProduction / test environment
sdkCollectControlSDKCollectControl?Collection control via API response
tapOptionTapOption?Automatic touch event collection → TapOption details
xhrOptionXHROption?HTTP Header/Body collection → XHROption details
webviewOptionWebviewOption?WebView session connection mode → WebviewOption details

TapOption Details

Sophonz.TapOption configures how user tap (click) events are collected.

Initialization

let tapOption = Sophonz.TapOption(
    isAutoCapture:             Bool,
    isAutoCaputrueButtonTitle: Bool,
    isAutoCaputrueButtonId:    Bool
)

Parameter description

ParameterTypeDefaultDescription
isAutoCaptureBoolfalseEnable automatic tap event collection
isAutoCaptureButtonTitleBooltrueCollect button title text
isAutoCaptureButtonIdBooltrueCollect button ID

When isAutoCapture is false, tap events are not collected regardless of the other option values.

Excluding specific buttons

button.sophonz_ignore = true

Example

// Auto-capture enabled, title collection enabled, ID collection enabled
let tapOption = Sophonz.TapOption(
    isAutoCapture:             true,
    isAutoCaputrueButtonTitle: true,
    isAutoCaputrueButtonId:    true
)

XHROption Details

Sophonz.XHROption controls whether HTTP request Headers and Body are collected within the app.

Initialization

let xhrOption = Sophonz.XHROption(
    isCaptureHttpRequestHeader: Bool,
    isCaptureHttpRequestBody:   Bool
)

Parameter description

ParameterTypeDefaultDescription
isCaptureHttpRequestHeaderBoolfalseCollect HTTP request Headers
isCaptureHttpRequestBodyBoolfalseCollect HTTP request Body

If XHROption is not set, XHR requests themselves are collected, but Headers and Body are not.

Body collection may include sensitive personal data (passwords, tokens, etc.). Review target APIs before enabling this option.

Example

// Collect both Header and Body
let xhrOption = Sophonz.XHROption(
    isCaptureHttpRequestHeader: true,
    isCaptureHttpRequestBody:   true
)
 
// Collect Header only
let xhrOption = Sophonz.XHROption(
    isCaptureHttpRequestHeader: true,
    isCaptureHttpRequestBody:   false
)

WebviewOption Details

Sophonz.WebviewOption controls how the Native session and WebView session are connected in a hybrid app.

Initialization

let webOption = Sophonz.WebviewOption(
    isSharedSession: Bool,
    isNeedWebAgent:  Bool
)

Parameter description

ParameterTypeDefaultDescription
isSharedSessionBooltrueWhether to merge Native and WebView sessions
isNeedWebAgentBooltrueWhether the SDK auto-injects the WebAgent script into WebViews

Setting isSharedSession: true unifies Native and WebView user behavior into a single tracked session.

Use isNeedWebAgent: false to prevent duplicate injection when the WebAgent script is already loaded separately. No additional configuration is needed for pure Native apps.

Example

// Hybrid app — merged session, auto WebAgent injection
let webOption = Sophonz.WebviewOption(
    isSharedSession: true,
    isNeedWebAgent:  true
)
 
// When WebAgent is loaded separately — prevent duplicate injection
let webOption = Sophonz.WebviewOption(
    isSharedSession: true,
    isNeedWebAgent:  false
)

Key APIs

extension Sophonz {
 
    /// Initialize the SDK
    @discardableResult
    @objc public static func setup(options: Sophonz.Options,
                                   isDebug: Bool = false) -> Sophonz?
 
    /// Start the SDK
    @objc public func start()
 
    /// Set user ID
    @objc public static func setUserId(id: String?)
 
    /// Get the currently set user ID
    @objc public static func getUserId() -> String?
 
    /// Send a custom log
    @objc public static func customLog(level: Sophonz.LogLevel, message: String)
 
    /// Add a custom attribute to Spans
    /// Set before start() to include it in all subsequently created Spans.
    @objc public static func setAttribute(key: String, value: String?)
 
    /// Return the device UUID stored in the Keychain
    @objc public static func getDeviceId() -> String
 
    /// Manually inject scripts when WKWebView is initialized via xib
    @objc public static func setWebviewConfiguration(
        userContentController: WKUserContentController)
}

API summary

APIDescription
Sophonz.setup(options:isDebug:)Initialize the SDK
.start()Start the SDK
Sophonz.setUserId(id:)Set user ID
Sophonz.getUserId()Get user ID
Sophonz.customLog(level:message:)Send a custom log
Sophonz.setAttribute(key:value:)Add a custom attribute to Spans
Sophonz.getDeviceId()Get device UUID
Sophonz.setWebviewConfiguration(userContentController:)Manually inject scripts for xib WebView

SDK Initialization Examples

Swift Project — Basic Example

Initialize in AppDelegate's didFinishLaunchingWithOptions.

import UIKit
import SophonzCore
 
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
 
    var window: UIWindow?
 
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        setupSophonzSDK()
        return true
    }
 
    func setupSophonzSDK() {
        let endpoint   = Sophonz.Endpoints(collectorURL: "https://in.sophonz.ai")
        let appKey = "your-app-key"
 
        // Control SDK collection via API response
        let sdkControl = Sophonz.SDKCollectControl(remoteCollectionControlEnable: true)
 
        // Collect HTTP request Header and Body
        let xhrOption  = Sophonz.XHROption(
            isCaptureHttpRequestHeader: true,
            isCaptureHttpRequestBody:   true)
 
        // Share Native session (default: true)
        let webOption  = Sophonz.WebviewOption(isSharedSession: true)
 
        // Auto tap collection, title enabled, ID enabled
        let tapOption  = Sophonz.TapOption(
            isAutoCapture:             true,
            isAutoCaputrueButtonTitle: true,
            isAutoCaputrueButtonId:    true)
 
        let option = Sophonz.Options(
            project:           "namespace",
            appKey:            appKey,
            endpoints:         endpoint,
            deployEnvironment: .production,
            sampleRate:        1.0,
            isDeviceIdEnable:  true,
            sdkCollectControl: sdkControl,
            tapOption:         tapOption,
            xhrOption:         xhrOption,
            webviewOption:     webOption)
 
        // isDebug: true → enables console log output
        Sophonz.setup(options: option, isDebug: true)?.start()
    }
}

Swift Project — Production Example

In production projects, it is recommended to manage the Collector URL, app key, and project in a dedicated manager class.

func setupSophonzSDK() {
    // Collector URL: prefer user-selected address, fall back to default
    let endpoint = Sophonz.Endpoints(
        collectorURL: "https://in.sophonz.ai"
    )
 
    // Remote control of SDK collection via API response
    let sdkControl = Sophonz.SDKCollectControl(
        remoteCollectionControlEnable: true
    )
 
    // Enable Header and Body collection for HTTP requests
    let xhrOption = Sophonz.XHROption(
        isCaptureHttpRequestHeader: true,
        isCaptureHttpRequestBody:   true
    )
 
    // Share Native session, prevent duplicate WebAgent injection
    let webOption = Sophonz.WebviewOption(
        isSharedSession: true,
        isNeedWebAgent:  false
    )
 
    // Auto tap collection (title enabled, ID enabled)
    let tapOption = Sophonz.TapOption(
        isAutoCapture:             true,
        isAutoCaputrueButtonTitle: true,
        isAutoCaputrueButtonId:    true
    )
 
    let option = Sophonz.Options(
        project:           "namespace",
        appKey:            appKey,
        endpoints:         endpoint,
        deployEnvironment: .development,
        sampleRate:        1,
        isDeviceIdEnable:  true,
        sdkCollectControl: sdkControl,
        tapOption:         tapOption,
        xhrOption:         xhrOption,
        webviewOption:     webOption
    )
 
    // isDebug: true → enables console log output
    Sophonz.setup(options: option, isDebug: true)?.start()
}

Objective-C Project

Initialize in AppDelegate's didFinishLaunchingWithOptions.

#import "AppDelegate.h"
#import <SophonzCore/SophonzCore-Swift.h>
 
@implementation AppDelegate
 
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self setupSophonzSDK];
    return YES;
}
 
- (void)setupSophonzSDK {
    SophonzEndpoints *endpoint =
        [[SophonzEndpoints alloc] initWithCollectorURL:@"https://in.sophonz.ai"];
    NSString *appKey = @"your-app-key";
 
    SophonzSDKCollectControl *sdkControl =
        [[SophonzSDKCollectControl alloc] initWithRemoteCollectionControlEnable:YES];
 
    SophonzXHROption *xhrOption =
        [[SophonzXHROption alloc] initWithIsCaptureHttpRequestHeader:YES
                               isCaptureHttpRequestBody:YES];
 
    SophonzWebviewOption *webOption =
        [[SophonzWebviewOption alloc] initWithIsSharedSession:YES];
 
    SophonzTapOption *tapOption =
        [[SophonzTapOption alloc] initWithIsAutoCapture:YES];
 
    SophonzOptions *option = [[SophonzOptions alloc]
        initWithProject:           @"namespace"
        appKey:                    appKey
        endpoints:                 endpoint
        deployEnvironment:         SophonzDeployEnvironmentProduction
        sampleRate:                1.0
        isDeviceIdEnable:          YES
        sdkCollectControl:         sdkControl
        tapOption:                 tapOption
        xhrOption:                 xhrOption
        webviewOption:             webOption];
 
    [[Sophonz setupWithOptions:option isDebug:YES] start];
}
 
@end