Skip to main content
Flashduty iOS RUM SDK supports iOS 12.0, iPadOS 12.0, tvOS 12.0 and above. By integrating the SDK, you can monitor your iOS app’s performance, errors, and user behavior in real-time.
About Dependencies and Package NamesFlashduty iOS SDK is fully compatible with the Datadog open-source protocol. When adding dependencies via Swift Package Manager or CocoaPods, use names like FlashcatCore and FlashcatRUM, but in code, import modules like DatadogCore and DatadogRUM. You can seamlessly leverage Datadog ecosystem documentation, examples, and best practices while enjoying Flashduty platform services.

Integration Steps

1

Add SDK Dependencies

Flashduty iOS SDK supports Swift Package Manager and CocoaPods:
  1. In Xcode, open your project and select File > Add Package Dependencies
  2. Enter the Flashduty SDK Git repository URL:
    https://github.com/flashcatcloud/fc-sdk-ios
    
  3. Select version rule:
    • Recommended: Select Up to Next Major Version and enter the latest version number (e.g., 0.3.0)
    • This allows bug fixes and minor updates while maintaining compatibility
  4. Click Add Package and wait for Xcode to download dependencies
  5. In the Choose Package Products window, select modules to add to your Target:
    • FlashcatCore - Core SDK (required)
    • FlashcatRUM - RUM feature module (required)
    • FlashcatWebViewTracking - WebView tracking (optional)
    • FlashcatCrashReporting - Crash reporting (recommended)
  6. Ensure each module is linked to the correct Target, click Add Package to complete
Get Latest VersionCheck the SDK Release Page for the latest stable version. Pin to a specific version to avoid unexpected updates.
2

Get Application Credentials

In the Flashduty console’s RUM Application Management page:
  1. Create or select an iOS application
  2. Get the following credentials:
    • Application ID - Application unique identifier
    • Client Token - Client access token
3

Initialize SDK

Initialize the SDK in your AppDelegate.swift’s application(_:didFinishLaunchingWithOptions:) method:
AppDelegate.swift
import UIKit
import DatadogCore

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        Datadog.initialize(
            with: Datadog.Configuration(
                clientToken: "<CLIENT_TOKEN>",
                env: "<ENV_NAME>"
            ),
            trackingConsent: .granted
        )

        return true
    }
}
Parameter Description:
  • clientToken - Client token obtained from console (required)
  • env - Environment name, e.g., production, staging (required)
  • trackingConsent - User tracking consent state (see below)
TrackingConsent States:
StateBehavior
.grantedStart collecting data and send to Flashduty
.pendingStart collecting and batching data, but don’t send, wait for confirmation
.notGrantedDo not collect any data
You can dynamically modify tracking consent state after initialization via Datadog.set(trackingConsent:).
4

Enable RUM Features

Configure and enable RUM features. Recommend enabling early in AppDelegate:
AppDelegate.swift
import DatadogRUM

RUM.enable(
    with: RUM.Configuration(
        applicationID: "<RUM_APPLICATION_ID>",
        uiKitViewsPredicate: DefaultUIKitRUMViewsPredicate(),
        uiKitActionsPredicate: DefaultUIKitRUMActionsPredicate(),
        swiftUIViewsPredicate: DefaultSwiftUIRUMViewsPredicate(),
        swiftUIActionsPredicate: DefaultSwiftUIRUMActionsPredicate(
            isLegacyDetectionEnabled: true
        ),
        urlSessionTracking: RUM.Configuration.URLSessionTracking()
    )
)
Configuration Parameter Description:
  • applicationID - RUM application ID obtained from console
  • uiKitViewsPredicate - UIKit view tracking strategy
  • uiKitActionsPredicate - UIKit user action tracking strategy
  • swiftUIViewsPredicate - SwiftUI view tracking strategy
  • swiftUIActionsPredicate - SwiftUI user action tracking strategy
  • urlSessionTracking - URLSession network request tracking configuration
The SDK will automatically start collecting the following data:
  • UIKit and SwiftUI view tracking
  • User interaction events
  • Network request monitoring
5

Configure Network Tracking (Optional)

Enable URLSession Tracking:To monitor network requests sent from URLSession instances, enable URLSessionInstrumentation and pass your delegate class type:
import DatadogRUM

URLSessionInstrumentation.enable(
    with: .init(
        delegateClass: YourSessionDelegate.self
    )
)

let session = URLSession(
    configuration: .default,
    delegate: YourSessionDelegate(),
    delegateQueue: nil
)
Auto-tracked Network Information:
  • Request URL, method, status code
  • Request and response headers
  • Request duration and data size
  • Network error information
Only network requests initiated while a view is active are tracked.

View Tracking

Flashduty iOS SDK supports automatic tracking of UIKit and SwiftUI views.

UIKit View Auto Tracking

UIKit views are automatically tracked via DefaultUIKitRUMViewsPredicate. The SDK tracks UIViewController lifecycle, automatically recording view display and hide events.

SwiftUI View Tracking

For SwiftUI apps, add the .trackRUMView() modifier to views:
import SwiftUI
import DatadogRUM

struct ProductView: View {
    var body: some View {
        VStack {
            Text("Product Details")
            // Your view content
        }
        .trackRUMView(name: "Product")
    }
}
The trackRUMView(name:) method automatically starts and stops view tracking when SwiftUI views appear and disappear.

Custom View Tracking

For more granular control, manually track views:
import DatadogRUM

// Start tracking view
RUMMonitor.shared().startView(
    key: "view-key",
    name: "View Name",
    attributes: [:]
)

// Stop tracking view
RUMMonitor.shared().stopView(
    key: "view-key",
    attributes: [:]
)

User Action Tracking

UIKit Action Auto Tracking

User actions in UIKit (like button taps, switch toggles, etc.) are automatically tracked via DefaultUIKitRUMActionsPredicate.

SwiftUI Action Tracking

For SwiftUI controls, add the .trackRUMTapAction() modifier:
import SwiftUI
import DatadogRUM

struct CheckoutView: View {
    var body: some View {
        Button("Complete Purchase") {
            // Button action
        }
        .trackRUMTapAction(name: "Purchase")
    }
}
Using .trackRUMTapAction(name:) inside List may affect default gestures (e.g., disabling Button actions or breaking NavigationLink). For List elements, recommend using custom action API.

Custom Action Tracking

Manually track user actions:
import DatadogRUM

RUMMonitor.shared().addAction(
    type: .tap,
    name: "Button Tapped",
    attributes: ["button_id": "submit"]
)

Advanced Configuration

Track Errors

Flashduty iOS SDK automatically captures app crashes and uncaught exceptions. You can also manually record errors:
import DatadogRUM

RUMMonitor.shared().addError(
    message: "Network request failed",
    type: "NetworkError",
    source: .network,
    attributes: [
        "url": "https://api.example.com",
        "status_code": 500
    ]
)
All error information is displayed in the console’s RUM Explorer, including error stack, attributes, and JSON details.
For detailed error reporting configuration, see iOS Error Reporting.

Track Background Events

You can track events when the app is running in the background (e.g., crashes and network requests):
RUM.enable(
    with: RUM.Configuration(
        applicationID: "<RUM_APPLICATION_ID>",
        trackBackgroundEvents: true
    )
)
Tracking background events may generate additional sessions, affecting billing. If you have questions, please contact Flashduty support team.

Track User Information

You can set user information for the current session to track specific user behavior:
import DatadogCore

Datadog.setUserInfo(
    id: "user-123",
    name: "John Doe",
    email: "john.doe@example.com",
    extraInfo: [
        "plan": "premium",
        "signup_date": "2024-01-15"
    ]
)
Custom user attributes (like plan, signup_date) can be used to group and filter data in the Insights dashboard.

Offline Data Handling

The iOS SDK ensures data availability when the user’s device is offline:
Data Persistence Mechanism:
  • Events are stored locally in batches when network signal is weak or device battery is low
  • Automatically uploaded when network recovers, ensuring no data loss
  • Old data is automatically cleaned up to avoid excessive disk usage
Even if users use the app while offline, data is retained and uploaded when network recovers, ensuring no monitoring data is lost.

WebView Integration

If your iOS app contains WKWebView, you can enable WebView tracking to monitor web content performance and errors.
1

Add WebView Dependency

When adding package dependencies in Swift Package Manager, also add the FlashcatWebViewTracking module.
2

Enable WebView Tracking

Enable WebView tracking in your ViewController:
import DatadogWebViewTracking
import WebKit

let webView = WKWebView()

// Enable tracking for specified WKWebView
WebViewTracking.enable(
    webView: webView,
    hosts: ["example.com", "*.example.com"]
)
Parameter Description:
  • webView - WKWebView instance to track
  • hosts - List of domains to track, supports wildcards (e.g., *.example.com)
Web pages in WebView can now be correlated with native app RUM data.

Disable Auto User Data Collection

To comply with privacy regulations or organizational data governance policies, you can disable automatic user data collection.
1

Go to Application Management

After creating an application, go to the Application Management page and click your application.
2

Configure Data Collection

Click the User Data Collection option and use toggles to control the following settings:
  • Client IP collection
  • Geo-location data collection

Verify Integration

After integration, verify that the integration is successful:
1

Check Console Logs

Search for Datadog keyword in Xcode console to view SDK initialization and data reporting logs.
2

Access Console

Log in to Flashduty console, go to the corresponding RUM application, and check if data is being reported.
3

Trigger Test Events

Perform the following actions in the app to verify data collection:
  • Open different pages in the app to verify page view events
  • Perform user actions (taps, swipes, etc.) to verify interaction events
  • Trigger network requests to verify resource loading events
  • Manually trigger an error to verify error tracking
If you see data reporting and data appears in the console, the integration is successful!

Next Steps