Skip to content

UIAlertController RUM tracking not working - no known workarounds work #2457

@dineshiOSDev

Description

@dineshiOSDev

UIAlertController RUM tracking is fundamentally not working in the iOS SDK. Neither automatic view tracking via predicate nor manual view management can properly isolate alert actions from the parent view.

Steps to Reproduce:

  1. Configure UIKitRUMViewsPredicate to return a RUMView for UIAlertController
  2. Present an alert with accessibilityIdentifier set
  3. User taps alert button
  4. Check Datadog RUM dashboard

Actual Behavior:

  • Alert view is created and tracked separately
  • Button tap actions are mapped to the parent view instead of the alert view
  • This creates a disconnect between the view hierarchy and action tracking

Environment:

  • SDK Version: 2.29.0
  • iOS Version: iOS 18.0+
  • Device: iPhone
  • Xcode Version: 16.3

Code Example:

class CustomRUMViewPredicate: UIKitRUMViewsPredicate {
    func rumView(for viewController: UIViewController) -> RUMView? {
        if let alert = viewController as? UIAlertController,
           let label = alert.view.accessibilityIdentifier,
           let viewName = ScreenNameManager.shared.getAlertName(alert: label) {
            return RUMView(name: viewName)  // Returns valid RUMView
        }
        
        // Fallback for regular screens
        guard let viewName = ScreenNameManager.shared.getScreenName(for: viewController) else { 
            return nil 
        }
        return RUMView(name: viewName)
    }
}

// Usage:
let alert = UIAlertController(title: "Test", message: "Message", preferredStyle: .alert)
alert.view.accessibilityIdentifier = "TestAlert"
alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in
    // This action gets tracked under parent view, not "TestAlert"
})
present(alert, animated: true)

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting responseWaiting for response / confirmation from the reporter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions