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 | Unique identifier of the Real User Monitoring (RUM) application ID. RUM data collection is enabled only when the RUM appid is set. See how to obtain the appid. |
| sessionSamplingRate | float | No | SDK 1.6.8+: RUM session sampling rate in the range [0,100], supports decimals, default 100. 0.1 means 0.1%, 1 means 1%. Applies to RUM data within the same session. |
| sampleRate | int | No | Integer percentage sampling rate. Deprecated since SDK 1.6.8 and may be removed in future versions. Use sessionSamplingRate instead. |
| sessionOnErrorSamplingRate | float | No | SDK 1.6.8+: The supplemental error sampling percentage applied when a session does not hit the normal session sampling, range [0,100], supports decimals, default 0. Applies to RUM data within the same session. |
| sessionOnErrorSampleRate | int | No | Integer percentage error supplemental sampling configuration. Deprecated since SDK 1.6.8 and may be removed in future versions. Use sessionOnErrorSamplingRate instead. |
| enableTrackAppCrash | BOOL | No | Whether to collect crash logs. Default NO. |
| enableTrackAppANR | BOOL | No | Collect ANR (Application Not Responding) events. Default NO. |
| enableTrackAppFreeze | BOOL | No | Collect UI freeze events. Default NO. You can use the -setEnableTrackAppFreeze:freezeDurationMs: method to enable freeze collection and set the freeze threshold. |
| freezeDurationMs | long | No | Sets the UI freeze threshold, range [100,), in milliseconds, default 250 ms. Supported in SDK 1.5.7 and later. |
| enableTraceUserView | BOOL | No | Whether to trace user View operations. Default NO. |
| enableTraceUserAction | BOOL | No | Whether to trace user Action operations. Default NO. You can customize action_name with view.accessibilityIdentifier. |
| enableTraceUserResource | BOOL | No | Whether to trace user network requests. Default NO, applies only to native HTTP. Note: network requests made through [NSURLSession sharedSession] cannot capture performance data; SDK 1.5.9 and later support capturing network requests made through Swift's URLSession async/await APIs. |
| enableTraceURLConnectionResource | BOOL | No | SDK 1.6.8+: Automatically collect RUM Resource for NSURLConnection, default NO. Independent of enableTraceUserResource, which controls URLSession. See NSURLConnection Collection for an example. |
| visitorIDConfig | FTVisitorIDConfig | No | SDK 1.6.8+: Anonymous Visitor ID configuration, default nil (disabled). See Visitor ID for details. |
| nextViewActionPredicate | id<FTRUMNextViewActionPredicate> | No | SDK 1.6.8+: INV Action matching rule, default is click with an interval of no more than 3 seconds. Pass an explicit nil to disable INV. Not supported in App Extensions. See View Timing Metrics for details. |
| networkSettledResourcePredicate | id<FTRUMNetworkSettledResourcePredicate> | No | SDK 1.6.8+: TNS initial request matching rule. By default, requests start within [0,100ms] after the View starts. Set to nil to restore the default rule. See View Timing Metrics for details. |
| resourceUrlHandler | FTResourceUrlHandler | No | Custom rules for Resource collection. No filtering by default. Return NO to collect and YES not to collect. |
| errorMonitorType | FTErrorMonitorType | No | Supplemental monitoring type for error events. Adds monitoring information to collected crash data. FTErrorMonitorBattery monitors battery level, FTErrorMonitorMemory monitors memory usage, and FTErrorMonitorCpu monitors CPU usage. Not set by default. |
| deviceMetricsMonitorType | FTDeviceMetricsMonitorType | No | Performance monitoring type for views, not set by default. Adds the corresponding monitoring information to collected View data. FTDeviceMetricsMonitorMemory monitors the current app's memory usage, FTDeviceMetricsMonitorCpu monitors CPU usage changes, and FTDeviceMetricsMonitorFps monitors the screen frame rate. |
| monitorFrequency | FTMonitorFrequency | No | Sampling interval for view performance monitoring. FTMonitorFrequencyDefault is 500 ms (default), FTMonitorFrequencyFrequent is 100 ms, and FTMonitorFrequencyRare is 1000 ms. |
| enableResourceHostIP | BOOL | No | Whether to collect the IP of the request's target domain. Supported on >= iOS 13.0 and >= tvOS 13.0. |
| globalContext | NSDictionary | No | Adds custom tags to distinguish user monitoring data sources. If you need to use the tracing feature, set the parameter key to track_id and value to any value. See here for the rules on adding tags. |
| rumCacheLimitCount | int | No | Maximum RUM cache count. Default 100_000. Supported in SDK 1.5.8 and later. |
| rumDiscardType | FTRUMCacheDiscard | No | Sets the RUM discard rule. Default is FTRUMCacheDiscard. FTRUMCacheDiscard discards newly appended data when the RUM data count exceeds the maximum value; FTRUMDiscardOldest discards old data when RUM data exceeds the maximum value. Supported in SDK 1.5.8 and later. |
| resourcePropertyProvider | FTResourcePropertyProvider | No | Adds custom RUM Resource attributes through a block callback. Supported in SDK 1.5.10 and later. Has lower priority than URLSession Custom Collection. |
| enableTraceWebView | BOOL | No | Whether to enable WebView data collection, default YES. Supported in SDK 1.5.17 and later. |
| allowWebViewHost | NSArray | No | Deprecated since SDK 1.6.8. New code should configure the unified WebView allowlist through FTSDKConfig.allowWebViewHost. The old configuration remains as a compatibility fallback. See WebView Data Monitoring for the priority. |
| sessionTaskErrorFilter | FTSessionTaskErrorFilter | No | Sets whether to intercept URLSessionTask errors. Return YES to intercept and NO not to intercept. Once intercepted, RUM-Error does not collect that error. Supported in SDK 1.5.17 and later. |
| issueDataProvider | FTIssueDataProvider | No | Synchronously adds custom fields to the Crash and ANR RUM Errors automatically collected by the SDK. Requires enableTrackAppCrash or enableTrackAppANR to be enabled respectively. Supported in SDK 1.6.7 and later. See Error Custom Fields for usage. |
| viewTrackingHandler | FTViewTrackingHandler | No | Custom View tracking logic used to determine which ViewControllers should be monitored as RUM Views and to customize View Names. Effective when enableTraceUserView = YES. Supported in SDK 1.5.18 and later. See here for usage examples. |
| swiftUIViewTrackingHandler | FTSwiftUIViewTrackingHandler | No | Experimental. Custom SwiftUI View auto-collection logic used to filter automatically extracted SwiftUI View Names and customize the RUM View Name. Effective when enableTraceUserView = YES and this configuration is not empty. If no custom filtering or naming is needed, set FTDefaultSwiftUIViewTrackingHandler. This experimental API may change in future versions. Supported in SDK 1.6.4 and later. See here for usage examples. |
| actionTrackingHandler | FTActionTrackingHandler | No | Custom Action tracking logic used to filter the RUM Action events that need to be recorded and to customize Action Names. Effective when enableTraceUserAction = YES. Supported in SDK 1.5.18 and later. See here for usage examples. |
| crashMonitoring | FTCrashMonitorType | No | Configures the type scope of SDK crash monitoring. Default is FTCrashMonitorTypeHighCompatibility (preset macro for high compatibility mode). Effective when enableTrackAppCrash = YES. Note: you need to specify FTCrashMonitorTypeSystem | FTCrashMonitorTypeApplicationState because these provide important information for reports. Supported in SDK 1.5.19 and later. |
Sampling Rate Parameter Naming
For SDK 1.6.8 and later, sessionSamplingRate is recommended. It takes a percentage value from 0 to 100 and supports decimals. Invalid values (out of range, NaN, infinity) do not override the existing configuration. The legacy sampleRate / samplerate supports only integer percentages, is deprecated, and may be removed in future versions. Reading a decimal sampling rate through the legacy getter returns only the integer part.
For the units and priority of remote sampling fields, see Remote Configuration Fields.
RUM User Data Tracking¶
FTRUMConfig can be configured with enableTraceUserAction, enableTraceUserView, enableTraceUserResource, enableTrackAppFreeze, enableTrackAppCrash, and enableTrackAppANR to implement automatic collection of Action, View, Resource, LongTask, and Error data. If you want custom collection, you can report data through FTExternalDataManager.
View¶
Usage¶
/// Creates a page.
///
/// Call this method before the `-startViewWithName` method. It records the page load time. This method can be omitted if the load time is unavailable.
/// - Parameters:
/// - viewName: Page name
/// - loadTime: Page load time (nanoseconds)
-(void)onCreateView:(NSString *)viewName loadTime:(NSNumber *)loadTime;
/// Enters a page.
/// - Parameters:
/// - viewName: Page name
/// - property: Custom event attributes (optional)
-(void)startViewWithName:(NSString *)viewName property:(nullable NSDictionary *)property;
/// Updates the load time of the current RUM View.
/// Must be called between `-startView` and `-stopView` to take effect.
/// - Parameter duration: Load duration (nanoseconds).
-(void)updateViewLoadingTime:(NSNumber *)duration;
/// Leaves a page.
/// - Parameter property: Custom event attributes (optional)
-(void)stopViewWithProperty:(nullable NSDictionary *)property;
/// Creates a page.
///
/// Call this method before the `-startViewWithName` method. It records the page load time. This method can be omitted if the load time is unavailable.
/// - Parameters:
/// - viewName: Page name
/// - loadTime: Page load time (ns)
open func onCreateView(_ viewName: String, loadTime: NSNumber)
/// Enters a page.
/// - Parameters:
/// - viewName: Page name
/// - property: Custom event attributes (optional)
open func startView(withName viewName: String, property: [AnyHashable : Any]?)
/// Updates the load time of the current RUM View.
/// Must be called between `-startView` and `-stopView` to take effect.
/// - Parameter duration: Load duration (nanoseconds).
open func updateViewLoadingTime(_ duration: NSNumber)
/// Leaves a page.
/// - Parameter property: Custom event attributes (optional)
open func stopView(withProperty property: [AnyHashable : Any]?)
Code Examples¶
- (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 Collection¶
SwiftUI View supports automatic collection and manual collection:
- Automatic collection (experimental): The SDK automatically identifies pages and performs filtering and naming uniformly through
FTRumConfig.swiftUIViewTrackingHandler. See SwiftUI View Automatic Collection (Experimental) for usage. - Manual collection: Use
.ftTrackRUMView(name:property:)on a specific SwiftUI View to explicitly mark the start and end of the page and customize the View Name and attributes. Suitable for scenarios where you need stable page names, precise control over the View lifecycle, or the automatically extracted names do not meet expectations.
Action¶
Usage¶
/// Starts a RUM Action.
///
/// RUM binds the Resource, Error, and LongTask events that may be triggered by this Action. Avoid adding the action multiple times within 0.1 s. A View is associated with only one Action at a time. If a new Action is added before the previous Action ends, the new Action is discarded.
/// Does not interfere with Actions added through the `addAction:actionType:property` method.
///
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Custom event attributes (optional)
- (void)startAction:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;
/// Adds an Action event. No discard logic. Does not bind Resource, Error, or LongTask events.
///
/// Does not interfere with RUM Actions started through `startAction:actionType:property:`.
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Custom event attributes (optional)
- (void)addAction:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;
/// Starts a RUM Action.
///
/// RUM binds the Resource, Error, and LongTask events that may be triggered by this Action. Avoid adding the action multiple times within 0.1 s. A View is associated with only one Action at a time. If a new Action is added before the previous Action ends, the new Action is discarded.
/// Does not interfere with Actions added through the `addAction:actionType:property` method.
///
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Custom event attributes (optional)
open func startAction(_ actionName: String, actionType: String, property: [AnyHashable : Any]?)
/// Adds an Action event. No discard logic. Does not bind Resource, Error, or LongTask events.
///
/// Does not interfere with RUM Actions started through `startAction:actionType:property:`.
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Custom event attributes (optional)
open func addAction(_ actionName: String, actionType: String, property: [AnyHashable : Any]?)
Code Examples¶
SwiftUI Action Manual Collection¶
SwiftUI Action must be added manually at business interaction points. For SwiftUI components such as Button, NavigationLink, List items, or custom gestures, proactively record the RUM Action where user interaction is confirmed to occur.
SwiftUI Action supports two manual collection methods:
- Call in an existing event closure: Use
FTRUMSwiftUI.trackTapAction(name:property:). No additional gesture is added, making it suitable forButton,NavigationLink,List, scroll views, or scenarios with existing custom gestures. - Use a View Modifier: Use
.ftTrackRUMTapAction(name:property:count:), which adds asimultaneousGestureto the current View. Suitable for simple tap collection on ordinary Views.
Note: If the same tap event has already been manually collected through
FTExternalDataManager, avoid manually collecting it again with SwiftUI Action to prevent duplicate reporting.
FTRUMSwiftUI.trackTapAction(name:property:) is the recommended manual collection approach, especially for components that already have a tap closure. .ftTrackRUMTapAction(name:property:count:) is a convenient alternative, but because it adds an extra tap gesture, it may affect existing interactions in List, NavigationLink, scroll containers, or complex gesture combinations. In such cases, call FTRUMSwiftUI.trackTapAction(name:property:) in the existing tap closure instead.
Error¶
Usage¶
/// Adds an Error event.
/// - Parameters:
/// - type: Error type
/// - message: Error message
/// - stack: Stack trace
/// - property: Custom event attributes (optional)
- (void)addErrorWithType:(NSString *)type message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;
/// Adds an Error event.
/// - Parameters:
/// - type: Error type
/// - state: Application running state
/// - message: Error message
/// - stack: Stack trace
/// - property: Custom event attributes (optional)
- (void)addErrorWithType:(NSString *)type state:(FTAppState)state message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;
/// Adds an Error event.
/// - Parameters:
/// - type: Error type
/// - message: Error message
/// - stack: Stack trace
/// - property: Custom event attributes (optional)
open func addError(withType: String, message: String, stack: String, property: [AnyHashable : Any]?)
/// Adds an Error event.
/// - Parameters:
/// - type: Error type
/// - state: Application running state
/// - message: Error message
/// - stack: Stack trace
/// - property: Custom event attributes (optional)
open func addError(withType type: String, state: FTAppState, message: String, stack: String, property: [AnyHashable : Any]?)
Code Examples¶
// 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¶
Code Examples¶
Resource¶
Usage¶
/// HTTP request started.
/// - Parameters:
/// - key: Request identifier
/// - property: Custom event attributes (optional)
- (void)startResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// Adds HTTP request data.
///
/// - Parameters:
/// - key: Request identifier
/// - metrics: Request-related performance metrics
/// - content: Request-related data
- (void)addResourceWithKey:(NSString *)key metrics:(nullable FTResourceMetricsModel *)metrics content:(FTResourceContentModel *)content;
/// HTTP request ended.
/// - Parameters:
/// - key: Request identifier
/// - property: Custom event attributes (optional)
- (void)stopResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// HTTP request started.
/// - Parameters:
/// - key: Request identifier
/// - property: Custom event attributes (optional)
open func startResource(withKey key: String, property: [AnyHashable : Any]?)
/// HTTP request ended.
/// - Parameters:
/// - key: Request identifier
/// - property: Custom event attributes (optional)
open func stopResource(withKey key: String, property: [AnyHashable : Any]?)
/// Adds HTTP request data.
///
/// - Parameters:
/// - key: Request identifier
/// - metrics: Request-related performance metrics
/// - content: Request-related data
open func addResource(withKey key: String, metrics: FTResourceMetricsModel?, content: FTResourceContentModel)
Code Examples¶
// Step 1: Before the request starts
[[FTExternalDataManager sharedManager] startResourceWithKey:key];
// Step 2: Request completed
[[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 timing data for each phase is available
// FTResourceMetricsModel
// For iOS native, use the FTResourceMetricsModel initializer with NSURLSessionTaskMetrics data
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]initWithTaskMetrics:metrics];
// For other platforms, all timing data is in nanoseconds
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]init];
// Step 4: Add the resource. Pass nil for metrics if no timing data is available.
[[FTExternalDataManager sharedManager] addResourceWithKey:key metrics:metricsModel content:content];
// Step 1: Before the request starts
FTExternalDataManager.shared().startResource(withKey: key)
// Step 2: Request completed
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 timing data for each phase is available
// FTResourceMetricsModel
// For iOS native, use the FTResourceMetricsModel initializer with NSURLSessionTaskMetrics data
var metricsModel:FTResourceMetricsModel?
if let metrics = resource.metrics {
metricsModel = FTResourceMetricsModel(taskMetrics:metrics)
}
// For other platforms, all timing data is in nanoseconds
metricsModel = FTResourceMetricsModel()
...
// Step 4: Add the resource. Pass nil for metrics if no timing data is available.
FTExternalDataManager.shared().addResource(withKey: resource.key, metrics: metricsModel, content: contentModel)
NSURLConnection Resource Automatic Collection¶
Supported in SDK 1.6.8+
For projects that already use NSURLConnection requests, Resource automatic collection can be enabled independently. This switch does not replace or automatically enable enableTraceUserResource for URLSession.
Disabled by default. Request filtering, custom Resource attributes, and error filtering still use resourceUrlHandler, resourcePropertyProvider, and sessionTaskErrorFilter. To include Trace request headers, additionally enable NSURLConnection Trace. The performance fields are subject to the data actually available on the collection side; the complete details of URLSessionTaskMetrics are not guaranteed.