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 for the Real User Monitoring (RUM) application ID. RUM collection is enabled only when the corresponding RUM appid is set. How to obtain appid |
| sessionSamplingRate | float | No | RUM session sampling rate, range [0,100], supports decimals, default 100. 0.1 means 0.1%, 1 means 1%. Applies to RUM data under the same Session. Supported since SDK 1.6.8. |
| sampleRate | int | No | Deprecated since SDK 1.6.8, retained for compatibility. Integer percentage sampling rate, range [0,100], default 100. Use sessionSamplingRate instead. |
| sessionOnErrorSamplingRate | float | No | Error supplemental sampling percentage when normal session sampling is not hit, range [0,100], supports decimals, default 0. Applies to RUM data under the same Session. Supported since SDK 1.6.8. |
| sessionOnErrorSampleRate | int | No | Deprecated since SDK 1.6.8, retained for compatibility. Integer percentage error supplemental sampling configuration, range [0,100], default 0. Use sessionOnErrorSamplingRate instead. |
| enableTrackAppCrash | BOOL | No | Whether to collect crash logs. Default NO |
| enableTrackAppANR | BOOL | No | Collect ANR freeze/unresponsive events. Default NO |
| enableTrackAppFreeze | BOOL | No | Collect UI freeze events. Default NO. You can enable freeze collection and set the freeze threshold using the -setEnableTrackAppFreeze:freezeDurationMs: method |
| freezeDurationMs | long | No | Set the UI freeze threshold. Value range [100,), in milliseconds, default 250ms. Supported in SDK 1.5.7 and later |
| enableTraceUserView | BOOL | No | Whether to track user View operations. Default NO |
| enableTraceUserViewLoadingTime | BOOL | No | Supported since SDK 1.6.9. Whether to automatically collect page loading_time. Default YES, effective when enableTraceUserView = YES. Setting it to NO still retains RUM View tracking. Must be configured before starting RUM. For details, see Collection control |
| viewLoadingTimeClassNameExcludes | NSArray<NSString *> | No | Supported since SDK 1.6.9. Array of complete runtime class names of view controllers for which page load time is not automatically collected. Default empty array. Case-sensitive exact match; does not match by substring, regular expression, or inheritance relationship, and does not use custom View Names. After a match, RUM View tracking is still retained. Must be configured before starting RUM. For details, see Collection control |
| enableTraceUserAction | BOOL | No | Whether to track user Action operations. Default NO. You can customize action_name through view.accessibilityIdentifier |
| launchPrewarmInterval | NSInteger | No | Supported since SDK 1.6.9, iOS only. Custom prewarming detection threshold, in milliseconds, default 0 (disabled). It is recommended to set 1500 as needed; enableTraceUserAction must be enabled. System prewarming detection and trimming always take effect. For details, see Launch prewarming detection |
| enableTraceUserResource | BOOL | No | Whether to track user network requests. Default NO, applies only to native HTTP. Note: Network requests initiated through [NSURLSession sharedSession] cannot collect performance data; SDK 1.5.9 and later supports collecting network requests initiated through Swift's URLSession async/await APIs |
| enableTraceURLConnectionResource | BOOL | No | SDK 1.6.8+: Automatically collect NSURLConnection RUM Resources. Default NO. Independent of enableTraceUserResource, which controls URLSession. For an example, see NSURLConnection collection |
| visitorIDConfig | FTVisitorIDConfig | No | SDK 1.6.8+: Anonymous visitor identifier (Visitor ID) configuration, default nil (disabled). For details, see Visitor ID |
| nextViewActionPredicate | id<FTRUMNextViewActionPredicate> | No | SDK 1.6.8+: INV Action matching rule. By default, click with an interval of no more than 3 seconds. Explicit nil disables INV. App Extension is not supported. For details, see View timing metrics |
| 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. For details, see View timing metrics |
| resourceUrlHandler | FTResourceUrlHandler | No | Custom resource collection rule. No filtering by default. Return NO to collect, YES to not collect |
| errorMonitorType | FTErrorMonitorType | No | Supplementary type for error event monitoring. Adds monitoring information to collected crash data. FTErrorMonitorBattery is battery level, FTErrorMonitorMemory is memory usage, FTErrorMonitorCpu is CPU usage. Not set by default |
| deviceMetricsMonitorType | FTDeviceMetricsMonitorType | No | View performance monitoring type. Not set by default. Adds corresponding monitoring item information to collected View data. FTDeviceMetricsMonitorMemory monitors the current app's memory usage, FTDeviceMetricsMonitorCpu monitors the number of CPU fluctuations, FTDeviceMetricsMonitorFps monitors the screen frame rate |
| monitorFrequency | FTMonitorFrequency | No | Sampling interval for View performance monitoring. FTMonitorFrequencyDefault 500ms (default), FTMonitorFrequencyFrequent 100ms, FTMonitorFrequencyRare 1000ms |
| enableResourceHostIP | BOOL | No | Whether to collect the IP address of the request target domain. Supported on >= iOS 13.0 and >= tvOS 13.0 |
| globalContext | NSDictionary | No | Add custom tags to distinguish RUM data sources. If you need to use the tracking feature, the parameter key is track_id and value is any numeric value. For rules on adding tags, see here |
| rumCacheLimitCount | int | No | Maximum RUM cache size. Default 100_000. This parameter is supported in SDK 1.5.8 and later |
| rumDiscardType | FTRUMCacheDiscard | No | Set the RUM discard rule. Default FTRUMCacheDiscard. FTRUMCacheDiscard discards appended data when the amount of RUM data exceeds the maximum value; FTRUMDiscardOldest discards old data when RUM data exceeds the maximum value. This parameter is supported in SDK 1.5.8 and later |
| resourcePropertyProvider | FTResourcePropertyProvider | No | Add custom RUM Resource properties through a block callback. This parameter is supported in SDK 1.5.10 and later. Its priority is lower than that of 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 configures the unified WebView allowlist in FTSDKConfig.allowWebViewHost. The old configuration continues to serve as a compatibility fallback; for priority, see WebView data monitoring |
| sessionTaskErrorFilter | FTSessionTaskErrorFilter | No | Set whether to intercept URLSessionTask Error. Return YES to intercept and NO not to intercept. After interception, RUM-Error does not collect that error. Supported in SDK 1.5.17 and later |
| issueDataProvider | FTIssueDataProvider | No | Add custom fields synchronously to Crash and ANR RUM Errors automatically collected by the SDK. You need to enable enableTrackAppCrash or enableTrackAppANR respectively. Supported in SDK 1.6.7 and later. For usage, see Error custom fields |
| 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. For examples, see here |
| swiftUIViewTrackingHandler | FTSwiftUIViewTrackingHandler | No | Experimental. Custom SwiftUI View auto-collection logic, used to filter automatically extracted SwiftUI View Names and customize RUM View Names. Effective when enableTraceUserView = YES and this configuration is not empty. If custom filtering or naming is not required, you can set FTDefaultSwiftUIViewTrackingHandler. This experimental API may change in later versions. Supported in SDK 1.6.4 and later. For examples, see here |
| actionTrackingHandler | FTActionTrackingHandler | No | Custom Action tracking logic, used to filter RUM Action events to record and customize Action Names. Effective when enableTraceUserAction = YES. Supported in SDK 1.5.18 and later. For examples, see here |
| crashMonitoring | FTCrashMonitorType | No | Configure the type scope for SDK crash monitoring. Default FTCrashMonitorTypeHighCompatibility (a preset macro for high-compatibility mode). Effective when enableTrackAppCrash = YES. Note: You need to specify FTCrashMonitorTypeSystem | FTCrashMonitorTypeApplicationState; these provide important information for reports. Supported in SDK 1.5.19 and later |
Sampling rate parameter naming
SDK 1.6.8 and later recommends using sessionSamplingRate, with a value from 0 to 100 as a percentage, supporting decimals; invalid values (out of range, NaN, infinity) do not overwrite the original configuration. The old sampleRate / samplerate supports only integer percentages and has been marked as deprecated; it may be removed in future versions. Reading a decimal sampling rate through the old getter returns the integer part.
For the units and priority of remote sampling fields, see Remote configuration fields.
RUM User Data Tracking¶
Configure enableTraceUserAction, enableTraceUserView, enableTraceUserResource, enableTrackAppFreeze, enableTrackAppCrash, and enableTrackAppANR in FTRUMConfig to implement automatic collection tracking of Action, View, Resource, LongTask, and Error data. If you want custom collection, you can report data through FTExternalDataManager.
View¶
Usage¶
/// Create a view
///
/// Call before the `-startViewWithName` method. This method is used to record View load time; if load time cannot be obtained, this method can be omitted.
/// - Parameters:
/// - viewName: View name
/// - loadTime: View load time (nanoseconds)
-(void)onCreateView:(NSString *)viewName loadTime:(NSNumber *)loadTime;
/// Start a view
/// - Parameters:
/// - viewName: View name
/// - property: Event custom properties (optional)
-(void)startViewWithName:(NSString *)viewName property:(nullable NSDictionary *)property;
/// Update the load time of the current RUM View.
/// Must be called between the `-startView` and `-stopView` methods to take effect.
/// - Parameter duration: Load duration (nanoseconds).
-(void)updateViewLoadingTime:(NSNumber *)duration;
/// Stop a view
/// - Parameter property: Event custom properties (optional)
-(void)stopViewWithProperty:(nullable NSDictionary *)property;
/// Create a view
///
/// Call before the `-startViewWithName` method. This method is used to record View load time; if load time cannot be obtained, this method can be omitted.
/// - Parameters:
/// - viewName: View name
/// - loadTime: View load time (ns)
open func onCreateView(_ viewName: String, loadTime: NSNumber)
/// Start a view
/// - Parameters:
/// - viewName: View name
/// - property: Event custom properties (optional)
open func startView(withName viewName: String, property: [AnyHashable : Any]?)
/// Update the load time of the current RUM View.
/// Must be called between the `-startView` and `-stopView` methods to take effect.
/// - Parameter duration: Load duration (nanoseconds).
open func updateViewLoadingTime(_ duration: NSNumber)
/// Stop 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 properties
[[FTExternalDataManager sharedManager] startViewWithName:@"TestVC" property:@{@"custom_key":@"custom_value"}];
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
// Scenario 1:
[[FTExternalDataManager sharedManager] stopView];
// Scenario 2: Dynamic properties
[[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 properties
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 properties
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 views and uniformly filters and names them through
FTRumConfig.swiftUIViewTrackingHandler. For usage, see SwiftUI View automatic collection (experimental). - Manual collection: Use
.ftTrackRUMView(name:property:)on a specific SwiftUI View to explicitly mark the start and end of a view and customize the View Name and properties. This is suitable for scenarios that require stable view names, precise control over the View lifecycle, or when the automatically extracted name does not meet expectations.
Action¶
Usage¶
/// Start a RUM Action.
///
/// RUM binds the Resource, Error, and LongTask events that this Action may trigger. Avoid adding multiple times within 0.1 s. A View is associated with only one Action at a time; if the previous Action has not ended, newly added Actions are discarded.
/// Actions added via the `addAction:actionType:property` method are not affected.
///
/// - 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, or LongTask events.
///
/// Does not affect 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 binds the Resource, Error, and LongTask events that this Action may trigger. Avoid adding multiple times within 0.1 s. A View is associated with only one Action at a time; if the previous Action has not ended, newly added Actions are discarded.
/// Actions added via the `addAction:actionType:property` method are not affected.
///
/// - 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, or LongTask events.
///
/// Does not affect 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¶
SwiftUI Action Manual Collection¶
SwiftUI Actions need to be added manually at business interaction points. For SwiftUI components such as Button, NavigationLink, List rows, or custom gestures, proactively record a RUM Action where a user operation is confirmed to occur.
SwiftUI Action supports two manual collection methods:
- Call in an existing event closure: Use
FTRUMSwiftUI.trackTapAction(name:property:). This does not add an extra gesture and is suitable forButton,NavigationLink,List, scroll views, or scenarios with existing custom gestures. - Use a View Modifier: Use
.ftTrackRUMTapAction(name:property:count:). This adds asimultaneousGestureto the current View and is suitable for simple click collection on ordinary Views.
Note: If the same click event has already been manually collected through
FTExternalDataManager, avoid collecting it again manually with SwiftUI Action to prevent duplicate reporting.
FTRUMSwiftUI.trackTapAction(name:property:) is the recommended manual collection method, especially for components that already have click closures. .ftTrackRUMTapAction(name:property:count:) is a convenience syntax, but because it adds an extra tap gesture, it may affect existing interactions in List, NavigationLink, scroll containers, or complex gesture combinations. It is recommended to call FTRUMSwiftUI.trackTapAction(name:property:) in the original click closure instead.
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 properties
[[FTExternalDataManager sharedManager] addErrorWithType:@"ios_crash" message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
// Scenario 3: Dynamic properties
[[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 properties
FTExternalDataManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack",property: ["custom_key":"custom_value"])
// Scenario 3: Dynamic properties
FTExternalDataManager.shared().addError(withType: "custom_type", state: .unknown, message: "custom_message", stack: "custom_stack", property: ["custom_key":"custom_value"])
LongTask¶
Usage¶
Code Example¶
Resource¶
Usage¶
/// HTTP request starts
/// - 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 metrics
/// - content: Request-related data
- (void)addResourceWithKey:(NSString *)key metrics:(nullable FTResourceMetricsModel *)metrics content:(FTResourceContentModel *)content;
/// HTTP request ends
/// - Parameters:
/// - key: Request identifier
/// - property: Event custom properties (optional)
- (void)stopResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// HTTP request starts
/// - Parameters:
/// - key: Request identifier
/// - property: Event custom properties (optional)
open func startResource(withKey key: String, property: [AnyHashable : Any]?)
/// HTTP request ends
/// - 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 metrics
/// - content: Request-related data
open func addResource(withKey key: String, metrics: FTResourceMetricsModel?, content: FTResourceContentModel)
Code Example¶
// 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 time data for each stage can be obtained
// FTResourceMetricsModel
// If iOS native obtains NSURLSessionTaskMetrics data, use the FTResourceMetricsModel initializer directly
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]initWithTaskMetrics:metrics];
// On other platforms, all time data is in nanoseconds
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]init];
// Step 4: Add resource; if there is no time data, pass nil for metrics
[[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 time data for each stage can be obtained
// FTResourceMetricsModel
// If iOS native obtains NSURLSessionTaskMetrics data, use the FTResourceMetricsModel initializer directly
var metricsModel:FTResourceMetricsModel?
if let metrics = resource.metrics {
metricsModel = FTResourceMetricsModel(taskMetrics:metrics)
}
// On other platforms, all time data is in nanoseconds
metricsModel = FTResourceMetricsModel()
...
// Step 4: Add resource; if there is no time data, pass nil for metrics
FTExternalDataManager.shared().addResource(withKey: resource.key, metrics: metricsModel, content: contentModel)
NSURLConnection Resource Automatic Collection¶
Supported in SDK 1.6.8+
For projects that already have NSURLConnection requests, you can independently enable Resource automatic collection. This switch does not replace or automatically enable URLSession's enableTraceUserResource.
Disabled by default. Request filtering, custom Resource properties, and error filtering still use resourceUrlHandler, resourcePropertyProvider, and sessionTaskErrorFilter. If Trace request headers are needed, enable NSURLConnection Trace separately. The performance fields depend on the data actually available on the collection side; not all details of URLSessionTaskMetrics are guaranteed to be available.