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. Corresponds to setting the RUM appid. Only when this is set will the RUM collection function be enabled. 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 period 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) freeze 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 threshold for UI freezes. Value range [100,), unit milliseconds, default 250ms. Supported from SDK 1.5.7 and above
enableTraceUserView BOOL No Sets whether to trace user View operations. Default NO
enableTraceUserAction BOOL No Sets whether to trace user Action operations. Default NO. action_name can be customized via view.accessibilityIdentifier
enableTraceUserResource BOOL No Sets whether to trace user network requests. Default NO, only applies to native http. 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 the rule for collecting resources. Default is no filtering. Returns NO to collect, YES to not collect
errorMonitorType FTErrorMonitorType No Supplementary type for error event monitoring. 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 Performance monitoring type for views, 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 Sampling period for view performance monitoring. 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 tracing functionality is needed, the parameter key should be track_id, value can be any value. Rules for addition can be found here
rumCacheLimitCount int No Maximum cache limit for RUM. Default 100_000. Supported from SDK 1.5.8 and above
rumDiscardType FTRUMCacheDiscard No Sets the RUM discard rule. Default 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 the allowed WebView host addresses for data tracing, nil means collect all, default is nil. Supported from SDK 1.5.17 and above
sessionTaskErrorFilter FTSessionTaskErrorFilter No Sets whether to intercept URLSessionTask Error. Return YES to confirm interception, NO to not intercept. After interception, RUM-Error will not collect this 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 to 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 range for SDK crash monitoring, default is FTCrashMonitorTypeHighCompatibility (high compatibility mode preset macro). Effective condition: enableTrackAppCrash = YES. Note: It is necessary to specify FTCrashMonitorTypeSystem | FTCrashMonitorTypeApplicationState, 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 and tracking of 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`. This method is used to record the loading time of the view. If the loading time cannot be obtained, this method can be omitted.
/// - Parameters:
///  - viewName: View name
///  - loadTime: View 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`. This method is used to record the loading time of the view. If the loading time cannot be obtained, this method can be omitted.
/// - Parameters:
///  - viewName: View name
///  - loadTime: View 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 hope for unified integration and minimal business code changes. Usage: see SwiftUI View Automatic Collection.
  • Manual Collection: Use .ftTrackRUMView(name:property:) on specific SwiftUI Views to explicitly mark the start and end of a page. Suitable for scenarios requiring stable page names, precise control over View lifecycle, or when 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 the same View at the same time. If the previous Action has not ended, newly added Actions 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 discard logic, does not bind Resource, Error, LongTask events
///
/// 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 the same View at the same time. If the previous Action has not ended, newly added Actions 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 discard logic, does not bind Resource, Error, LongTask events
///
/// 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 business interaction points. For SwiftUI components such as Button, NavigationLink, List items, or custom gestures, actively record RUM Action at the location where user operation is confirmed.

SwiftUI Action supports two manual collection methods:

  • Call within existing event closure: Use FTRUMSwiftUI.trackTapAction(name:property:), which does not add additional gestures. Suitable for scenarios with Button, NavigationLink, List, scroll views, or existing custom gestures.
  • Use View Modifier: Use .ftTrackRUMTapAction(name:property:count:), which adds a simultaneousGesture to the current View. Suitable for simple click collection on ordinary Views.

Note: If the same click 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 since it adds an extra click gesture, it may affect original interactions in List, NavigationLink, scroll containers, or complex gesture combinations. It is recommended to instead call FTRUMSwiftUI.trackTapAction(name:property:) within the original click closure.

Error

Usage

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - message: error message
///   - stack: stack information
///   - 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 information
///   - 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 information
///   - 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 information
///   - 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 freeze event
/// - Parameters:
///   - stack: freeze stack
///   - duration: freeze duration (nanoseconds)
///   - property: event custom properties (optional)
- (void)addLongTaskWithStack:(NSString *)stack duration:(NSNumber *)duration property:(nullable NSDictionary *)property;
/// Add a freeze event
/// - Parameters:
///   - stack: freeze stack
///   - 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 completes
[[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 completes
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)

Feedback

Is this page helpful? ×