UIViewController or SwiftUI View. If you want to manually track specific views or add custom time and attributes to automatically tracked views, you can use the APIs provided by the RUM iOS SDK.RUMMonitor.shared().startView(key:name:attributes:) to start tracking a new RUM view. All views with the same key will be grouped in the RUM Explorer.RUMMonitor.shared().stopView(key:attributes:) to stop tracking.@import FlashcatObjc;
// in your `UIViewController`:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[RUMMonitor shared] startViewWithKey:@"view-key" name:@"View Name" attributes:@{@"foo": @"bar"}];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[RUMMonitor shared] stopViewWithKey:@"view-key" attributes:@{@"foo": @"bar"}];
}RUMMonitor.shared().addAction(type:name:attributes:):@import FlashcatObjc;
- (IBAction)didTapDownloadResourceButton:(UIButton *)sender {
[[RUMMonitor shared] addActionWithType:RUMActionTypeTap name:sender.currentTitle attributes:@{@"resource_id": @"123"}];
}RUMMonitor.shared().addAction(type:name:attributes:), the RUM SDK creates a RUM action and attaches all new resources, errors, and long tasks to this action until the view is considered fully loaded.URLSession. If you want to manually track custom resources (such as network requests, third-party provider APIs, GraphQL queries, etc.), you can use the following methods:RUMMonitor.shared().startResource(resourceKey:request:attributes:) to start loading a resource, then call RUMMonitor.shared().stopResource(resourceKey:response:size:attributes:) when loading completes, or call RUMMonitor.shared().stopResourceWithError(resourceKey:error:attributes:) when loading fails:@import FlashcatObjc;
// in your network client:
[[RUMMonitor shared] startResourceWithResourceKey:@"resource-key" request:request attributes:@{@"foo": @"bar"}];
[[RUMMonitor shared] stopResourceWithResourceKey:@"resource-key" response:response size:size attributes:@{@"foo": @"bar"}];resourceKey used in both calls must be unique for the RUM iOS SDK to match the resource start with its completion.RUMMonitor when an error occurs:@import FlashcatObjc;
[[RUMMonitor shared] addErrorWithMessage:@"Error message"
type:@"ErrorType"
source:DDRUMErrorSourceCustom
stack:@"Error stack trace"
attributes:@{@"foo": @"bar"}
file:file
line:line];RUMMonitor.shared().addAttribute(forKey:value:):@import FlashcatObjc;
[[RUMMonitor shared] addAttributeForKey:@"user_plan" value:@"premium"];date, error.kind, error.message, error.stack, error.source_type, view.id, view.url, view.loading_time, view.referrer, application.id.RUMMonitor.shared().removeAttribute(forKey:):@import FlashcatObjc;
[[RUMMonitor shared] removeAttributeForKey:@"user_plan"];usr.id (string): Unique user identifierusr.name (string): User-friendly name, displayed by default in RUM UIusr.email (string): User email, displayed if no name is providedFlashcat.setUserInfo(id:name:email:extraInfo:) after SDK initialization:@import FlashcatObjc;
[Flashcat setUserInfoWithId:@"1234"
name:@"John Doe"
email:@"john@doe.com"
extraInfo:@{@"plan": @"premium", @"signup_date": @"2024-01-15"}];trackBackgroundEvents setting when configuring RUM:@import FlashcatObjc;
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<RUM_APPLICATION_ID>"];
configuration.trackBackgroundEvents = YES;
[RUM enableWith:configuration];| Parameter | Type | Required | Description |
|---|---|---|---|
clientToken | String | Yes | Client token |
env | String | Yes | Environment name |
service | String | No | Service name, defaults to app bundle identifier |
batchSize | BatchSize | No | Batch upload data size, options: .small, .medium, .large |
uploadFrequency | UploadFrequency | No | Data upload frequency, options: .frequent, .average, .rare |
| Parameter | Type | Required | Description |
|---|---|---|---|
applicationID | String | Yes | RUM application ID |
sessionSampleRate | Float | No | Session sampling rate (0-100), default 100 |
uiKitViewsPredicate | UIKitRUMViewsPredicate | No | UIKit view tracking strategy |
uiKitActionsPredicate | UIKitRUMActionsPredicate | No | UIKit action tracking strategy |
swiftUIViewsPredicate | SwiftUIRUMViewsPredicate | No | SwiftUI view tracking strategy |
swiftUIActionsPredicate | SwiftUIRUMActionsPredicate | No | SwiftUI action tracking strategy |
urlSessionTracking | URLSessionTracking | No | URLSession network request tracking configuration |
trackBackgroundEvents | Bool | No | Whether to track background events, default false |
trackFrustrations | Bool | No | Whether to track user frustrations (such as error clicks), default true |
trackLongTasks | Bool | No | Whether to track long tasks, default true |
longTaskThreshold | TimeInterval | No | Long task threshold (seconds), default 0.1 seconds |
vitalsUpdateFrequency | VitalsFrequency | No | Performance metrics update frequency, options: .frequent, .average, .rare, .never |
uiKitViewsPredicate or swiftUIViewsPredicate when initializing RUM.DefaultUIKitRUMViewsPredicate class:DefaultSwiftUIRUMViewsPredicate class:predicate to customize tracking behavior.uiKitActionsPredicate or swiftUIActionsPredicate when initializing RUM.urlSessionTracking when initializing RUM and enable URLSessionInstrumentation:firstPartyHostsTracing to enable distributed tracing, associating RUM resources with backend traces:throw@import FlashcatObjc;
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<RUM_APPLICATION_ID>"];
[configuration setViewEventMapper:^DDRUMViewEvent * _Nonnull(DDRUMViewEvent * _Nonnull RUMViewEvent) {
return RUMViewEvent;
}];
[configuration setErrorEventMapper:^DDRUMErrorEvent * _Nullable(DDRUMErrorEvent * _Nonnull RUMErrorEvent) {
return RUMErrorEvent;
}];
[configuration setResourceEventMapper:^DDRUMResourceEvent * _Nullable(DDRUMResourceEvent * _Nonnull RUMResourceEvent) {
return RUMResourceEvent;
}];
[configuration setActionEventMapper:^DDRUMActionEvent * _Nullable(DDRUMActionEvent * _Nonnull RUMActionEvent) {
return RUMActionEvent;
}];
[configuration setLongTaskEventMapper:^DDRUMLongTaskEvent * _Nullable(DDRUMLongTaskEvent * _Nonnull RUMLongTaskEvent) {
return RUMLongTaskEvent;
}];(T) -> T?, where T is the specific RUM event type. This allows changing parts of events before they're sent.url of a RUM Resource, implement a custom redacted(_:) -> String function and use it in resourceEventMapper:DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<RUM_APPLICATION_ID>"];
[configuration setResourceEventMapper:^DDRUMResourceEvent * _Nullable(DDRUMResourceEvent * _Nonnull RUMResourceEvent) {
return RUMResourceEvent;
}];nil from error, resource, or action mappers will completely drop the event; the event will not be sent to Flashcat. The value returned from view event mappers cannot be nil (to drop views, customize the UIKitRUMViewsPredicate implementation; see Automatic View Tracking).| Event Type | Property Key | Description |
|---|---|---|
| RUMActionEvent | RUMActionEvent.action.target?.name | Action name |
RUMActionEvent.view.url | View URL associated with this action | |
| RUMErrorEvent | RUMErrorEvent.error.message | Error message |
RUMErrorEvent.error.stack | Error stack trace | |
RUMErrorEvent.error.resource?.url | Resource URL referenced by the error | |
RUMErrorEvent.view.url | View URL associated with this error | |
| RUMResourceEvent | RUMResourceEvent.resource.url | Resource URL |
RUMResourceEvent.view.url | View URL associated with this resource | |
| RUMViewEvent | RUMViewEvent.view.name | View name |
RUMViewEvent.view.url | View URL | |
RUMViewEvent.view.referrer | URL linking to initial page view |
sessionStarted event:@import FlashcatObjc;
[[RUMMonitor shared] currentSessionIDWithCompletion:^(NSString * _Nullable sessionId) {
// use session ID
}];trackingConsent setting can be one of the following values:.pending: Flashcat iOS SDK starts collecting and batching data but does not send to Flashcat. Flashcat iOS SDK waits for a new tracking consent value to decide how to handle batched data..granted: Flashcat iOS SDK starts collecting data and sends to Flashcat..notGranted: Flashcat iOS SDK does not collect any data. No logs, traces, or RUM events are sent to Flashcat.Flashcat.set(trackingConsent:) API call. Flashcat iOS SDK will change its behavior based on the new value..pending:.granted, Flashcat iOS SDK will send all current and future data to Flashcat;.notGranted, Flashcat iOS SDK will clear all current data and not collect future data.@import FlashcatObjc;
[Flashcat setWithTrackingConsent:DDTrackingConsentGranted];Flashcat.addUserExtraInfo(_:) API to attach additional user attributes to previously set attributes.@import FlashcatObjc;
[Flashcat addUserExtraInfo:@{@"company": @"Flashcat"}];Flashcat.clearAllData() API:@import FlashcatObjc;
[Flashcat clearAllData];Flashcat.stopInstance() API to stop a named SDK instance (or default instance if name is nil) from further collecting and uploading data.@import FlashcatObjc;
[Flashcat stopInstance];sessionSampleRate parameter. For example, to collect 90% of sessions:@import FlashcatObjc;
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<RUM_APPLICATION_ID>"];
configuration.sessionSampleRate = 90;
[RUM enableWith:configuration];firstPartyHostsTracing to configure your current app's API service domains:@import FlashcatObjc;
DDRUMConfiguration *configuration = [[DDRUMConfiguration alloc] initWithApplicationID:@"<RUM_APPLICATION_ID>"];
DDURLSessionTracking *urlSessionTracking = [DDURLSessionTracking new];
[urlSessionTracking setFirstPartyHostsTracing:[DDRUMFirstPartyHostsTracing alloc] initWithHosts:@[@"api.example.com", @"example.com"] sampleRate:20];
configuration.urlSessionTracking = urlSessionTracking;
[RUM enableWith:configuration];
[DDURLSessionInstrumentation enableWithConfiguration:[DDURLSessionInstrumentationConfiguration alloc] initWithDelegateClass:[SessionDelegate class]]];hosts: List of domains to tracesampleRate: Percentage of requests to trace (0-100), default 100traceparent, tracestate) to HTTP headers. Here's an explanation of the corresponding headers:traceparent: [version]-[trace id]-[parent id]-[trace flags]version: Currently 00trace id: 128-bit trace ID converted to 32 characters after hex processingparent id: 64-bit span ID, 16 characters after hex processingtrace flags: Indicates whether sampled, 01 means sampled, 00 means not sampledtracestate: dd=s:[sampling priority];o:[origin]sampling priority: 1 means trace is sampledorigin: Always rum, indicating collection through RUM SDKtraceparent: 00-00000000000000008448eb211c80319c-b7ad6b7169203331-01
tracestate: dd=s:1;o:rumapplicationID and clientToken are configured correctly to avoid data upload failuresViewsPredicate is recommended