Skip to content

RUM Configuration

RUM Initialization Configuration

    //Enable rum
    FTRumConfig *rumConfig = [[FTRumConfig alloc]initWithAppid:appid];
    rumConfig.enableTraceUserView = YES;
    rumConfig.deviceMetricsMonitorType = FTDeviceMetricsMonitorAll;
    rumConfig.monitorFrequency = FTMonitorFrequencyRare;
    rumConfig.enableTraceUserAction = YES;
    rumConfig.enableTraceUserResource = YES;
    rumConfig.enableTrackAppFreeze = YES;
    rumConfig.enableTrackAppCrash = YES;
    rumConfig.enableTrackAppANR = YES;
    rumConfig.errorMonitorType = FTErrorMonitorAll;
    [[FTMobileAgent sharedInstance] startRumWithConfigOptions:rumConfig];
    let rumConfig = FTRumConfig(appid: appid)
    rumConfig.enableTraceUserView = true
    rumConfig.deviceMetricsMonitorType = .all
    rumConfig.monitorFrequency = .rare
    rumConfig.enableTraceUserAction = true
    rumConfig.enableTraceUserResource = true
    rumConfig.enableTrackAppFreeze = true
    rumConfig.enableTrackAppCrash = true
    rumConfig.enableTrackAppANR = true
    rumConfig.errorMonitorType = .all
    FTMobileAgent.sharedInstance().startRum(withConfigOptions: rumConfig)
Property Type Required Description
appid NSString Yes The unique identifier for the RUM application ID. Setting the RUM appid is required to enable RUM collection functionality. How to obtain appid
samplerate int No Sampling rate. Value range [0,100], 0 means no collection, 100 means full collection, default is 100. Scope applies to all View, Action, LongTask, Error data under the same session_id.
sessionOnErrorSampleRate int No Sets the error collection rate. When a session is not sampled by samplerate, if an error occurs during the session, data from the 1 minute before the error can be collected. Value range [0,100], 0 means no collection, 100 means full collection, default is 0. Scope applies to all View, Action, LongTask, Error data under the same session_id. Supported from SDK 1.5.16 and above.
enableTrackAppCrash BOOL No Sets whether to collect crash logs. Default NO.
enableTrackAppANR BOOL No Collects ANR (Application Not Responding) events. Default NO.
enableTrackAppFreeze BOOL No Collects UI freeze events. Default NO. Can be enabled and freeze threshold set via the -setEnableTrackAppFreeze:freezeDurationMs: method.
freezeDurationMs long No Sets the UI freeze threshold. Value range [100,), unit is milliseconds, default is 250ms. Supported from SDK 1.5.7 and above.
enableTraceUserView BOOL No Sets whether to track user View operations. Default NO.
enableTraceUserAction BOOL No Sets whether to track user Action operations. Default NO. action_name can be customized via view.accessibilityIdentifier.
enableTraceUserResource BOOL No Sets whether to track user network requests. Default NO, only affects native http requests. Note: Network requests initiated via [NSURLSession sharedSession] cannot collect performance data; SDK 1.5.9 and above supports collecting network requests initiated via Swift's URLSession async/await APIs.
resourceUrlHandler FTResourceUrlHandler No Customizes resource collection rules. Default is no filtering. Returns NO to collect, YES to not collect.
errorMonitorType FTErrorMonitorType No Error event monitoring supplement type. Adds monitoring information to collected crash data. FTErrorMonitorBattery for battery level, FTErrorMonitorMemory for memory usage, FTErrorMonitorCpu for CPU usage, default is not set.
deviceMetricsMonitorType FTDeviceMetricsMonitorType No View performance monitoring type, default is not set. Adds corresponding monitoring item information to collected View data. FTDeviceMetricsMonitorMemory monitors current application memory usage, FTDeviceMetricsMonitorCpu monitors CPU ticks, FTDeviceMetricsMonitorFps monitors screen frame rate.
monitorFrequency FTMonitorFrequency No View performance monitoring sampling period. FTMonitorFrequencyDefault 500ms (default), FTMonitorFrequencyFrequent 100ms, FTMonitorFrequencyRare 1000ms.
enableResourceHostIP BOOL No Whether to collect the IP address of the requested target domain. Supported under >= iOS 13.0, >= tvOS 13.0.
globalContext NSDictionary No Adds custom tags for distinguishing user monitoring data sources. If tracking functionality is needed, the parameter key should be track_id, and value can be any value. Addition rules can be found here.
rumCacheLimitCount int No Maximum RUM cache limit. Default is 100_000. Supported from SDK 1.5.8 and above.
rumDiscardType FTRUMCacheDiscard No Sets RUM discard rules. Default is FTRUMCacheDiscard. FTRUMCacheDiscard discards appended data when RUM data count exceeds the maximum; FTRUMDiscardOldest discards old data when RUM data exceeds the maximum. Supported from SDK 1.5.8 and above.
resourcePropertyProvider FTResourcePropertyProvider No Adds custom properties for RUM Resource via block callback. Supported from SDK 1.5.10 and above. Priority is lower than URLSession custom collection.
enableTraceWebView BOOL No Sets whether to enable WebView data collection, default YES. Supported from SDK 1.5.17 and above.
allowWebViewHost NSArray No Sets allowed WebView host addresses for data tracking, nil means collect all, default is nil. Supported from SDK 1.5.17 and above.
sessionTaskErrorFilter FTSessionTaskErrorFilter No Sets whether to intercept URLSessionTask Error. Returns YES to confirm interception, NO to not intercept. Intercepted errors will not be collected by RUM-Error. Supported from SDK 1.5.17 and above.
viewTrackingHandler FTViewTrackingHandler No Customizes View tracking logic, used to determine which ViewControllers need to be monitored as RUM Views and to customize View Name. Effective condition: enableTraceUserView = YES. Supported from SDK 1.5.18 and above. Usage example can be found here.
swiftUIViewTrackingHandler FTSwiftUIViewTrackingHandler No Experimental. Customizes SwiftUI View automatic collection logic, used to filter automatically extracted SwiftUI View Names and customize RUM View Name. Effective condition: enableTraceUserView = YES and this configuration is not empty. If no custom filtering or naming is needed, set FTDefaultSwiftUIViewTrackingHandler. This experimental API may be adjusted in future versions. Supported from SDK 1.6.4 and above. Usage example can be found here.
actionTrackingHandler FTActionTrackingHandler No Customizes Action tracking logic, used to filter RUM Action events that need to be recorded and customize Action Name. Effective condition: enableTraceUserAction = YES. Supported from SDK 1.5.18 and above. Usage example can be found here.
crashMonitoring FTCrashMonitorType No Configures the type scope for SDK crash monitoring, default is FTCrashMonitorTypeHighCompatibility (high compatibility mode preset macro). Effective condition: enableTrackAppCrash = YES. Note: Specifying FTCrashMonitorTypeSystem | FTCrashMonitorTypeApplicationState is required, as these provide important information for reports. Supported from SDK 1.5.19 and above.

RUM User Data Tracking

Configure FTRUMConfig with enableTraceUserAction, enableTraceUserView, enableTraceUserResource, enableTrackAppFreeze, enableTrackAppCrash, and enableTrackAppANR to achieve automatic collection tracking for Action, View, Resource, LongTask, and Error data. For custom collection, data can be reported via FTExternalDataManager.

View

Usage

/// Create a View
///
/// Call this method before `-startViewWithName`. It is used to record the page loading time. If the loading time cannot be obtained, this method can be omitted.
/// - Parameters:
///  - viewName: View name
///  - loadTime: Page loading time (nanoseconds)
-(void)onCreateView:(NSString *)viewName loadTime:(NSNumber *)loadTime;

/// Enter a View
/// - Parameters:
///  - viewName: View name
///  - property: Event custom properties (optional)
-(void)startViewWithName:(NSString *)viewName property:(nullable NSDictionary *)property;

/// Update the loading time of the current RUM View.
/// Must be called between `-startView` and `-stopView` methods to take effect.
/// - Parameter duration: Loading duration (nanoseconds).
-(void)updateViewLoadingTime:(NSNumber *)duration;

/// Leave a View
/// - Parameter property: Event custom properties (optional)
-(void)stopViewWithProperty:(nullable NSDictionary *)property;
/// Create a View
///
/// Call this method before `-startViewWithName`. It is used to record the page loading time. If the loading time cannot be obtained, this method can be omitted.
/// - Parameters:
///  - viewName: View name
///  - loadTime: Page loading time (ns)
open func onCreateView(_ viewName: String, loadTime: NSNumber)

/// Enter a View
/// - Parameters:
///  - viewName: View name
///  - property: Event custom properties (optional)
open func startView(withName viewName: String, property: [AnyHashable : Any]?)

/// Update the loading time of the current RUM View.
/// Must be called between `-startView` and `-stopView` methods to take effect.
/// - Parameter duration: Loading duration (nanoseconds).
open func updateViewLoadingTime(_ duration: NSNumber)

/// Leave a View
/// - Parameter property: Event custom properties (optional)
open func stopView(withProperty property: [AnyHashable : Any]?)

Code Example

- (void)viewDidAppear:(BOOL)animated{
  [super viewDidAppear:animated];
  // Scenario 1:
  [[FTExternalDataManager sharedManager] startViewWithName:@"TestVC"];

  // Scenario 2: Dynamic parameters
  [[FTExternalDataManager sharedManager] startViewWithName:@"TestVC" property:@{@"custom_key":@"custom_value"}];
}
-(void)viewDidDisappear:(BOOL)animated{
  [super viewDidDisappear:animated];
  // Scenario 1:
  [[FTExternalDataManager sharedManager] stopView];

  // Scenario 2: Dynamic parameters
  [[FTExternalDataManager sharedManager] stopViewWithProperty:@{@"custom_key":@"custom_value"}];
}
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    // Scenario 1:
    FTExternalDataManager.shared().startView(withName: "TestVC")
    // Scenario 2: Dynamic parameters
    FTExternalDataManager.shared().startView(withName: "TestVC",property: ["custom_key":"custom_value"])
}
override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    // Scenario 1:
    FTExternalDataManager.shared().stopView()
    // Scenario 2: Dynamic parameters
    FTExternalDataManager.shared().stopView(withProperty: ["custom_key":"custom_value"])
}

SwiftUI View Manual Collection

SwiftUI View supports two collection methods:

  • Automatic Collection: Use FTRumConfig.swiftUIViewTrackingHandler to filter and name SwiftUI View Names automatically extracted by the SDK. Suitable for scenarios that desire unified integration with minimal business code changes. Usage can be found at SwiftUI View Automatic Collection.
  • Manual Collection: Use .ftTrackRUMView(name:property:) to explicitly mark the start and end of a page on a specific SwiftUI View. Suitable for scenarios requiring stable page names, precise control over View lifecycle, or where automatically extracted names do not meet expectations.
import SwiftUI
import FTMobileSDK

struct HomeView: View {
    var body: some View {
        VStack {
            Text("Home")
        }
        .ftTrackRUMView(
            name: "Home",
            property: ["page_type": "home"]
        )
    }
}

Action

Usage

/// Start a RUM Action.
///
/// RUM will bind Resource, Error, LongTask events that may be triggered by this Action. Avoid adding multiple times within 0.1 s. Only one Action can be associated with a View at the same time. If a new Action is added before the previous one ends, it will be discarded.
/// Does not interfere with Actions added via the `addAction:actionType:property` method.
///
/// - Parameters:
///   - actionName: Event name
///   - actionType: Event type
///   - property: Event custom properties (optional)
- (void)startAction:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;

/// Add an Action event. No duration, no discard logic.
///
/// Does not interfere with RUM Actions started via `startAction:actionType:property:`.
/// - Parameters:
///   - actionName: Event name
///   - actionType: Event type
///   - property: Event custom properties (optional)
- (void)addAction:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;
/// Start a RUM Action.
///
/// RUM will bind Resource, Error, LongTask events that may be triggered by this Action. Avoid adding multiple times within 0.1 s. Only one Action can be associated with a View at the same time. If a new Action is added before the previous one ends, it will be discarded.
/// Does not interfere with Actions added via the `addAction:actionType:property` method.
///
/// - Parameters:
///   - actionName: Event name
///   - actionType: Event type
///   - property: Event custom properties (optional)
open func startAction(_ actionName: String, actionType: String, property: [AnyHashable : Any]?)

/// Add an Action event. No duration, no discard logic.
///
/// Does not interfere with RUM Actions started via `startAction:actionType:property:`.
/// - Parameters:
///   - actionName: Event name
///   - actionType: Event type
///   - property: Event custom properties (optional)
open func addAction(_ actionName: String, actionType: String, property: [AnyHashable : Any]?)

Code Example

// startAction
[[FTExternalDataManager sharedManager] startAction:@"action" actionType:@"click" property:@{@"action_property":@"testActionProperty1"}];
// addAction
[[FTExternalDataManager sharedManager] addAction:@"action" actionType:@"click" property:@{@"action_property":@"testActionProperty1"}];
// startAction
FTExternalDataManager.shared().startAction("custom_action", actionType: "click",property: nil)
// addAction
FTExternalDataManager.shared().addAction("custom_action", actionType: "click",property: nil)

SwiftUI Action Manual Collection

SwiftUI Action needs to be manually supplemented at the business interaction point. For SwiftUI components like Button, NavigationLink, List items, or custom gestures, actively record the RUM Action at the location where user interaction is confirmed.

SwiftUI Action supports two manual collection methods:

  • Call within existing event closure: Use FTRUMSwiftUI.trackTapAction(name:property:). This does not add an extra gesture and is suitable for scenarios with Button, NavigationLink, List, scroll views, or existing custom gestures.
  • Use View Modifier: Use .ftTrackRUMTapAction(name:property:count:). This adds a simultaneousGesture to the current View, suitable for simple tap collection on ordinary Views.

Note: If the same tap event has already been manually collected via FTExternalDataManager, avoid using SwiftUI Action manual collection again to prevent duplicate reporting.

import SwiftUI
import FTMobileSDK

struct ProductView: View {
    var body: some View {
        Button("Buy") {
            FTRUMSwiftUI.trackTapAction(
                name: "buy_click",
                property: ["source": "product_detail"]
            )

            // Execute business click logic
            buy()
        }
    }

    private func buy() {
        // ...
    }
}
import SwiftUI
import FTMobileSDK

struct ProductCard: View {
    var body: some View {
        Text("Buy")
            .ftTrackRUMTapAction(
                name: "buy_click",
                property: ["source": "product_card"]
            )
    }
}

FTRUMSwiftUI.trackTapAction(name:property:) is the more recommended manual collection method, especially for components with existing click closures; .ftTrackRUMTapAction(name:property:count:) is a convenient shorthand, but because it adds an extra tap gesture, it may affect original interactions in List, NavigationLink, scroll containers, or complex gesture combinations. It is recommended to call FTRUMSwiftUI.trackTapAction(name:property:) within the original click closure instead.

Error

Usage

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - message: Error message
///   - stack: Stack trace
///   - property: Event custom properties (optional)
- (void)addErrorWithType:(NSString *)type message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - state: Application running state
///   - message: Error message
///   - stack: Stack trace
///   - property: Event custom properties (optional)
- (void)addErrorWithType:(NSString *)type state:(FTAppState)state  message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;
/// Add an Error event
/// - Parameters:
///   - type: error type
///   - message: Error message
///   - stack: Stack trace
///   - property: Event custom properties (optional)
open func addError(withType: String, message: String, stack: String, property: [AnyHashable : Any]?)

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - state: Application running state
///   - message: Error message
///   - stack: Stack trace
///   - property: Event custom properties (optional)
open func addError(withType type: String, state: FTAppState, message: String, stack: String, property: [AnyHashable : Any]?)

Code Example

// Scenario 1
[[FTExternalDataManager sharedManager] addErrorWithType:@"type" message:@"message" stack:@"stack"];
// Scenario 2: Dynamic parameters
[[FTExternalDataManager sharedManager] addErrorWithType:@"ios_crash" message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
// Scenario 3: Dynamic parameters
[[FTExternalDataManager sharedManager] addErrorWithType:@"ios_crash" state:FTAppStateUnknown message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
// Scenario 1
FTExternalDataManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack")
// Scenario 2: Dynamic parameters
FTExternalDataManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack",property: ["custom_key":"custom_value"])
// Scenario 3: Dynamic parameters
FTExternalDataManager.shared().addError(withType: "custom_type", state: .unknown, message: "custom_message", stack: "custom_stack", property: ["custom_key":"custom_value"])

LongTask

Usage

/// Add a LongTask (freeze) event
/// - Parameters:
///   - stack: Freeze stack trace
///   - duration: Freeze duration (nanoseconds)
///   - property: Event custom properties (optional)
- (void)addLongTaskWithStack:(NSString *)stack duration:(NSNumber *)duration property:(nullable NSDictionary *)property;
/// Add a LongTask (freeze) event
/// - Parameters:
///   - stack: Freeze stack trace
///   - duration: Freeze duration (nanoseconds)
///   - property: Event custom properties (optional)
func addLongTask(withStack: String, duration: NSNumber, property: [AnyHashable : Any]?)

Code Example

// Scenario 1
[[FTExternalDataManager sharedManager] addLongTaskWithStack:@"stack string" duration:@1000000000];
// Scenario 2: Dynamic parameters
[[FTExternalDataManager sharedManager] addLongTaskWithStack:@"stack string" duration:@1000000000 property:@{@"custom_key":@"custom_value"}];
// Scenario 1
FTExternalDataManager.shared().addLongTask(withStack: "stack string", duration: 1000000000)
// Scenario 2: Dynamic parameters
FTExternalDataManager.shared().addLongTask(withStack: "stack string", duration: 1000000000 ,property: [["custom_key":"custom_value"]])

Resource

Usage

/// HTTP request start
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (optional)
- (void)startResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;

/// Add HTTP request data
///
/// - Parameters:
///   - key: Request identifier
///   - metrics: Request-related performance attributes
///   - content: Request-related data
- (void)addResourceWithKey:(NSString *)key metrics:(nullable FTResourceMetricsModel *)metrics content:(FTResourceContentModel *)content;

/// HTTP request end
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (optional)
- (void)stopResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// HTTP request start
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (optional)
open func startResource(withKey key: String, property: [AnyHashable : Any]?)

/// HTTP request end
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (optional)
open func stopResource(withKey key: String, property: [AnyHashable : Any]?)

/// Add HTTP request data
///
/// - Parameters:
///   - key: Request identifier
///   - metrics: Request-related performance attributes
///   - content: Request-related data
open func addResource(withKey key: String, metrics: FTResourceMetricsModel?, content: FTResourceContentModel)

Code Example

//Step 1: Before request starts
[[FTExternalDataManager sharedManager] startResourceWithKey:key];

//Step 2: Request completion
[[FTExternalDataManager sharedManager] stopResourceWithKey:key];

//Step 3: Assemble Resource data
//FTResourceContentModel data
FTResourceContentModel *content = [[FTResourceContentModel alloc]init];
content.httpMethod = request.HTTPMethod;
content.requestHeader = request.allHTTPHeaderFields;
content.responseHeader = httpResponse.allHeaderFields;
content.httpStatusCode = httpResponse.statusCode;
content.responseBody = responseBody;
//ios native
content.error = error;

//If time data for each phase can be obtained
//FTResourceMetricsModel
//ios native obtains NSURLSessionTaskMetrics data, directly use FTResourceMetricsModel's initialization method
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]initWithTaskMetrics:metrics];

//Other platforms, all time data in nanoseconds
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]init];

//Step 4: add resource. If no time data, pass nil for metrics
[[FTExternalDataManager sharedManager] addResourceWithKey:key metrics:metricsModel content:content];
//Step 1: Before request starts
FTExternalDataManager.shared().startResource(withKey: key)

//Step 2: Request completion
FTExternalDataManager.shared().stopResource(withKey: resource.key)

//Step 3: ① Assemble Resource data
let contentModel = FTResourceContentModel(request: task.currentRequest!, response: task.response as? HTTPURLResponse, data: resource.data, error: error)

//② If time data for each phase can be obtained
//FTResourceMetricsModel
//ios native obtains NSURLSessionTaskMetrics data, directly use FTResourceMetricsModel's initialization method
var metricsModel:FTResourceMetricsModel?
if let metrics = resource.metrics {
   metricsModel = FTResourceMetricsModel(taskMetrics:metrics)
}
//Other platforms, all time data in nanoseconds
metricsModel = FTResourceMetricsModel()
...

//Step 4: add resource. If no time data, pass nil for metrics
FTExternalDataManager.shared().addResource(withKey: resource.key, metrics: metricsModel, content: contentModel)